mosquitto 官网: https://mosquitto.org
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
添加配置文件
在/etc/mosquitto/conf.d目录下,添加配置文件myconfig.conf 配置文件:
sudo vi /etc/mosquitto/conf.d/myconfig.conf
粘入下面这些配置
#添加监听端口(很重要,否则只能本机访问)
listener 1883
#-------------------------------------------
# 关闭匿名访问,客户端必须使用用户名
allow_anonymous false
#指定 用户名-密码 文件
password_file /etc/mosquitto/pwfile.txt
#--------------------------------------------
2.添加账户及密码 admin为账号,连续输入两次密码
sudo mosquitto_passwd -c /etc/mosquitto/pwfile.txt admin
sudo systemctl status mosquitto
3.测试环节:
客户端一:订阅主题:
mosquitto_sub -h localhost -t "lai001/#" -u admin -P 123456 -i “client1”
客户端二:发布主题:
mosquitto_pub -h localhost -t "lai001/testTopic" -u admin -P 123456 -m "Hello MQTT from mosquitto-clients"
客户端一收到信息"Hello MQTT from mosquitto-clients"就说明通信正常了。
标签:admin,sudo,apt,etc,mosquitto,conf,ubuntu,安装 From: https://www.cnblogs.com/sheizhuchenfu2/p/17415042.html