/notebook/linux-special-topics/mqtt

Installing and Setting up MQTT


Installation

sudo apt update
sudo apt install -y mosquitto mosquitto-clients
sudo snap install mqtt-explorer

Example Setup

sudo cp /usr/share/doc/mosquitto/examples/mosquitto.conf /etc/mosquitto/conf.d/

Firewall

If you have UFW set up make sure you add permission:

sudo ufw allow 1883

Simple Setup

MYIP1="<put your first ip address here>"
MYIP2="<put your second ip address here>"
cat <<EOT | tee ~/mosquitto.conf
listener 1883
allow_anonymous true
EOT
sudo install -o root -g root -m 644 mosquitto.conf /etc/mosquitto/conf.d/mosquitto.conf
sudo systemctl restart mosquitto
rm ~/mosquitto.conf

Advanced Setup

This setup could be used for many users, to limit footprint

MYIP="<put your ip address here>"
cat <<EOT | tee ~/mosquitto.conf
listener 1883 $MYIP
allow_anonymous true
max_inflight_messages 1
max_inflight_bytes 500
message_size_limit 100
max_queued_bytes 500
max_queued_messages 3
#memory_limit 2000000
EOT
sudo install -o root -g root -m 644 mosquitto.conf /etc/mosquitto/conf.d/mosquitto.conf
rm ~/mosquitto.conf

Service Instructions

sudo systemctl enable mosquitto
sudo systemctl start mosquitto
sudo systemctl status mosquitto

Other Useful commands

sudo systemctl restart mosquitto
sudo systemctl stop mosquitto
sudo systemctl disable mosquitto
  • See the docker setup page

Other Resources

Secure MQTT info

ca_maker produces:

. |-- CA | |-- ca_crt.der | |-- ca_crt.pem | |-- ca_crt.srl | -- ca_key.pem |-- DH |-- dhp_ffdhe2048.pem |-- clients | |-- ca_crt.der | -- ca_crt.pem |-- csr_files |-- server_req.csr -- server |-- server_crt.pem-- server_key.pem

client_maker produces in addition

. |-- clients | -- student | |-- ca_crt.pem | |-- student_crt.pem |-- student_key.pem |-- csr_files | `-- student_req.csr

About

I am an engineer and educator, having spent ten years as a professor. My goal is to help you build your knowledge of design and technology, get your hardware working, and propel your startup or small business. Get in touch!