moquitto配置方法

[复制链接]
689|3
 楼主| keer_zu 发表于 2020-10-19 15:36 | 显示全部楼层 |阅读模式
  1. sudo nano /etc/mosquitto/mosquitto.conf

  2. pid_file /var/run/mosquitto.pid

  3. # 消息持久存储
  4. persistence true
  5. persistence_location /var/lib/mosquitto/

  6. # 日志文件
  7. log_dest file /var/log/mosquitto/mosquitto.log

  8. # 其他配置
  9. include_dir /etc/mosquitto/conf.d

  10. # 禁止匿名访问
  11. allow_anonymous false

  12. # 认证配置
  13. password_file /etc/mosquitto/pwfile

  14. # 权限配置
  15. acl_file /etc/mosquitto/aclfile

  16.     认证配置pwfile

  17. 创建文件

  18. sudo touch /etc/mosquitto/pwfile

  19.     开启服务开启

  20. sudo mosquitto_passwd /etc/mosquitto/pwfile bootloader #bootloader是我当前用户名

  21.     权限配置aclfile

  22. sudo nano /etc/mosquitto/aclfile

  23. # user1只能发布以test为前缀的主题,订阅以$SYS开头的主题即系统主题
  24. user user1
  25. topic write test/#
  26. topic read $SYS/#

  27. # user2只能订阅以test为前缀的主题
  28. user user2
  29. topic read test/#



 楼主| keer_zu 发表于 2020-10-19 15:42 | 显示全部楼层
启动服务端:
  1. #-c:指定特定配置文件启动
  2. #-d:后台运行
  3. mosquitto -c /etc/mosquitto/mosquitto.conf -d



 楼主| keer_zu 发表于 2020-10-19 15:44 | 显示全部楼层
测试:
发布使用mosquitto_pub命令,订阅使用mosquitto_sub命令.常用参数介绍:
参数
描述

-h
服务器主机,默认localhost

-t
指定主题

-u
用户名

-P
密码

-i
客户端id,唯一

-m
发布的消息内容
  • 订阅
  1. mosquitto_sub -h localhost -t "test/#" -u user2 -P 123456 -i "client1"

订阅系统主题
  1. # 订阅客户端存活连接数
  2. mosquitto_sub -h localhost -u user1 -P 123456 -i "client2" -t '$SYS/broker/clients/active'  #发布者 订阅 者都算存活连接
发布:
  1. mosquitto_pub -h localhost -t "test/abc" -u user1 -P 123456 -i "client3" -m "How are you?"




 楼主| keer_zu 发表于 2020-12-7 17:30 | 显示全部楼层
4.2注册应用到EdgeX

curl -X POST -d '{

    "name":"QuickStartExport",

    "addressable":{

        "name":"HiveMQBroker",

        "protocol":"tcp",

        "address":"localhost",

        "port":1883,

        "publisher":"EdgeXExportPublisher",

        "topic":"EdgeXQuickStartGuide"

    },

    "format":"JSON",

    "filter":{

        "deviceIdentifiers":["Random-Integer-Generator01"]

    },

    "enable":true,

    "destination":"MQTT_TOPIC"

}' http://localhost:48071/api/v1/registration
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:qq群:49734243 Email:zukeqiang@gmail.com

1488

主题

12949

帖子

55

粉丝
快速回复 在线客服 返回列表 返回顶部