2015-12-08 18:57:14 +02:00
|
|
|
mosquitto
|
|
|
|
=========
|
|
|
|
|
|
|
|
![](https://badge.imagelayers.io/vimagick/mosquitto:latest.svg)
|
|
|
|
|
|
|
|
[Mosquitto][1] is an open source (BSD licensed) message broker that implements
|
2016-11-02 19:34:54 +02:00
|
|
|
the MQ Telemetry Transport protocol versions 3.1 and 3.1.1.
|
2015-12-08 18:57:14 +02:00
|
|
|
|
2015-12-08 19:02:10 +02:00
|
|
|
## docker-compose.yml
|
|
|
|
|
2016-11-02 19:34:54 +02:00
|
|
|
```yaml
|
2015-12-08 19:02:10 +02:00
|
|
|
mosquitto:
|
|
|
|
image: vimagick/mosquitto
|
|
|
|
ports:
|
|
|
|
- "1883:1883"
|
2017-04-22 10:51:33 +02:00
|
|
|
- "8080:8080"
|
2016-11-02 19:34:54 +02:00
|
|
|
- "8883:8883"
|
|
|
|
volumes:
|
2017-04-22 06:19:52 +02:00
|
|
|
- ./data/mosquitto.conf:/etc/mosquitto/mosquitto.conf
|
|
|
|
- ./data/pwfile:/etc/mosquitto/pwfile
|
2016-11-02 19:34:54 +02:00
|
|
|
- ./data:/var/lib/mosquitto
|
2015-12-08 19:02:10 +02:00
|
|
|
restart: always
|
|
|
|
```
|
|
|
|
|
2016-11-02 19:34:54 +02:00
|
|
|
## mosquitto.conf
|
|
|
|
|
|
|
|
```
|
|
|
|
port 8883
|
|
|
|
log_dest stdout
|
2017-04-22 06:19:52 +02:00
|
|
|
password_file /etc/mosquitto/pwfile
|
2016-11-02 19:34:54 +02:00
|
|
|
persistence true
|
|
|
|
persistence_location /var/lib/mosquitto
|
|
|
|
cafile /var/lib/mosquitto/ca.crt
|
|
|
|
certfile /var/lib/mosquitto/server.crt
|
|
|
|
keyfile /var/lib/mosquitto/server.key
|
|
|
|
require_certificate false
|
|
|
|
```
|
|
|
|
|
2017-04-22 06:19:52 +02:00
|
|
|
- `pwfile` is managed by [mosquitto_passwd][3].
|
2016-11-02 19:34:54 +02:00
|
|
|
- TLS keys are generated by [openssl][2].
|
|
|
|
|
|
|
|
> It is important to use different certificate subject parameters for your CA,
|
|
|
|
> server and clients.
|
|
|
|
|
|
|
|
## server
|
|
|
|
|
|
|
|
```
|
2017-04-22 06:19:52 +02:00
|
|
|
$ mkdir -p data
|
|
|
|
$ touch data/mosquitto.conf data/pwfile
|
2016-11-02 19:34:54 +02:00
|
|
|
$ docker-compose up -d
|
2017-04-22 06:19:52 +02:00
|
|
|
$ docker-compose exec mosquitto sh
|
|
|
|
>>> cd /etc/mosquitto
|
2017-05-06 06:59:40 +02:00
|
|
|
>>> mosquitto_passwd -b pwfile username password
|
|
|
|
>>> cat pwfile
|
|
|
|
username:$6$IuF7JUzS1k/QoF3y$YpiClom7/==
|
2017-04-22 06:19:52 +02:00
|
|
|
>>> exit
|
|
|
|
$ docker-compose restart
|
2016-11-02 19:34:54 +02:00
|
|
|
$ docker-compose logs -f
|
|
|
|
Attaching to mosquitto_mosquitto_1
|
|
|
|
mosquitto_1 | 1478107412: mosquitto version 1.4.8 (build date 2016-05-16 14:17:19+0000) starting
|
|
|
|
mosquitto_1 | 1478107412: Config loaded from /etc/mosquitto/mosquitto.conf.
|
|
|
|
mosquitto_1 | 1478107412: Opening ipv4 listen socket on port 8883.
|
|
|
|
mosquitto_1 | 1478107412: Opening ipv6 listen socket on port 8883.
|
|
|
|
mosquitto_1 | 1478107437: New connection from 192.168.31.102 on port 8883.
|
|
|
|
mosquitto_1 | 1478107437: New client connected from 192.168.31.102 as mosqsub/38158-Kevins-Ma (c1, k60).
|
|
|
|
mosquitto_1 | 1478107585: New client connected from 192.168.31.102 as mosqpub/38324-Kevins-Ma (c1, k60).
|
|
|
|
mosquitto_1 | 1478107585: Client mosqpub/38324-Kevins-Ma disconnected.
|
|
|
|
```
|
|
|
|
|
|
|
|
## client
|
|
|
|
|
|
|
|
```bash
|
2017-04-22 06:19:52 +02:00
|
|
|
$ mosquitto_sub -d -h 192.168.31.231 -p 8883 --cafile ca.crt --insecure -u username -P password -t hello
|
2016-11-02 19:34:54 +02:00
|
|
|
Client mosqsub/38158-Kevins-Ma sending CONNECT
|
|
|
|
Client mosqsub/38158-Kevins-Ma received CONNACK
|
|
|
|
Client mosqsub/38158-Kevins-Ma sending SUBSCRIBE (Mid: 1, Topic: hello, QoS: 0)
|
|
|
|
Client mosqsub/38158-Kevins-Ma received SUBACK
|
|
|
|
Subscribed (mid: 1): 0
|
|
|
|
Client mosqsub/38158-Kevins-Ma sending PINGREQ
|
|
|
|
Client mosqsub/38158-Kevins-Ma received PINGRESP
|
|
|
|
received PUBLISH (d0, q0, r0, m0, 'hello', ... (5 bytes))
|
|
|
|
world
|
|
|
|
Client mosqsub/38158-Kevins-Ma sending PINGREQ
|
|
|
|
Client mosqsub/38158-Kevins-Ma received PINGRESP
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
2017-04-22 06:19:52 +02:00
|
|
|
$ mosquitto_pub -d -h 192.168.31.231 -p 8883 --cafile ca.crt --insecure -u username -P password -t hello -m world
|
2016-11-02 19:34:54 +02:00
|
|
|
Client mosqpub/38324-Kevins-Ma sending CONNECT
|
|
|
|
Client mosqpub/38324-Kevins-Ma received CONNACK
|
|
|
|
Client mosqpub/38324-Kevins-Ma sending PUBLISH (d0, q0, r0, m1, 'hello', ... (5 bytes))
|
|
|
|
Client mosqpub/38324-Kevins-Ma sending DISCONNECT
|
|
|
|
```
|
|
|
|
|
2015-12-08 18:57:14 +02:00
|
|
|
[1]: http://mosquitto.org/
|
2016-11-02 19:34:54 +02:00
|
|
|
[2]: https://mosquitto.org/man/mosquitto-tls-7.html
|
|
|
|
[3]: https://mosquitto.org/man/mosquitto_passwd-1.html
|