`
rensanning
  • 浏览: 3515459 次
  • 性别: Icon_minigender_1
  • 来自: 大连
博客专栏
Efef1dba-f7dd-3931-8a61-8e1c76c3e39f
使用Titanium Mo...
浏览量:37509
Bbab2146-6e1d-3c50-acd6-c8bae29e307d
Cordova 3.x入门...
浏览量:604425
C08766e7-8a33-3f9b-9155-654af05c3484
常用Java开源Libra...
浏览量:678233
77063fb3-0ee7-3bfa-9c72-2a0234ebf83e
搭建 CentOS 6 服...
浏览量:87357
E40e5e76-1f3b-398e-b6a6-dc9cfbb38156
Spring Boot 入...
浏览量:399894
Abe39461-b089-344f-99fa-cdfbddea0e18
基于Spring Secu...
浏览量:69092
66a41a70-fdf0-3dc9-aa31-19b7e8b24672
MQTT入门
浏览量:90534
社区版块
存档分类
最新评论

MQTT入门(5)- 服务器Servers/Brokers

 
阅读更多
虽然有免费的公开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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics