Why are we doing this?
I wanted to use MQTT to interact with a browser-based application in order to deliver real-time interactions such as notifications. Having read Oriel Ruis’ instructions, my initial approach was to put Lighttpd in front of Mosquitto, and tunnel websockets, but it was perplexing how we were going to secure it.
However, since (at the time of writing) it was still pre-release, we need to compile v1.4 ourselves.
How to do it
These instructions were successful on a clean build of Mint Linux 17, i.e. Ubuntu 14.04.
The Brass Moustaches section towards the end of this post lists the additional steps I took due to missing dependencies.
Your mileage may vary…
Option 1: build instructions for an newer version…
sudo apt-get install cmake libssl-dev cd <SRC> # i.e. your source code home wget http://git.warmcat.com/cgi-bin/cgit/libwebsockets/snapshot/libwebsockets-1.3-chrome37-firefox30.tar.gz tar -xzvf libwebsockets-1.3-chrome37-firefox30.tar.gz cd libwebsockets-1.3-chrome37-firefox30/ mkdir build cd build cmake .. -DOPENSSL_ROOT_DIR=/usr/bin/openssl make sudo make install
Option 2: build instructions for an older version…
cd <SRC> # i.e. your source code home wget http://git.warmcat.com/cgi-bin/cgit/libwebsockets/snapshot/libwebsockets-1.22-chrome26-firefox18.tar.gz tar -xzvf libwebsockets-1.22-chrome26-firefox18.tar.gz sudo apt-get install autoconf cd libwebsockets-1.22-chrome26-firefox18/ ./autogen.sh ./configure make sudo make install
Install Mercurial tools
sudo apt-get install mercurial
Clone the Mosquitto repo and switch to the 1.4 branch
cd <SRC> # i.e. your source code home hg clone ssh://firstname.lastname@example.org/oojah/mosquitto cd mosquitto/ hg pull && hg update 1.4
config.mk and ensure that the websockets option is set to “yes”.
Then install pre-reqs:-
sudo apt-get install uuid-dev xsltproc docbook-xsl
make make test sudo make install
If need be, edit or create your config file and create the service user ID.
sudo vi /etc/mosquitto/mosquitto.conf sudo useradd -r -m -d /var/lib/mosquitto -s /usr/sbin/nologin -g nogroup mosquitto
Then start it up…
sudo /usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
And you’re done.
If you get an error about missing zlib, do this:-
cd <SRC> # i.e. your source code home wget http://zlib.net/zlib-1.2.8.tar.gz tar xvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure make make test sudo make install
If you get an error about missing ares.h, do this:-
cd <SRC> # i.e. your source code home wget http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz tar xvf c-ares-1.10.0.tar.gz cd c-ares-1.10.0 ./configure make sudo make install
make test and libwebsockets
make test failed for me. As per https://answers.launchpad.net/mosquitto/+question/252173, it might be that the websockets build has not put the library on the shared library path.
To diagnose this, just try bringing the test broker up directly:-
cd <SRC>/mosquitto/test/broker ../../src/mosquitto -p 1888
If it’s the shared library problem, you’ll see this immediately. To resolve this, do something like:-
find /usr -name libwebsockets.so
Mine was in /usr/local/lib64/libwebsockets.so
sudo vi /etc/ld.so.conf.d/lib64c.conf
…and add the following lines:-
# lib64c default configuration /usr/local/lib64
…and try the test again.