mosquitto的acl規則及用戶配置信息真讓人頭疼啊.折騰了半天才搞明白,隨手記下來,省的下次又忘了.
首先mosquitto.conf中設置acl配置文件及用戶配置文件:
password_file pwfile.example
acl_file aclfile.example
pwfile.example為用戶列表
aclfile.example為訪問規則列表
在pwfile.example中需要以usernme/password格式添加相關用戶
#發布信息用戶
pub/pub
#接收信息用戶
sub/sub
然后在aclfile.example文件中配置用戶可訪問的topic信息
#用戶信息
user pub
#用戶可訪問的topic,這里為可讀可寫
topic mytopic/news
#訂閱用戶可訪問權限
user sub
#這里為只讀
topic read mytopic/news