BLOG MOVED
Please click the link below to read in new location.
http://goochgooch.co.uk/2014/08/01/building-mosquitto-1-4/
How to build Mosquitto
EDIT (21st Jan 2015): updated to reflect move of repo.
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.
I asked a question on StackOverflow and, in mid-July 2014, Mosquitto got websockets. This will allow us to more easily use existing security models for MQTT.
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…
Install libwebsockets
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 git tools
sudo apt-get install mercurialsudo apt-get install git
Clone the Mosquitto repo and switch to the 1.4 branch
cd <SRC> # i.e. your source code homehg clone ssh://hg@bitbucket.org/oojah/mosquitto cd mosquitto/ hg pull && hg update 1.4git clone https://git.eclipse.org/r/mosquitto/org.eclipse.mosquitto cd org.eclipse.mosquitto/ git checkout origin/1.4
make it
First edit config.mk
and ensure that the websockets option is set to “yes”.
WITH_WEBSOCKETS:=yes
Then install pre-reqs:-
sudo apt-get install uuid-dev xsltproc docbook-xsl
And then…
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.
Brass Moustaches
zlib
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
ares.h
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/brokercd <SRC>/org.eclipse.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 then:-
sudo ldconfig
…and try the test again.
Public key error when cloning Bitbucket repo
If you get an error when cloning the Bitbucket repository, such as:-
remote: Permission denied (publickey). abort: no suitable response from remote hg!
…then you might need to load your public key into Bitbucket.
Brass Moustache for Raspberry Pi:
I needed to remove Ipv6 support from libwebsocket 1.3 with cmake .. -DLWS_IPV6=OFF.
LikeLike
Thanks! It took a bit of bashing to get working with CentOS but I’m up and running now.
LikeLike
root@Kafka-8:~/z# hg clone ssh://hg@bitbucket.org/oojah/mosquitto
remote: Warning: Permanently added the RSA host key for IP address ‘131.103.20.167’ to the list of known hosts.
remote: Permission denied (publickey).
abort: no suitable response from remote hg!
what can it be?
LikeLike
https://confluence.atlassian.com/pages/viewpage.action?pageId=302811860
You’ll need to have a bitbucket account, and load your SSH key into it.
LikeLiked by 1 person
Thanks. That seems familiar, so I think I might have hit it myself and should have added it to the “Brass Moustaches” section. I’ll make a small update…
LikeLike
Great post, really helpful! You can just grab it over HTTPS as it’s a public repo so running `hg clone https://bitbucket.org/oojah/mosquitto` should do the trick.
LikeLike
Thanks for your post. I created a Dockerfile and Docker Image for Centos 7, which builds mosquito 1.4.
Use with
“`
docker run -it –rm weitzj/mosquittobin:1.4.0_centos7_websocket mosquitto
“`
LikeLike
Dockerfile: https://raw.githubusercontent.com/weitzj/mosquittobin/1.4.0_centos7_websocket/Dockerfile
LikeLiked by 1 person
looks like the bitbucket repo is no longer the place to go, try
http://git.eclipse.org/c/mosquitto/org.eclipse.mosquitto.git/
LikeLike
Thanks – it does seem to have moved. I’ll update the instructions.
LikeLike
Thank you for the original post, very useful indeed! And thank you to those that got on board and contributed additions and Dockerfiles. This kind of global software collaboration/organization is what gives me hope for the future.
LikeLike
Thanks a lot for this post!
I compiled mosquitto on an RPi B2, updated to jessie. I ran into some issues (ares.h missing, make test and libwebsockets) and even these problems were perfectly covered by this posting.
LikeLiked by 1 person
Hi, previously I had to use willem4ever’ s modules to enable websocket in apache for mosquitto https://github.com/willem4ever/mod_websocket_mosquitto
Now I see this splendid tutorial with native websocket modules modules directly from mosquitto , but since time has passed and we are to mosquitto version 1.4.7 I don’t understand If this is still needed or there are also linux packages with websocket enabled.
LikeLike