Project

General

Profile

Inst mosquitto » History » Version 9

Michael Gunsch, 09/14/2023 12:50 PM

1 1 Michael Gunsch
h1. Installation MQTT-Server (Broker) Mosquitto unter Debian
2
3
h2. Pakete installieren
4
5
<pre><code class="shell">
6
sudo apt install mosquitto mosquitto-clients
7
</code></pre>
8
9
h2. Konfiguration
10
11
/etc/mosquitto/mosquitto.conf 
12
13
<pre>
14
# Place your local configuration in /etc/mosquitto/conf.d/
15
#
16
# A full description of the configuration file is at
17
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
18
19
pid_file /var/run/mosquitto.pid
20
21
persistence true
22
persistence_location /var/lib/mosquitto/
23
persistent_client_expiration 30d
24
25 7 Michael Gunsch
log_timestamp_format %Y-%m-%dT%H:%M:%S
26 1 Michael Gunsch
log_dest file /var/log/mosquitto/mosquitto.log
27
28
include_dir /etc/mosquitto/conf.d
29
</pre>
30 2 Michael Gunsch
31 6 Michael Gunsch
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:
32 2 Michael Gunsch
33
/etc/mosquitto/conf.d/andino.conf
34
35
<pre>
36
listener 1883
37
38 9 Michael Gunsch
allow_anonymous true
39 2 Michael Gunsch
connection <bridge-name>
40 4 Michael Gunsch
address <host>:8883
41 2 Michael Gunsch
bridge_cafile /etc/ssl/certs/ISRG_Root_X1.pem
42
remote_username <username>
43 1 Michael Gunsch
remote_password <password>
44 9 Michael Gunsch
try_private true
45
cleansession true
46
# topic abc/def/# out 1 "" <prefix>/
47 2 Michael Gunsch
# topic # in 1 <prefix>/ ""
48
topic # both 1
49
</pre>
50 5 Michael Gunsch
51
h2. Test
52
53
<pre>
54
mosquitto_sub -h localhost -t '#' -v
55
</pre>
56 8 Michael Gunsch
57
h2. Script zum Löschen von persistenten Daten
58
59
cleanmqtt.sh:
60
61
<pre><code class="shell">
62
#!/bin/sh
63
64
# Clean mqtt from all retained messages.
65
# Usage: ./cleanmqtt hostname
66
# 2020-11-05 MG
67
68
echo "cleaning " $1 " :: usage: cleanmqtt <host>"
69
mosquitto_sub -h $1 -t "#" -v --retained-only | while read line
70
do
71
	mosquitto_pub -h $1 -t "${line% *}" -r -n
72
done
73
</code></pre>