Install Mosquitto with Websockets on Centos

Facebooktwittergoogle_plusredditpinterestlinkedinmail

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 https://github.com/warmcat/libwebsockets.git

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

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

wget http://mosquitto.org/files/source/mosquitto-1.4.10.tar.gz
tar xvzf mosquitto-1.4.10.tar.gz
cd mosquitto-1.4.10/

vi config.mk


# Build with websockets support on the broker.
WITH_WEBSOCKETS:=yes


make
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/ld.so.conf.d/libwebsockets.conf
echo /usr/local/lib > /etc/ld.so.conf.d/local.conf

ldconfig

 

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

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.