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
|
2021-11-15 07:37:03 +02:00
|
|
|
the MQTT protocol versions 3.1 and 3.1.1.
|
2015-12-08 18:57:14 +02:00
|
|
|
|
2022-12-08 09:06:17 +02:00
|
|
|
## server
|
2017-05-22 08:48:55 +02:00
|
|
|
|
2022-12-08 09:06:17 +02:00
|
|
|
Sample config file: [mosquitto.conf](https://github.com/vimagick/dockerfiles/blob/master/mosquitto/data/etc/mosquitto.conf)
|
2016-11-02 19:34:54 +02:00
|
|
|
|
2017-04-22 06:19:52 +02:00
|
|
|
- `pwfile` is managed by [mosquitto_passwd][3].
|
2017-05-22 08:48:55 +02:00
|
|
|
- Two methods to support TLS:
|
|
|
|
- You can get free TLS certificates from letsencrypt, `capath` is needed.
|
|
|
|
- Self-signed TLS keys can be generated by [openssl][2], `cafile` is needed.
|
2016-11-02 19:34:54 +02:00
|
|
|
|
2017-05-22 08:48:55 +02:00
|
|
|
> It is important to use different certificate subject parameters for your self-signed CA, server and clients.
|
2016-11-02 19:34:54 +02:00
|
|
|
|
2017-05-22 08:48:55 +02:00
|
|
|
```bash
|
2022-12-08 09:06:17 +02:00
|
|
|
$ mkdir -p data/{etc,var,log}
|
2021-11-15 07:37:03 +02:00
|
|
|
$ chmod -R 777 data
|
|
|
|
$ touch data/etc/mosquitto.conf data/etc/pwfile
|
|
|
|
$ vi data/etc/mosquitto.conf
|
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
|
2024-01-24 09:57:59 +02:00
|
|
|
$ docker-compose kill -s SIGHUP
|
2022-12-08 09:06:17 +02:00
|
|
|
$ tails -f data/log/mosquitto.log
|
|
|
|
2022-12-08T06:59:00: mosquitto version 1.4.8 (build date 2016-05-16 14:17:19+0000) starting
|
|
|
|
2022-12-08T06:59:01: Config loaded from /etc/mosquitto/mosquitto.conf.
|
|
|
|
2022-12-08T06:59:02: Opening ipv4 listen socket on port 8883.
|
|
|
|
2022-12-08T06:59:03: Opening ipv6 listen socket on port 8883.
|
|
|
|
2022-12-08T06:59:04: New connection from 192.168.31.102 on port 8883.
|
|
|
|
2022-12-08T06:59:05: New client connected from 192.168.31.102 as mosqsub/38158-Kevins-Ma (c1, k60).
|
|
|
|
2022-12-08T06:59:06: New client connected from 192.168.31.102 as mosqpub/38324-Kevins-Ma (c1, k60).
|
|
|
|
2022-12-08T06:59:07: Client mosqpub/38324-Kevins-Ma disconnected.
|
2016-11-02 19:34:54 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## 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
|