如何自建MQTT服务器?详细配置及实例

mcg0312
mcg0312 This guy is lazy,Introduction has not been set

0 People liked this article · 6348 views

本文介绍使用windows版mosquitto软件,自建一个服务器用于测试产品IG532。

1.登录官网,下载windows版mosquitto软件,并安装

https://mosquitto.org/download/

mosquitto-2.0.15-install-windows-x64.exe

2.使用默认IP和端口127.0.0.1:1883,先测试一下

a.打开第一个CMD终端,启动代理服务器:

9fc17f65bee0a366b9cfd321489a4acf.png

b.打开第二个CMD终端,作为客户端1,订阅主题:

4759a3718f39a7835860b59a369bfbc1.png

c.打开第三个CMD终端,作为客户端2,发布主题和消息:

962ff4bd98ab8f2066d92a13fea7960c.png

3.使用指定IP和端口:192.168.2.8:18888

a.修改配置文件:mosquitto.conf;将以下内容加入到配置文件并保存:

listener 18888 192.168.2.8

log_dest file my_mosquitto.log

log_type error

log_type warning

log_type notice

log_type information

allow_anonymous false

password_file my_mosquitto_pwd_file.cfg

b.创建用户名和口令,用于登录MQTT服务器:

mosquitto_passwd.exe -H sha512 -c my_mosquitto_pwd_file.cfg admin

ba3daebee13320b08ee85e331424a079.png

c.查看口令文件my_mosquitto_pwd_file.cfg的内容:

dc26e080db0bc68fdcfdddbbe0eaa66f.png

d.配置路由及防火墙,使其他客户端与192.168.2.8均相互PING通

e.打开第一个CMD终端,启动代理服务器(指定配置文件):

3f19fde32bd58cb1742023f5b1db03e0.png

f.打开第二个CMD终端,作为客户端1,订阅主题(指定IP、端口、用户名、口令):

b9226e2af4af0d07bb912b1c946f8d24.png

g.打开第三个CMD终端,作为客户端2,发布主题和消息(指定IP、端口、用户名、口令):

e37f5a53ead528689e2a1387f24ba9a3.png

h.IG532连接自建MQTT服务器成功

f70131a4f39a6da2e9f68e93369b3b90.png

5a94e8bedfdc437cc8aeabd73fcb9278.png

i.使用mqtt.fx订阅主题

80613ea81996f0cb5db0d278d7a45981.png

c6c408a9216df8e16106ba3f0e174d02.png


Published on 2023-11-29 10:26

Disclaimers:

This document is written by mcg0312 Original published on 技术社区 ,The copyright belongs to the author。

Log in,More exciting content waiting for you to find,Contribute wonderful answers,Participate in comment interaction

go Sign in! No accountgoregister