MQTT服务器搭建-mosquitto1.4.4安装指南
Mosquitto
mosquitto是一款实现了 MQTT v3.1 协议的开源的消息代理服务软件.
其提供了非常轻量级的消息数据传输协议,采用发布/订阅模式进行工作,可用于物联设备、中间件、APP客户端之间的消息通讯。
mosquitto官网
http://mosquitto.org/
关于mqtt协议可参考
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
基础准备
Linux内核版本:Centos 6.5_final_64bit
安装基础软件
yum install gcc-c++
yum install cmake
yum install openssl-devel //mosquitto默认支持openssl
下载程序
官网下载
wget http://mosquitto.org/files/source/mosquitto-1.4.4.tar.gz
tar -xzvf mosquitto-1.4..tar.gz
cd mosquitto-1.4.
编译安装
编译选项
当前的程序目录可直接编译,在编译之前需根据需要做一定的配置,否则会出现 xxx.h找不到的情况。
vim config.mk
config.mk包括了多个选项, 可按需关闭或开启,但一旦开启则需要先安装对应的模块
模块说明
|
选项
|
说明
|
make出错信息
|
WITH_SRV |
启用c-areas库的支持,一个支持异步DNS查找的库 见http://c-ares.haxx.se |
missing ares.h |
WITH_UUID |
启用lib-uuid支持,支持为每个连接的客户端生成唯一的uuid |
missing uuid.h |
WITH_WEBSOCKETS |
启用websocket支持,需安装libwebsockets 对于需要使用websocket协议的应用开启 |
missing libwebsockets.h
|
安装c-areas
wget http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz
tar xvf c-ares-1.10..tar.gz
cd c-ares-1.10.
./configure
make
sudo make install
安装lib-uuid
yum install libuuid-devel
安装libwebsockets
wget https://github.com/warmcat/libwebsockets/archive/v1.3-chrome37-firefox30.tar.gz
tar zxvf v1.-chrome37-firefox30.tar.gz
cd libwebsockets-1.3-chrome37-firefox30
mkdir build; cd build;
cmake .. -DLIB_SUFFIX=
make install
//若遇到以上模块无法安装的情况,可将对应模块选项关闭即可,但相应功能也将无法提供;
开始安装mosquitto
make
make install
至此程序已经安装完毕!
程序文件将默认安装到以下位置
| 路径 | 程序文件 |
| /usr/local/sbin | mosquiotto server |
| /etc/mosquitto | configuration |
| /usr/local/bin | utility command |
修正链接库路径
由于操作系统版本及架构原因,很容易出现安装之后的链接库无法被找到,如启动mosquitto客户端可能出现找不到
libmosquitto.so.1文件,因此需要添加链接库路径
//添加路径
vim /etc/ld.so.conf.d/liblocal.conf
/usr/local/lib64
/usr/local/lib
//刷新
ldconfig
启动与测试
创建用户
mosquitto默认以mosquitto用户启动,可以通过配置文件修改
groupadd mosquitto
useradd -g mosuqitto mosquiotto
程序配置
mv /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf
配置项说明
# 服务进程的PID
#pid_file /var/run/mosquitto.pid # 服务进程的系统用户
#user mosquitto # 服务绑定的IP地址
#bind_address # 服务绑定的端口号
#port 1883 # 允许的最大连接数,-1表示没有限制
#max_connections -1 # 允许匿名用户
#allow_anonymous true
//关于详细配置可参考
http://mosquitto.org/man/mosquitto-conf-5.html
启动
mosquitto -c /etc/mosquitto/mosquitto.conf -d
成功将启动1883端口监听
客户端测试
新建两个shell端口A/B
A 订阅主题:
mosquitto_sub -t location
B 推送消息:
mosquitto_pub -t location -h localhost -m "new location"
可以在A窗口看到由B推送的消息,此外服务端窗口也可以看到客户端连接和端口的日志
: New client connected from 127.0.0.1 as mosqpub/-iZ94eb8yq (c1, k60).
: Client mosqpub/-iZ94eb8yq disconnected.、
FAQ
启动mosquitto报错
error while loading shared libraries: libwebsockets.so.4.0.0: cannot open shared object file: No such file or directory
或者
error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
解决方法
找不到链接库,通过locate或find命令找到libwebsockets.so.4.0.0,将其目录添加至ldconfg配置中:
vim /etc/ld.so.conf.d/liblocal.conf
/usr/local/lib64
/usr/local/lib
ldconfig
//执行ln -s 添加软连接的方式也可行
编译找不到openssl/ssl.h
解决方法
yum install openssl-devel
编译报错
mosquitto.c:871: error: ‘struct mosquitto’ has no member named ‘achan’
找不到areas.h
解决方法
安装 c-areas模块(见上文)或将config.mk中WITH_SRV选项关闭
make test 提示不支持协议
参考文档
mosquitto1.4 搭建日记
https://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/
Ubuntu下搭建教程(日文)
http://qiita.com/aquaviter/items/cb3051cf42a3a3c4a4d9
使mosquitto支持websockets
https://www.justinribeiro.com/chronicle/2014/10/22/mosquitto-libwebsockets-google-compute-engine-setup/
使用JS实现mqtt-websocket
http://jpmens.net/2014/07/03/the-mosquitto-mqtt-broker-gets-websockets-support/
MQTT服务器搭建-mosquitto1.4.4安装指南的更多相关文章
- Mqtt服务器搭建
.bg { background: #99CC99 } Mqtt服务器搭建 测试环境:CentOS64位 1.安装基础软件 yum install gcc-c++ yum install cmake ...
- 个人智能家居系统 - MQTT服务器搭建(centOS7.3)
个人智能家居系统 - MQTT服务器搭建(centOS7.3) 0x00 参考 在CentOS7 上安装mosquitto1.4.1服务器,实现MQTT信息推送功能并增加websocket功能 mos ...
- 常见MQTT服务器搭建与试用
常见MQTT服务器搭建与试用 简介 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)是IBM开发的一个即时通讯协议,它比较适合于在低带宽.不可靠 ...
- 常见MQTT服务器搭建[转载]
简介 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)是IBM开发的一个即时通讯协议,它比较适合于在低带宽.不可靠的网络的进行远程传感器和控制设备通 ...
- Apollo mqtt 服务器搭建
html { overflow-x: initial !important } :root { --bg-color: #ffffff; --text-color: #333333; --select ...
- MQTT——服务器搭建(一)
MQTT介绍 MQTT,是IBM推出的一种针对移动终端设备的基于TCP/IP的发布/预订协议,可以连接大量的远程传感器和控制设备: 轻量级的消息订阅和发布(publish/subscribe)协议 建 ...
- MQTT服务器搭建--Mosquitto用户名密码配置
Mosquitto用户认证配置 前言:基于Mosquitto服务器已经搭建成功,大部分都是采用默认的是允许匿名用户登录模式,正式上线的系统需要进行用户认证. 1.用户参数说明 Mosquitto服务器 ...
- MQTT服务器搭建--Apollo
尊重原创,我是伸手党:https://blog.csdn.net/u012377333/article/details/68943416 1.Apollo下载 下载地址:http://activemq ...
- Windows 下 MQTT 服务器搭建之Apollo
https://blog.csdn.net/wangh0802/article/details/84861226#%EF%BC%881%EF%BC%89%E4%B8%8B%E8%BD%BD%20Apo ...
随机推荐
- Android 自定义波浪动画 --"让进度浪起来~"
原文链接:http://www.jianshu.com/p/0e25a10cb9f5 一款效果不错的动画,实现也挺简单的,推荐阅读学习~ -- 由 傻小孩b 分享 waveview <Andro ...
- checkbox将选中的数据提交到后台
在项目中有些地方需要批量添加的数据,在这里使用到checkbox比较方便一些. 例如:我需要将多个包添加到同一个地区的 主要的前端代码: 这个是用来放checkbox的. <div id=&qu ...
- 分方式缓存常用的一致性hash是什么原理
分方式缓存常用的一致性hash是什么原理 一致性hash是用来解决什么问题的?先看一个场景有n个cache服务器,一个对象object映射到哪个cache上呢?可以采用通用方法计算object的has ...
- JAVA学习之路(环境配置,)
最近过去的寒假我就开始看一些JAVA的学习视频了,视频是毕向东老师的,讲得还不错,东北口音,欧了没? 首先是一些基础概念. 1.JAVA的三种技术架构 企业版 J2EE 标准版 J2SE 小型版 J2 ...
- Yii2框架安装(windows)
-->安装PHP环境Wamp集成环境,XAMMP等.-->安装Composerhttp://pan.baidu.com/s/1i3fejjvPS:安装过程中的有一个手动操作项选择php.e ...
- pagemap, from the userspace perspective
pagemap, from the userspace perspective --------------------------------------- pagemap is a new (as ...
- ARM汇编程序基本知识
ARM汇编程序基本知识 1.汇编程序的基本组成 ARM汇编语言程序中,程序是以程序段为单位组织代码的.段是相对独立的指令或者代码序列,拥有特定的名称.段的种类有代码段.数据段和通用段,代 码段的内容为 ...
- Topcoder SRM584 DIV 2 500
#include <set> #include <iostream> #include <string> #include <vector> using ...
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局 一.项目文件结构和plist文件 二.实现效果 三.代码示例 1.没有使用配套的类,而是直接使用xib文 ...
- .htaccess保护目录与文件
一般来说很多虚拟主机预设是没有开启保护网站主机目录下的文件,其实很危险的,假若你的目录下忘记放置index文件,那很可能您目录就被看光,一个不小心很可能重要资料就被拿走,这是蛮严重的一件事情.如果是L ...