November 25, 2022

Install MQTT Broker (Mosquitto) on centos 8

 In this article we will see how to Install MQTT Broker (Mosquitto) on centos 8.

We will be using the Eclipse-Mosquitto for MQTT configuration. 

Overview of Steps:

Install the Mosquitto

Configure The Mosquitto

Test the Server

Detailed Steps:

Step 1. Install the Mosquitto

[root@localhost ~]# sudo yum install -y

[root@localhost ~]# sudo yum -y install mosquitto

[root@localhost ~]# sudo systemctl start mosquitto

[root@localhost ~]# sudo systemctl enable mosquitto

Step 2. Configure The Mosquitto with Auth, let's choose username/password auth.:

[root@localhost ~]# sudo mosquitto_passwd -c /etc/mosquitto/passwd username

then Choose the password

Step 3. Adding Port: Run the following command to allow port in firewall:

[root@localhost ~]# sudo firewall-cmd --permanent --zone=public --add-port=1883/tcp

[root@localhost ~]# sudo firewall-cmd --reload

Step 4. Test The Server

[root@localhost ~]# mosquitto_sub -t demo/one -h -u username -P password -p 1883

[root@localhost ~]# mosquitto_pub -t demo/one -h -u username -P password -p 1883 -m '{"message": 1}'

Written by Sushanth, personal technology columnist and founder of Logical Bee. You can follow him on the social web or sign up for the email newsletter for your daily dose of how-to guides and video tutorials.