卓泰科技 发表于 2016-6-5 16:04:37

【Joytag 香蕉派】在香蕉派M3上安装和使用Mosquitto

原文信息

标题:【Joytag 香蕉派】在香蕉派M3上安装和使用Mosquitto
连接:http://forum.godpub.com/thread-121-1-1.html
备注:狗趴论坛首发,转载请注明出处。


简介

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
至此我们完成了安装的全部过程。


其它安装方式

除了使用源码编译安装外,我们可以使用以下安装方式直接安装和使用mosquittosudo 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奠定了一个基础。
谨以本文抛砖引玉,希望大家折腾出更好玩的东西。

后续更多精彩内容,请关注狗趴论坛:http://www.godpub.com

卓泰科技 发表于 2016-6-5 16:45:54

(一)
删除apt-get方式安装的mosquitto, mosquitto-clients 以及库等

dpkg -l | grep mosq
使用apt-get remove 删除无用的以及库等,例如:
sudo apt-get remove mosquitto

(二)
删除编译源码方式安装的mosquitto, mosquitto-clients 以及库等
进入到源码目录
sudo make uninstall

leslie99 发表于 2021-3-23 16:47:55

你不知道我在想你,是幸运飞艇因为你不爱我,我明明知道你不想我,却还爱你,是因为十一运夺金太傻。也许有时候,逃避超级大乐透不是因为害怕去面对什么,而是在等待什么。
页: [1]
查看完整版本: 【Joytag 香蕉派】在香蕉派M3上安装和使用Mosquitto