Mosquitto 未从 conf.d 加载配置文件
Mosquitto isn't loading configuration files from conf.d
我在树莓派3上安装了mosquito v2.0.11。我写了配置文件,允许匿名连接,但是mosquitto好像不加载这个配置。
/etc/mosquitto/conf.d/custom.conf:
listener 1883
allow_anonymous true
当我在 bash 中 运行 "mosquitto" 时,输出如下所示:
1636892708: mosquitto version 2.0.11 starting
1636892708: Using default config.
1636892708: Starting in local only mode. Connections will only be possible from clients running on this machine.
1636892708: Create a configuration file which defines a listener to allow remote access.
1636892708: For more details see https://mosquitto.org/documentation/authentication-methods/
1636892708: Opening ipv4 listen socket on port 1883.
1636892708: Error: Address already in use
1636892708: Opening ipv6 listen socket on port 1883.
1636892708: Error: Address already in use
并且“systemctl status mosquitto.service”表示已加载 congfig 文件。仍然无法使用匿名连接。
mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-11-14 11:59:18 GMT; 27min ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Process: 471 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
Process: 481 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
Process: 482 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 483 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
Main PID: 484 (mosquitto)
Tasks: 1 (limit: 1597)
CPU: 793ms
CGroup: /system.slice/mosquitto.service
└─484 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Nov 14 11:59:18 raspberrypi systemd[1]: Starting Mosquitto MQTT Broker...
Nov 14 11:59:18 raspberrypi mosquitto[484]: 1636891158: Loading config file /etc/mosquitto/conf.d/custom.conf
Nov 14 11:59:18 raspberrypi systemd[1]: Started Mosquitto MQTT Broker.
当我指定配置文件时,通过“mosquitto -c /etc/mosquitto/conf.d/custom.conf”,配置文件被正确加载。
我真的不知道如何让它发挥作用。
Mosquitto 不会自动加载配置文件,如果您想使用除默认值。当 运行 作为服务时,服务定义包括指向默认配置文件的 -c
。
默认配置文件通常存储在/etc/mosquitto/mosquitto.conf
中。该文件包括以下行:
include_dir /etc/mosquitto/conf.d
这告诉 mosquitto 包含 /etc/mosquitto/conf.d
目录
中所有以 .conf
结尾的文件
当您尝试 运行 mosquitto 而不向其传递配置文件时,它失败了,因为该服务已经 运行ning。如果您停止它 (sudo service mosquitto stop
) 然后 运行 mosquitto -c /etc/mosquitto/mosquitto.conf
它会更进一步但也会失败,因为您的用户将无法访问默认持久性文件或日志文件。
最简单的解决方案就是用
重新启动服务
sudo service mosquitto restart
它会获取您在 /etc/mosquitto/conf.d/custom.conf
中所做的更改
然后您应该检查日志文件 (/var/log/mosquitto/mosquitto.log
) 以了解您的匿名客户端为何仍无法连接的指示。
我在树莓派3上安装了mosquito v2.0.11。我写了配置文件,允许匿名连接,但是mosquitto好像不加载这个配置。
/etc/mosquitto/conf.d/custom.conf:
listener 1883
allow_anonymous true
当我在 bash 中 运行 "mosquitto" 时,输出如下所示:
1636892708: mosquitto version 2.0.11 starting
1636892708: Using default config.
1636892708: Starting in local only mode. Connections will only be possible from clients running on this machine.
1636892708: Create a configuration file which defines a listener to allow remote access.
1636892708: For more details see https://mosquitto.org/documentation/authentication-methods/
1636892708: Opening ipv4 listen socket on port 1883.
1636892708: Error: Address already in use
1636892708: Opening ipv6 listen socket on port 1883.
1636892708: Error: Address already in use
并且“systemctl status mosquitto.service”表示已加载 congfig 文件。仍然无法使用匿名连接。
mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-11-14 11:59:18 GMT; 27min ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Process: 471 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
Process: 481 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
Process: 482 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 483 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
Main PID: 484 (mosquitto)
Tasks: 1 (limit: 1597)
CPU: 793ms
CGroup: /system.slice/mosquitto.service
└─484 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Nov 14 11:59:18 raspberrypi systemd[1]: Starting Mosquitto MQTT Broker...
Nov 14 11:59:18 raspberrypi mosquitto[484]: 1636891158: Loading config file /etc/mosquitto/conf.d/custom.conf
Nov 14 11:59:18 raspberrypi systemd[1]: Started Mosquitto MQTT Broker.
当我指定配置文件时,通过“mosquitto -c /etc/mosquitto/conf.d/custom.conf”,配置文件被正确加载。 我真的不知道如何让它发挥作用。
Mosquitto 不会自动加载配置文件,如果您想使用除默认值。当 运行 作为服务时,服务定义包括指向默认配置文件的 -c
。
默认配置文件通常存储在/etc/mosquitto/mosquitto.conf
中。该文件包括以下行:
include_dir /etc/mosquitto/conf.d
这告诉 mosquitto 包含 /etc/mosquitto/conf.d
目录
.conf
结尾的文件
当您尝试 运行 mosquitto 而不向其传递配置文件时,它失败了,因为该服务已经 运行ning。如果您停止它 (sudo service mosquitto stop
) 然后 运行 mosquitto -c /etc/mosquitto/mosquitto.conf
它会更进一步但也会失败,因为您的用户将无法访问默认持久性文件或日志文件。
最简单的解决方案就是用
重新启动服务sudo service mosquitto restart
它会获取您在 /etc/mosquitto/conf.d/custom.conf
然后您应该检查日志文件 (/var/log/mosquitto/mosquitto.log
) 以了解您的匿名客户端为何仍无法连接的指示。