虽然有免费的公开Broker服务可以使用,当初步理解了MQTT协议之后,就有必要自己动手搭建一台Broker了。这样才能更深入的学习MQTT的更多内容。开源的Broker有很多,目前主流的Broker有以下3个:
- Mosquitto:https://mosquitto.org/
- VerneMQ:https://vernemq.com/
- EMQTT:http://emqtt.io/
其他更多的可以参考:https://github.com/mqtt/mqtt.github.io/wiki/servers
Mosquitto 是当前用户最多的一款产品,用C开发的。其他两个(VerneMQ、EMQTT)是用Erlang语言开发的。
CentOS7 里安装Mosquitto Broker
(1)安装mosquitto
# yum -y install epel-release
# yum -y install mosquitto
启动服务
# systemctl start mosquitto
# netstat -nlp | grep 1883
测试确认(开启2个Terminal分别执行以下2个命令)
# mosquitto_sub -h localhost -t test/rensanning/mosquitto/t1
# mosquitto_pub -h localhost -t test/rensanning/mosquitto/t1 -m "hello world"
执行完mosquitto_pub命令后,在mosquitto_sub窗口能看到"hello world"消息的显示。
(2)设置密码
# mosquitto_passwd -c /etc/mosquitto/passwd rensanning
Password:123456
Reenter password:123456
# mv /etc/mosquitto/mosquitto.conf /etc/mosquitto/mosquitto.conf.bak
# vi /etc/mosquitto/mosquitto.conf
allow_anonymous false
password_file /etc/mosquitto/passwd
# systemctl restart mosquitto
密码确认
# mosquitto_pub -h localhost -t test/rensanning/mosquitto/t2 -m "hello world2"
Connection Refused: not authorised.
Error: The connection was refused.
# mosquitto_sub -h localhost -u "rensanning" -P "123456" -t test/rensanning/mosquitto/t2
# mosquitto_pub -h localhost -u "rensanning" -P "123456" -t test/rensanning/mosquitto/t2 -m "hello world2"
执行完mosquitto_pub命令后,在mosquitto_sub窗口能看到"hello world2"消息的显示。
配置文件mosquitto.conf的举例内容可以参考官网说明:
https://mosquitto.org/man/mosquitto-conf-5.html
(3)客户端工具确认
使用Eclipse Paho MQTT Utility连接搭建的服务器测试确认。
设置用户名和密码
连接、订阅、发布确认
Windows 7里安装Mosquitto Broker
(1) 从 https://mosquitto.org/download/ 下载安装文件mosquitto-1.4.14-install-win32.exe
(2) 执行安装文件会提示下载OpenSSL 和 pThreads。
(3) 继续执行完安装后,会提示SSLEAY21.dll找不到。
(4) 下载 Win32OpenSSL_Light-1_0_2n.exe 并安装。(注意选择把OpenSSL DLLS复制到 OpenSSL的安装目录下)
OpenSSL: http://slproweb.com/products/Win32OpenSSL.html
(5) 下载 pthreadVC2.dll
pThreads: ftp://sources.redhat.com/pub/pthreads-win32/dll-latest/dll/x86/
(6) 把下边三个文件复制到 C:\Program Files (x86)\mosquitto 里。
C:\Program Files (x86)\OpenSSL-Win32\libeay32.dll
C:\Program Files (x86)\OpenSSL-Win32\ssleay32.dll
pthreadVC2.dll
(7) 再次执行 安装文件 mosquitto-1.4.14-install-win32.exe 就可安装完成。
(8) 通过控制面板>管理工具>服务,启 Mosquitto Broker 服务后在命令行工具里执行 netstat -an 查看端口是否开启。
参考:
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-centos-7
- 大小: 51.1 KB
- 大小: 131.6 KB
- 大小: 12.8 KB
- 大小: 27 KB
- 大小: 12.9 KB
- 大小: 8.5 KB
- 大小: 13.4 KB
分享到:
相关推荐
MQTT中文文档,帮助理解MQTT具体协议,用于创建服务器或者客户端
mqtt-xmeter-2.0.2-jar-with-dependencies.zip
mqtt-xmeter-syl-jar-with-dependencies.rar
MQTT-3.1.1-CN(学习MQTT协议的完整中文资料),该文档详细描述了MQTT协议,希望对MQTT深入学习的童鞋值得下载。
编译好的paho mqtt c和cpp,含。deb安装包,在paho-matt-cpp/build下的deb文件。 直接安装命令:sudo dpkg -i libpaho-mqtt.cpp-1.2.0-Linux.deb
jmeter-mqtt插件应用于Jmeter对mqtt服务器压力测试
mqtt linux paho.mqtt.embedded-c-master.zip软件包
JMeter测试Mqtt协议所需jar
mqtt.fx-1.7.1-windows-x64位安装包,完美使用
paho.mqtt.embedded-c-master.zip paho.mqtt.embedded-c-master.zip paho.mqtt.embedded-c-master.zip
MQTT (Message Queue Telemetry Transport),翻译成中文就是,遥测传输协议,其主要提供了订阅/发布两种消息模式,更为简约、轻量,易于使用,特别适合于受限环境(带宽低、网络延迟高、网络通信不稳定)的消息分发...
mqtt-client-0.4.0.jar
paho.mqtt.c-master,mqtt C语言库
# Eclipse Paho MQTT C/C++ client for Embedded platforms This repository contains the source code for the [Eclipse Paho](http://eclipse.org/paho) MQTT C/C++ client library for Embedded platorms.
赠送jar包:mqtt-client-1.3.jar; 赠送原API文档:mqtt-client-1.3-javadoc.jar; 赠送源代码:mqtt-client-1.3-sources.jar; 包含翻译后的API文档:mqtt-client-1.3-javadoc-API文档-中文(简体)版.zip 对应...
mqtt协议的开源实现,中国移动onenet平台MQTT套件中官方c demo使用的第三方库paho.mqtt.c-1.3.0
mqtt-client-1.5-uber.jar
赠送jar包:mqtt-client-1.3.jar; 赠送原API文档:mqtt-client-1.3-javadoc.jar; 赠送源代码:mqtt-client-1.3-sources.jar; 包含翻译后的API文档:mqtt-client-1.3-javadoc-API文档-中文(简体)-英语-对照版....
MQTT-3.1.1-CN,MQTT协议中文版。不错的资料。