Installing Mosquitto on Debian 9

MQTT or Message Queuing Telemetry Transport, is an ISO standard (ISO/IEC PRF 20922) publish-subscribe-based messaging protocol.

Mosquitto by Eclipse is an open source implementation of an MQTT message broker. It currently implements MQTT protocol versions 5.0, 3.1.1 and 3.1. It’s lightweight and suitable for use on all devices from low power single board computers to full servers.

Installation is very easy considering that it is provided by apt:

apt install mosquitto

After installation Mosquitto should be running as a service. You can use these commands to check the status, or start and stop:

service mosquitto status
service mosquitto start
service mosquitto stop

Or the systemctl version:

systemctl status mosquitto
systemctl start mosquitto
systemctl stop mosquitto

Testing your installation

To test our new installation we need to install a few extra packages:

apt install mosquitto-clients

To subscribe to topic1 subtopic2 we use the following command:

mosquitto_sub -v -t "/topic1/subtopic1"

In an other console session you can then enter following command to publish a message to this subtopic:

mosquitto_pub -m "test message" -t "/topic1/subtopic1"

If the message is received in your first session your MQTT installation is working as intended. By default mosquitto listens on all interface. To only allow traffic from localhost add “bind_address localhost” to “/etc/mosquitto/mosquitto.conf” and restart the service.