Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

191.2. mosquitto: Open Source MQTT v5/v3.1.x Broker

191.2.1. 安装

    
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       
        
			

191.2.2. 配置

        
[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
        
			

191.2.3. Docker 方式安装

	        
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