I've installed mosquito v2.0.11 on raspberry Pi3. I've written configuration file, allowing anonymous connections, but mosquitto seems to not load this configuration.
/etc/mosquitto/conf.d/custom.conf:
listener 1883
allow_anonymous true
When I run "mosquitto" in bash, output looks like this:
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
And "systemctl status mosquitto.service" says that congfig file was loaded. Still anonymous connections doesn't work.
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.
When I specify config file, by "mosquitto -c /etc/mosquitto/conf.d/custom.conf", configuration file is loaded properly. I don't really know how to make it work.
Mosquitto does not automatically load a configuration file, you must pass it one on the command line with the -c
flag if you want to use anything other than the default values. When run as a service the service definition include the -c
pointing to the default configuration file.
The default configuration file is normally stored in /etc/mosquitto/mosquitto.conf
. This file includes the following line:
include_dir /etc/mosquitto/conf.d
Which tells mosquitto to include all the files that end in .conf
from the /etc/mosquitto/conf.d
directory
When you tried to run mosquitto without passing it a configuration file it failed because the service was already running. If you stop it (sudo service mosquitto stop
) and then run mosquitto -c /etc/mosquitto/mosquitto.conf
it will get a little further but also fail because your user will not have access to either the default persistence file or the log file.
The simplest solution is just to restart the service with
sudo service mosquitto restart
and it will pick up the changes you made in /etc/mosquitto/conf.d/custom.conf
You should then check the log file (/var/log/mosquitto/mosquitto.log
) for indications as to why your anonymous clients are still failing to connect.