
安装mosquito
更新源
sudo apt update
安装
sudo apt install mosquitto
安装Mosquitto的服务工具
sudo apt install mosquitto-clients
修改配置
打开 /etc/mosquitto/mosquitto.conf
pid_file /run/mosquitto/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
# 修改端口
listener 1883
# 开启匿名访问
allow_anonymous true
和EMQX集群
打开配置文件/etc/mosquitto/mosquitto.conf
在最下面添加
# 集群的名称
connection emqx1
# emqx的地址
address 1.2.3.4:1883
# clientid
remote_clientid mosquitto_test
# 用户名密码,有就填,没有就不写
remote_username xxx
remote_password xxx
# 桥接主题,#代表所有主题,方向可以是 out, in 或者 both
topic # both
命令
//启动
systemctl start mosquitto
//停止
systemctl stop mosquitto
//重启
systemctl restart mosquitto
//查看状态
systemctl status mosquitto