Ubuntu中安装Mosquitto集群MQTT服务

apt安装服务

使用命令

sudo apt install mosquitto

在这里插入图片描述
输入y确认等待就可以了

设置MQTT账号密码

本人是wsl环境,直接在运行访问
\wsl$
找到需要安装服务的ubuntu版本
进入\etc\mosquitto
找到mosquitto.conf
右键点击编辑
在最后加上两句话

allow_anonymous false
password_file /etc/mosquitto/pwfile

保存

cd /etc/mosquitto/
sudo touch /etc/mosquitto/pwfile
sudo mosquitto_passwd -c /etc/mosquitto/pwfile 用户名

然后输入两次密码,就设置好了

运行MQTT服务

运行命令

mosquitto -v 

在这里插入图片描述

附录:常用命令

订阅频道

mosquitto_sub -h localhost -t "频道名" -u [用户名] -P [用户密码] -i "[设备ID]"

发布消息

mosquitto_pub -h localhost -t "频道名" -u [用户名] -P [用户密码] -i "设备ID" -m "[发送的消息]"

猜你喜欢

转载自blog.csdn.net/AcStudio/article/details/106976206