知乎专栏 |
dnf install -y mosquitto systemctl enable mosquitto systemctl start mosquitto
检查是否工作正常,开启两个终端窗口,分别运行下面两个命令。
[root@netkiller ~]# mosquitto_sub -h localhost -t "sensor/temperature" 23
[root@netkiller ~]# mosquitto_pub -h localhost -t sensor/temperature -m 23
[root@netkiller ~]# grep -v "^#" /etc/mosquitto/mosquitto.conf | grep -v "^$" listener 1883 0.0.0.0 allow_anonymous false password_file /etc/mosquitto/pwfile
[root@netkiller ~]# touch /etc/mosquitto/pwfile [root@netkiller ~]# mosquitto_passwd -b /etc/mosquitto/pwfile homeassistant fag9iaTaix8nohL2cheenai7nua3sohjohfah7iuz1ileSheiRahs0och9Aedai8
生成配置文件
mkdir -p /opt/mosquitto/ docker run --rm --entrypoint cat eclipse-mosquitto:latest /mosquitto/config/mosquitto.conf > /opt/mosquitto/mosquitto.conf
运行容器
docker run -d --restart always --name mosquitto --hostname mosquitto.netkiller.cn \ -p 1883:1883 \ -v /opt/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro \ -v /opt/mosquitto/data:/mosquitto/data:rw \ -e TZ=Asia/Shanghai traccar/traccar:latest
创建密码
/mosquitto # mosquitto_passwd -c -b /mosquitto/config/pwfile netkiller passw0rd