我在 Raspberry PI 上运行 Mosquitto Broker。
我将 mosquitto.conf 文件放在 /etc/mosquitto/mosquitto.conf 上,其内容如下:
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
/etc/mosquitto/conf.g/mosquitto.conf 中的另一个文件内容如下:
autosave_interval 1800
user mosquitto
connection_messages true
log_dest stderr
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
log_type all
log_type debug
log_timestamp true
#message_size_limit 10240
password_file /etc/mosquitto/conf.d/osmc.pw
allow_anonymous false
#acl_file jp.acl
persistence true
persistence_file mosquitto.db
persistent_client_expiration 1m
#pid_file xxxx
retained_persistence true
#listener 1883
listener 1883
listener 8883
tls_version tlsv1.2
cafile /etc/mosquitto/conf.d/ca.crt
certfile /etc/mosquitto/conf.d/osmc.crt
keyfile /etc/mosquitto/conf.d/osmc.key
require_certificate false
当我使用以下命令运行 mosquitto 时
$sudo mosquitto -c /etc/mosquitto/mosquitto.conf -d
正如我所见,代理可以正确初始化:
$ sudo netstat -tulpn | grep mosquitto
tcp 0 0 0.0.0.0:8883 0.0.0.0:* LISTEN 23266/mosquitto
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN 23266/mosquitto
tcp6 0 0 :::8883 :::* LISTEN 23266/mosquitto
tcp6 0 0 :::1883 :::* LISTEN 23266/mosquitto
但重启后,使用相同的命令我注意到 Mosquitto 没有在端口 8883 上运行
$ sudo netstat -tulpn | grep mosquitto
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN 269/mosquitto
tcp6 0 0 :::1883 :::* LISTEN 269/mosquitto
如何在启动时使用正确的 mosquitto.conf 文件运行 mosquitto?
答案1
我在使用 Raspbian Jessie 时也遇到了同样的问题。文档说将配置文件放在 /etc/mosquitto/conf.d/ 中
但是,我的 /etc/init.d/mosquitto 文件正在 /etc/mosquitto 文件夹中查找 mosquitto.conf。阅读您的文件以查看它在启动时查找的位置。还要检查 /etc/init/mosquitto.conf 内部。
更改 init.d 和 init 中的文件或将更改后的配置文件放在 etc/mosquitto 中即可解决问题。