Mosquitto is a lightweight MQTT broker that uses publish/subscribe model. Since it is written in Python it can run on practically any Linux and many other systems. It also comes with command line utilities to publish and subscribe to MQTT clients.
Add a PGP signature.
gpg --recv-keys 779B22DFB3E717B7
This may take quite a while, so be patient.
Install Mosquitto from AUR with packer.
packer -S mosquitto
If the key is not added an error will occur preventing the installation.
ERROR: One or more PGP signatures could not be verified! The build failed.
Install Mosquitto Manually
Download the latest archive.
Unpack the archive.
tar xzf mosquitto-1.4.5.tar.gz
Change the current directory to the newly created directory.
Build the package.
Install the package.
sudo make install
Remove the leftover installation files.
sudo rm -Rd mosquitto-1.4.5
Remove the package archive.
sudo rm mosquitto-1.4.5.tar.gz
Create a system account and group.
sudo useradd -r -s /bin/false mosquitto
Copy configuration file from the example directory.
sudo cp /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf
Open the configuration file.
sudo nano /etc/mosquitto/mosquitto.conf
pid_file line. Optionally change the default
port and possibly other settings by uncommenting the relevant line and entering the relevant values.
Create a systemd script.
sudo nano /etc/systemd/system/mosquitto.service
Copy the script and save.
[Unit] Description=Mosquitto MQTT Broker daemon ConditionPathExists=/etc/mosquitto/mosquitto.conf Requires=network.target [Service] User=mosquitto Group=mosquitto Type=simple ExecStartPre=/usr/bin/rm -f /var/run/mosquitto.pid ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d ExecReload=/bin/kill -HUP $MAINPID PIDFile=/run/mosquitto.pid Restart=on-failure [Install] WantedBy=multi-user.target
Start the systemd service.
sudo systemctl start mosquitto
Enable the systemd service to run on boot.
sudo systemctl enable mosquitto
Subscribe to a topic with mosquitto_sub command.
mosquitto_sub -t home/frontgarden/doorbell
Publish a topic to a broker.
mosquitto_pub -h 192.168.0.100 -p 1883 -t home/livingroom/temperature -m test message
If the target broker is on the same system
-h option can be omitted as the host defaults to localhost. Similarly the
-p can be omitted if the default port is used. The topic is specified with
-t option and the message is
A fix to the
mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory error is outlined below.
Open the dynamic linker configuration file.
sudo nano /etc/ld.so.conf
/usr/local/lib line before
# End of file line line and save the file.
Configure dynamic linker run-time bindings.