Inst mosquitto » History » Revision 8
Revision 7 (Michael Gunsch, 08/07/2023 05:40 PM) → Revision 8/9 (Michael Gunsch, 08/07/2023 07:14 PM)
h1. Installation MQTT-Server (Broker) Mosquitto unter Debian
h2. Pakete installieren
<pre><code class="shell">
sudo apt install mosquitto mosquitto-clients
</code></pre>
h2. Konfiguration
/etc/mosquitto/mosquitto.conf
<pre>
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
persistent_client_expiration 30d
log_timestamp_format %Y-%m-%dT%H:%M:%S
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
</pre>
Im Verzeichnis /etc/mosquitto/conf.d werden die Konfigurationsdateien hinterlegt. Die Angaben in spitzen Klammern, wie <host> sind anzupassen, die Spitzen Klammern sind wegzulassen. Beispiel für eine Verbindung (Bridge) zu einem anderen Mosquitto-Broker:
/etc/mosquitto/conf.d/andino.conf
<pre>
listener 1883
connection <bridge-name>
address <host>:8883
allow_anonymous true
bridge_cafile /etc/ssl/certs/ISRG_Root_X1.pem
remote_username <username>
remote_password <password>
# topic # out 1 "" <prefix>/
# topic # in 1 <prefix>/ ""
topic # both 1
</pre>
h2. Test
<pre>
mosquitto_sub -h localhost -t '#' -v
</pre>
h2. Script zum Löschen von persistenten Daten
cleanmqtt.sh:
<pre><code class="shell">
#!/bin/sh
# Clean mqtt from all retained messages.
# Usage: ./cleanmqtt hostname
# 2020-11-05 MG
echo "cleaning " $1 " :: usage: cleanmqtt <host>"
mosquitto_sub -h $1 -t "#" -v --retained-only | while read line
do
mosquitto_pub -h $1 -t "${line% *}" -r -n
done
</code></pre>