mosquitto配置
mosquitto.conf#
mosquitto.conf是mosquitto的配置文件,
# Config file for mosquitto
# =================================================================
# General configuration
# =================================================================
per_listener_settings false
allow_zero_length_clientid false
check_retain_source false
max_inflight_messages 20
max_keepalive 60
persistent_client_expiration 1w
retain_available true
sys_interval 3600
listener 1883 0.0.0.0
# bind_address 127.0.0.1
# =================================================================
# Persistence
# =================================================================
persistence false
# =================================================================
# Security
# =================================================================
allow_anonymous false
password_file /etc/mosquitto/pwfile.example
acl_file /etc/mosquitto/aclfile.example
# =================================================================
# Debug configuration
# =================================================================
# log_dest file /var/log/mosquitto.log
# log_dest none
# log_type error
# log_type warning
# log_type notice
# log_type information
# connection_messages true
# log_timestamp true
# log_timestamp_format %Y-%m-%dT%H:%M:%S
# max_keepalive 5
# sys_interval 10
pwfile.example#
设置用户名和密码,若客户端登录时,提供的用户名和密码不匹配,将无法连接mosquitto broker。
安装mosquitto时,附带安装了mosquitto_passwd,用户创建用户的可执行文件。
创建两个用户,分别是:admin和mosquitto
创建第一个用户admin:sudo mosquitto_passwd -c /etc/mosquitto/pwfile.example admin
创建第二个用户mosquitto:sudo mosquitto_passwd /etc/mosquitto/pwfile.example mosquitto
(注意:创建第二个用户时,不需要参数-c。若添加了参数-c,那么第一个用户会被第二个用户覆盖)
aclfile.example#
可以限制指定用户对主题的发布或订阅权限。
例如:用户admin可以对 device/1001
发布,对 room/#
订阅。用户mosquitto可以对 #
发布和订阅。
user admin
topic write device/1001
topic read room/#
user mosquitto
topic readwrite #
作者:caojun97
出处:https://www.cnblogs.com/caojun97/p/18218513
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)