MQTT使用之mosquitto配置

Mosquitto的配置文件存放在/etc/mosquitto/

有4个文件:

aclfile.example mosquitto.conf .example pwfile.example

1.文件更名

mv aclfile.example   aclfile
mv pskfile.example   pskfile
mv pwfile.example   pwfile

2.创建用户

//-c 清空  -b密码明文   aa用户名  123456密码
sudo /etc/mosquitto# mosquitto_passwd -c -b /etc/mosquitto/pwfile  aa 123456  
sudo /etc/mosquitto# mosquitto_passwd  -b /etc/mosquitto/pwfile  bb 123456  
sudo /etc/mosquitto# mosquitto_passwd  -b /etc/mosquitto/pwfile  cc 123456

3.修改用户访问权限

//i编辑 u撤回 uu还原最初

//按Esc命令模式 /搜索 Enter确定 n下一个; :wq 保存退出

//命令
sudo vim /etc/mosquitto/aclfile

user aa
topic readwrite test/#

user bb
topic read test/#

user cc
topic write test/#

4.修改配置

vim mosquitto.conf
修改项
#per_listener_settings false   =>   per_listener_settings true
#allow_zero_length_clientid true  =>  allow_zero_length_clientid true   //允许0长度的客户端id
#allow_anonymous true    =>  allow_anonymous false    //不允许匿名登录
#password_file   =>   password_file   /etc/mosquitto/pwfile
#acl_file       =>    acl_file  /etc/mosquitto/aclfile
//持久化间隔
#autosave_interval 1800   =>  autosave_interval 10
#autosave_on_changes false  =>  autosave_on_changes false  //false 10秒  true 10次
#persistence_file mosquitto.db =>  persistence_file mosquitto.db  //持久化数据保存在哪里
#persistence_location    =>   persistence_location /etc/mosquitto/  //修改保存地址  (报错)

#user mosquitto   =>  user root  //用root权限访问
//配置监听
#listener  =>  listener  1883

5.运行

sudo /etc/mosquitto# mosquitto -v -c /etc/mosquitto/mosquitto.conf

猜你喜欢

转载自blog.csdn.net/echozly/article/details/122961187