滴水恩情 发表于 2024-8-14 04:05:32

MQTT:windows情况下设置MQTT服务器(mosquitto)



目录
1.下载 mosquitto
2.安装 mosquitto 
3.设置 mosquitto 
4.测试 mosquitto

1.下载 mosquitto

        登录网址:
           http://mosquitto.org/files/binary/
        这里是window情况,选择win32/,下载mosquitto安装包。
https://i-blog.csdnimg.cn/blog_migrate/715e40375aa4db34e6bc8d5aeeddb0a9.pnghttps://i-blog.csdnimg.cn/blog_migrate/976cadb8220a53e1bf1746d93bd514df.png


2.安装 mosquitto 

         双击安装 -> 点击Next -> 点击Next -> 选择安装路径 -> 点击install -> 点击Finish。
https://i-blog.csdnimg.cn/blog_migrate/9b118878eeb3d19e2e5f2490407de77e.png
 https://i-blog.csdnimg.cn/blog_migrate/2fc8074c09866362de973ba064d5ddd8.png
https://i-blog.csdnimg.cn/blog_migrate/99fd2b36eb6e42d293dbb0ed0be82c51.png
 https://i-blog.csdnimg.cn/blog_migrate/097490994a6a913d2e47f97449345562.png


3.设置 mosquitto 

       (1)关闭匿名访问 

       在安装路径下找到设置文件 mosquitto.conf 打开,任意位置加入下面文本。https://i-blog.csdnimg.cn/blog_migrate/a89710ee3b652e2ba4fcb0618d598376.png
#设置不允许匿名登录
allow_anonymous false         (2)插入新用户名及密码

       a)新增用户:
        输入密码时界面是不会表现的,直接输入后回车就可以。保证pwfile.example的路径和上面的设置同等。下面打开CMD并进入mosquitto目录输入:
   mosquitto_passwd -cpwfile.example 用户名1https://i-blog.csdnimg.cn/blog_migrate/421f1bdeecc2ef01510f0e736235d694.png​
         b)追加用户:
        使用-c 参数会导致清空密码文件,重新插入用户,如需追加用户,则不使用 -c,如下:
   mosquitto_passwd pwfile.example 用户名2打开pwfile.example文件可以看到增长的用户:
https://i-blog.csdnimg.cn/blog_migrate/432cc493553a08f1c01159344c44b96f.png​

4.测试 mosquitto

       (1)先打开Mosquitto Broker 服务:
        https://i-blog.csdnimg.cn/blog_migrate/38ce1603dbfabe2fe5c28cfe53be7ff5.png
        (2)这里方便利用,启动三个cmd窗口服务,并进入mosquitto目录下。
        a)第一个cmd服务窗口启动mosquitto。
   mosquitto.exe -c mosquitto.conf         b)第二个cmd服务窗口订阅消息(示例:账户user,密码123456)。
   mosquitto_sub -u user1 -P 123456 -t 'user/topic' -v        c)第三个cmd服务窗口发布消息(示例:mqtt测试)。
mosquitto_pub -u user1 -P 123456 -t 'user/topic' -m 'mqtt测试'         第二个订阅窗口会收到来自第三个订阅窗口发布的消息。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: MQTT:windows情况下设置MQTT服务器(mosquitto)