Project

General

Profile

Inst mosquitto » History » Version 8

Michael Gunsch, 08/07/2023 07:14 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
connection <bridge-name>
39
address <host>:8883
40 4 Michael Gunsch
allow_anonymous true
41 2 Michael Gunsch
bridge_cafile /etc/ssl/certs/ISRG_Root_X1.pem
42
remote_username <username>
43
remote_password <password>
44
# topic # out 1 "" <prefix>/
45
# topic # in 1 <prefix>/ ""
46
topic # both 1
47
</pre>
48 5 Michael Gunsch
49
h2. Test
50
51
<pre>
52
mosquitto_sub -h localhost -t '#' -v
53
</pre>
54 8 Michael Gunsch
55
h2. Script zum Löschen von persistenten Daten
56
57
cleanmqtt.sh:
58
59
<pre><code class="shell">
60
#!/bin/sh
61
62
# Clean mqtt from all retained messages.
63
# Usage: ./cleanmqtt hostname
64
# 2020-11-05 MG
65
66
echo "cleaning " $1 " :: usage: cleanmqtt <host>"
67
mosquitto_sub -h $1 -t "#" -v --retained-only | while read line
68
do
69
	mosquitto_pub -h $1 -t "${line% *}" -r -n
70
done
71
</code></pre>