Mosquitto MQTT

Install

sudo apt install mosquitto mosquitto-clients mosquitto-dev

Disable

Stop and disable mosquitto server for now. Later start it using `runit'

/etc/init.d/mosquitto stop
update-rc.d mosquitto disable
systemctl disable mosquitto
systemctl mask mosquitto

Setup

Private LAN

Create and edit local config

vi /etc/mosquitto/conf.d/local.conf

Add the following

listener 1883
allow_anonymous true
Public WAN

Create password file and add a user

touch /etc/mosquitto/pwfile
mosquitto_passwd -b /etc/mosquitto/pwfile username password

Create and edit local config

vi /etc/mosquitto/conf.d/local.conf

Add the following

listener 8883
allow_anonymous false
password_file /etc/mosquitto/pwfile

certfile /etc/mosquitto/certs/cert.pem
cafile   /etc/mosquitto/certs/fullchain.pem
keyfile  /etc/mosquitto/certs/key.pem

Runit

#! /bin/bash
sleep 1

#LOG
exec 2>&1
ulimit -l unlimited
ulimit -i unlimited
ulimit -q unlimited
ulimit -n 8192
ulimit -aH

#RUN
mkdir -p /var/lib/mosquitto
chown -R mosquitto:mosquitto /var/lib/mosquitto
mkdir -p /var/log/mosquitto
chown -R mosquitto:mosquitto /var/log/mosquitto
mkdir -p /run/mosquitto
chown -R mosquitto:mosquitto /run/mosquitto
exec /usr/sbin/mosquitto -c 

Test

Private LAN
mosquitto_sub -h 192.168.0.13 -t '#'
Public WAN
mosquitto_sub -v -h hostname.example.com -p 8883 -u username -P password -t '#'

The hostname must match the name in the TLS certificate.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies