mosquitto相关指令,用户配置,权限配置,配置文件介绍

1.配置文件设置

linux系统下配置文件一般存放在/etc/mosquitto/目录下。
一般含有一下四个配置文件:

配置文件
文件名描述
mosquitto.conf总配置文件
pwfile.example存放了用户的用户名与密码信息
aclfile.example权限配置文件
pskfile.example预共享密钥文件

mosquitto.conf 一般配置下列三个

  1. allow_anonymous 不允许匿名配置
    例如: 修改前:#allow_anonymous
        修改后:allow_anonymous false

  2. password_file 密码文件位置配置
    例如:修改前:#password_file
       修改后:password_file /etc/mosquitto/pwfile.example

  3. acl_file 访问控制列表配置
    例如:修改前:#acl_file
       修改后:acl_file /etc/mosquitto/aclfile.example

具体配置结果可参照下表

参数组合表
IDallow_anonymouspassword_fileacl_fileresult
1true(默认)允许匿名方式登录
2falsepassword_file pwfile.example开启用户验证机制
3falsepassword_file pwfile.exampleacl_file aclfile.example开启用户验证机制,但访问控制不起作用
4truepassword_file pwfile.exampleacl_file aclfile.example用户名及密码不为空,将自动进行用户验证且受到访问控制的限制;用户名和密码为空,将不进行用户验证且受到访问控制的限制
5false无法启动服务

2.用户管理

创建第一个用户(-c参数代表会清除文件中原有的用户信息)
mosquitto_passwd -c pwfile.example testuser1
增加用户
mosquitto_passwd pwfile.example testuser2
会修改 pwfile.example 配置文件

3.用户权限管理

假设我们想要:
testuser1设置为订阅权限,并且只能访问的主题为"root/topic/#"
testuser2设置为发布权限,并且只能访问的主题为"root/topic/#"

修改aclfile.example

user testuser1
topic read root/topic/#
user testuser2
topic write root/topic#

4.根据配置文件启动mosquitto

亲测不加配置文件参数-c /etc/mosquitto/mosquitto.conf会导致配置不生效,加上参数后正常

mosquitto -c /etc/mosquitto/mosquitto.conf

如果想要关闭后台的mosquitto服务请查看
https://blog.csdn.net/qq_44839815/article/details/115716909

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值