Mosquitto - mata-elang-stable/MataElang-Platform GitHub Wiki

Back to HOME

mosquitto

Example Environment

Item Value
MQTT user / password (user and password will be set below)

Prerequisite

✅ Ubuntu 20.04 LTS installed and updated with the following command.

sudo apt update && sudo apt -y upgrade

Time Zone and NTP already set.

✅ Docker 20.10 or later installed with the following command.

sudo apt -y install docker.io

✅ Docker Compose 2.13 or later installed with the following command.

sudo curl -L "https://github.com/docker/compose/releases/download/v2.13.0/docker-compose-$(uname -s)-$(uname -m)"\
 -o /usr/bin/docker-compose && sudo chmod +x /usr/bin/docker-compose

Setup Mosquitto

1. Configure Mosquitto

▶️ Clone Mata-Elang-Stable/mosquitto-asset from GitHub to your server.

git clone https://github.com/mata-elang-stable/mosquitto-asset.git ~/mosquitto

▶️ Prepare mosquitto.conf.

mv ~/mosquitto/mosquitto.conf.example ~/mosquitto/mosquitto.conf
Click here to edit the configuration.

▶️ Configure mosquitto.conf.

nano ~/mosquitto/mosquitto.conf

The contents of the configuration file are as follows:

listener 1883
allow_anonymous false
persistence true
persistence_location /mosquitto/data/
autosave_interval 60
queue_qos0_messages true
max_queued_messages 100000
max_inflight_messages 10000

connection_messages true
log_dest stdout

persistent_client_expiration 1h

password_file /mosquitto/config/password_file

▶️ Create a new password file.

🔑 Set <YOUR_USERNAME> and <YOUR_PASSWORD> for MQTT authentication.

cd ~/mosquitto &&\
sudo docker run --rm -e USERNAME=<YOUR_USERNAME> -e PASSWORD=<YOUR_PASSWORD>\
 --entrypoint /bin/sh eclipse-mosquitto:2.0.15\
 -c '/usr/bin/mosquitto_passwd -c -b password_file $USERNAME $PASSWORD && cat password_file' |\
tee mosquitto_passwd &&\
cd ~

2. Start Mosquitto

▶️ Start Mosquitto service.

sudo docker-compose -f ~/mosquitto/docker-compose.yaml up -d

✅ Confirm the container is running.

sudo docker-compose -f ~/mosquitto/docker-compose.yaml ps -a
Result

NAME                    COMMAND                  SERVICE             STATUS              PORTS
mosquitto-mosquitto-1   "/docker-entrypoint.…"   mosquitto           running             0.0.0.0:1883->1883/tcp, :::1883->1883/tcp

Useful Commands

Click to show commands

Service Commands

✅ Show service status

sudo docker-compose -f ~/mosquitto/docker-compose.yaml ps -a
Result

NAME                    COMMAND                  SERVICE             STATUS              PORTS
mosquitto-mosquitto-1   "/docker-entrypoint.…"   mosquitto           running             0.0.0.0:1883->1883/tcp, :::1883->1883/tcp

✅ Start services

sudo docker-compose -f ~/mosquitto/docker-compose.yaml up -d

✅ Stop services (and remove containers)

sudo docker-compose -f ~/mosquitto/docker-compose.yaml down

✅ Stop services (and keep containers)

sudo docker-compose -f ~/mosquitto/docker-compose.yaml stop

✅ Restart services

sudo docker-compose -f ~/mosquitto/docker-compose.yaml restart

Maintenance Commands

✅ Show MQTT messages on the Mata Elang topic

sudo docker-compose -f ~/mosquitto/docker-compose.yaml exec mosquitto mosquitto_sub\
 -u <YOUR_USERNAME> -P <YOUR_PASSWORD> -t mataelang/sensor/v3/+ -v

✅ Show the total number of messages received

sudo docker-compose -f ~/mosquitto/docker-compose.yaml exec mosquitto mosquitto_sub\
 -u <YOUR_USERNAME> -P <YOUR_PASSWORD> -t \$SYS/broker/messages/received

Configuration Commands

✅ Show the loaded configurations

sudo docker-compose -f ~/mosquitto/docker-compose.yaml exec mosquitto cat /mosquitto/config/mosquitto.conf

Log Commands

✅ Show mosquitto log

sudo docker-compose -f ~/mosquitto/docker-compose.yaml logs mosquitto

Version Commands

✅ Show Mosquitto version

sudo docker-compose -f ~/mosquitto/docker-compose.yaml exec mosquitto mosquitto -h

✅ Show Docker version

sudo docker version

✅ Show Docker Compose version

docker-compose version

✅ Show OS version

cat /etc/os-release

Change Username and Password

Warning
Remember to change the username and password in snort-parser and mqtt-source and restart them!

🔑 Set <YOUR_USERNAME> and <YOUR_PASSWORD> for MQTT authentication.

cd ~/mosquitto &&\
sudo docker run --rm -e USERNAME=<YOUR_USERNAME> -e PASSWORD=<YOUR_PASSWORD>\
 --entrypoint /bin/sh eclipse-mosquitto:2.0.15\
 -c '/usr/bin/mosquitto_passwd -c -b password_file $USERNAME $PASSWORD && cat password_file' |\
tee mosquitto_passwd

Restart mosquitto service with the following command

sudo docker compose up -d

Next Step >>

⚠️ **GitHub.com Fallback** ⚠️