Install Mosquitto with Websockets on Centos

Here are my notes on how to retrieve, compile and configure Mosquitto with Websockets on Centos 7. Installing websockets on Centos required to compile the library and it was a longer process than with Mint but doable nevertheless.

yum install wget mercurial cmake openssl-devel c-ares-devel libuuid-devel
yum install git gcc gcc-c++

git clone

cd libwebsockets
mkdir build
cd build
cmake .. -DLIB_SUFFIX=64
make install

Get the version that you prefer by changing the tar.gz file name below

tar xvzf mosquitto-1.4.10.tar.gz
cd mosquitto-1.4.10/


# Build with websockets support on the broker.

sudo make install

adduser mosquitto
mosquitto_passwd -c /etc/mosquitto/pwfile mosquitto

vi /etc/mosquitto/mosquitto.conf

# =================================================================
user mosquitto

# =================================================================
listener 1883
protocol mqtt

listener 9001
protocol websockets

# =================================================================
persistence true
persistence_location /var/lib/mosquitto/

# =================================================================
log_dest syslog

log_type error
log_type warning
log_type notice
log_type information

Two commands, different style. Fix some paths for the libraries

echo “/usr/local/lib64” | sudo tee -a /etc/
echo /usr/local/lib > /etc/



Test the setup by using two additional shells one for each of the two commands below
mosquitto_sub -h localhost -t “greetings” -v
mosquitto_pub -h localhost -t “greetings” -m “hello”

NB The commands about do not test the websockets on port 9001 for which you would need to develop a Javascript test program or similar

One comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.