Ubuntu 使用 docker 快速架 mosquitto

Tree

$ tree mosquitto/
mosquitto/
├── config
│   ├── certs
│   │   ├── vcom_dh.pem
│   │   ├── vcom.pem
│   │   └── vcom_rootCA.pem
│   └── mosquitto.conf
├── data
└── log

執行

Terminal 1 run mosquitto daemon:

$ docker run -it  --rm  --name mqtt -p 1883:1883 -p 9001:9001 -p 8883:8883 -p 8884:8884  -v `pwd`/mosquitto:/mosquitto eclipse-mosquitto sh

$ cat mosquitto/config/mosquitto.conf
allow_anonymous true

listener 1883
protocol mqtt

listener 8883
protocol mqtt
keyfile /mosquitto/config/certs/vcom.pem
certfile /mosquitto/config/certs/vcom.pem
cafile /mosquitto/config/certs/vcom_rootCA.pem
require_certificate true

$ mosquitto -c mosquitto/config/mosquitto.conf
1672046550: mosquitto version 2.0.15 starting
1672046550: Config loaded from mosquitto/config/mosquitto.conf.
1672046550: Opening ipv4 listen socket on port 8883.
1672046550: Opening ipv6 listen socket on port 8883.
1672046550: mosquitto version 2.0.15 running
1672046550: New connection from 127.0.0.1:56310 on port 8883.
1672046550: New client connected from 127.0.0.1:56310 as auto-3ADD4D06-E652-44B5-5D2A-52CE709FE8CA (p2, c1, k60).

Terminal 2 test subscript:


$ docker exec -it mqtt sh

$ mosquitto_sub -p 8883 -h 127.0.0.1 -t '#' -v --key /mosquitto/config/certs/vcom.pem --cert /mosquitto/config/certs/vcom.pem --cafile /mosquitto/config/certs/vcom_rootCA.pem --insecure

yuyuyuyu 1234wwwwwwwwwwwwww56

Terminal 3 test publish:

$ docker exec -it mqtt sh

$ mosquitto_pub -p 8883 -h 127.0.0.1 -t yuyuyuyu  --key /mosquitto/config/certs/vcom.pem --cert /mosquitto/config/certs/vcom.pem --cafile /mosquitto/config/certs/vcom_rootCA.pem --insecure
-m "1234wwwwwwwwwwwwww56"

  目錄