Eclipse Mosquitto™ is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 3.1 and 3.1.1. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for "Internet of Things" messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino.
安装
我们使用源代码方式直接安装。
首先,到http://mosquitto.org/ 查看当前最新的源代码。 (撰写本文时,最新代码版本为1.4.9)
wget http://mosquitto.org/files/source/mosquitto-1.4.9.tar.gz
解压代码:
tar xzvf mosquitto-1.4.9.tar.gz
进入目录,并执行编译:
cd mosquitto
make
根据当前系统上已经安装的软件情况,可能会提示编译失败。
缺少"openssl/ssl.h":
In file included from mosquitto.c:33:0:
./mosquitto_internal.h:27:27: fatal error: openssl/ssl.h: No such file or directory
# include <openssl/ssl.h>
^
compilation terminated.
缺少“ares.h”:
In file included from mosquitto.c:33:0:
./mosquitto_internal.h:40:20: fatal error: ares.h: No such file or directory
# include <ares.h>
^
compilation terminated.
缺少“uuid/uuid.h”:
sudo apt-get install libc-ares-dev
read_handle_server.c:31:25: fatal error: uuid/uuid.h: No such file or directory
# include <uuid/uuid.h>
^
compilation terminated.
依次执行以下指令即可:
sudo apt-get install libssl-dev
sudo apt-get install libc-ares-dev
sudo apt-get install uuid-dev
当然,也可以提前一并安装下,以免遇到上述的恼人提示。
sudo apt-get install libssl-dev ibc-ares-dev uuid-dev
解决掉以上问题后,如无其它意外就可以编译成功了。
make
接下来,执行安装命令:
sudo make install
如果一切顺利,我们就已经成功的将由源码编译的mosquitto, mosquitto-clients 安装到我们的系统上了。
启动Mosquitto
首先,我们添加对应的用户组和用户:
sudo groupadd mosquitto
sudo useradd -g mosquitto mosquitto
复制默认的配置文件:
sudo cp /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf
在后台启用mosquitto服务:
mosquitto -c /etc/mosquitto/mosquitto.conf -d
至此我们完成了安装的全部过程。
其它安装方式
除了使用源码编译安装外,我们可以使用以下安装方式直接安装和使用mosquitto
sudo apt-get install mosquitto mosquitto-clients python-mosquitto
启动和停止:
sudo /etc/init.d/mosquitto start
sudo /etc/init.d/mosquitto stop
查看版本:
sudo mosquitto -h
mosquitto version 1.3.4 (build date 2014-08-22 06:10:51+0000)
mosquitto is an MQTT v3.1 broker.
由此可见,这种方式安装的版本还是比较旧的。
总结
本文使用编译源码的方式在BananaPi M3上安装Mosquitto,为我们进一步学习和使用MQTT奠定了一个基础。
谨以本文抛砖引玉,希望大家折腾出更好玩的东西。