How to install Mosquitto to use mqtt service in centos

To install Mosquitto to use mqtt service in centos we have to follow below steps


#sudo yum -y install epel-release

install Mosquitto to use mqtt service in centos step 1
#sudo yum -y install mosquitto

install Mosquitto to use mqtt service in centos step 2

#sudo systemctl start mosquitto

We also need to enable the service to make sure it starts up when we reboot the system


#sudo systemctl enable mosquitto

#mosquitto_pub -h localhost -t test -m "hello world"

Installing Let’s Encrypt SSL Certificates

sudo yum -y install certbot

Use firewall-cmd to add the HTTP service.

#sudo firewall-cmd --permanent --add-service=http

Reload the firewall so the changes take effect.

#sudo firewall-cmd --reload
#sudo certbot certonly --standalone --preferred-challenges http-01 -d mqtt.tutorialshore.com

Add a new user “user1”

# sudo mosquitto_passwd -c /etc/mosquitto/passwd user1
# sudo vi /etc/mosquitto/mosquitto.conf
add below line 



allow_anonymous false
password_file /etc/mosquitto/passwd/strong>

mosquitto.conf



#sudo systemctl restart mosquitto

Now subscribe to a topic names “topic1”

#mosquitto_sub -h mqtt.tutorialshore.com-t topic1 -u "user1" -P "#password#"

open another terminal and get publish a message

#mosquitto_pub -h localhost -t "topic1" -m "Open window" -u "user1" -P "#password#"

Now restart Mosquitto .

#sudo systemctl restart mosquitto

Update the firewall to allow connections from port 1883.

#sudo firewall-cmd --permanent --add-port=1883/tcp

reload the firewall.

sudo firewall-cmd --reload

try connecting using any of the mqtt broker app like https://play.google.com/store/apps/details?id=in.dc297.mqttclpro