Site icon DIY Usthad

Mosquitto MQTT broker does not restart after altering the config file

You might have faced some issues after editing the /etc/mosquitto/mosquitto.conf file, follow the below solution to solve the issue

Error:

Job for mosquitto.service failed because the control process exited with error code.
See “systemctl status mosquitto.service” and “journalctl -xeu mosquitto.service” for details.

Solution:

Place your custom configuration files in the /etc/mosquitto/conf.d/ directory, which is included by default in Mosquitto’s configuration. To add listener 1883 and allow_anonymous false, you should create a new configuration file inside /etc/mosquitto/conf.d/. Here’s how you can do it:

Step-by-Step Guide:

  1. Create a Custom Configuration File: Open a terminal and use your favorite text editor to create a new file in /etc/mosquitto/conf.d/. For example:sudo nano /etc/mosquitto/conf.d/custom.conf
  2. Add Your Configuration: Inside this file, add the following lines:
    listener 1883
    allow_anonymous false
  3. Save and Exit:
    • If you’re using nano, press Ctrl + O to save the file, then Ctrl + X to exit.
  4. Restart the Mosquitto Service: After making changes, restart Mosquitto to apply the new configuration:sudo systemctl restart mosquitto
  5. Verify the Configuration: Check if Mosquitto is running with the new settings:sudo systemctl status mosquitto
    You can also test the MQTT broker using a client tool like mosquitto_sub or mosquitto_pub.

By placing your custom settings in /etc/mosquitto/conf.d/custom.conf, you ensure the main mosquitto.conf file remains untouched while adhering to best practices.

Exit mobile version