Install Mosquitto MQTT Broker

Mosquitto broker can be installed in different way. Here we are focusing to setup it on docker and Mosquitto 1.6.9 version.

To install Mosquitto broker on your host system follow this guide

mosquitto.conf

Detailed information is on Mosquitto Website

# create mosquitto.conf
mkdir -p /opt/apps/mosquitto
cd /opt/apps/mosquitto

cat << EOF > mosquitto.conf
allow_anonymous true
persistence false
persistence_location /mosquitto/data/
EOF

Install

mkdir -p /opt/apps/mosquitto
cd /opt/apps/mosquitto

docker run -d --name mc_mosquitto \
    --publish 1883:1883 \
    --publish 9001:9001 \
    --volume $PWD/mosquitto.conf:/mosquitto/config/mosquitto.conf \
    --restart unless-stopped \
    eclipse-mosquitto:1.6.9

To see the logs

  • Prints all available logs
    docker logs mc_mosquitto
    
  • Prints and tails the logs, to get exit do Ctrl+C
    docker logs --follow mc_mosquitto
    

Restart

docker restart mc_mosquitto

Uninstall

docker stop mc_mosquitto
docker rm mc_mosquitto
Last modified June 14, 2021: update installation guide (2fd41a2)