对接iot搭建使用docker来mqtt
# 创建文件夹
mqtt
在mqtt下面再继续创建三个文件夹
config
data
log
# 在config文件夹下面创建一个文件
mosquitto.conf
文件内容为;
persistence true
persistence_location /mosquitto/data
log_dest file /mosquitto/log/mosquitto.log
log_type all
log_timestamp true
# MQTT 默认端口
listener 1883
allow_anonymous false
# WebSocket 支持(可选)
listener 9001
protocol websockets
# 密码文件
password_file /mosquitto/config/pwfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 开始创建容器
docker run -d --name mqtt-broker --restart always -p 1883:1883 -p 9001:9001 -v F:/mqtt/config:/mosquitto/config -v F:/mqtt/data:/mosquitto/data -v F:/mqtt/log:/mosquitto/log eclipse-mosquitto
# 创建 MQTT 用户和密码:
# 进入容器
docker exec -it mqtt-broker sh
# 创建密码文件
mosquitto_passwd -c /mosquitto/config/pwfile iot_user
# 按提示输入密码(比如:iot123456 Dream&Big5)
# 退出容器
exit
# 重启容器
docker restart mqtt-broker
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
编辑 (opens new window)
上次更新: 2024/12/18, 17:45:13
- 01
- 免费的在线logo设计,uugai找了我好就12-24
- 02
- Untitled12-24