How to Deploy MQTT with Mosquitto and Monitor It Using Zabbix Agent2
This guide explains the MQTT protocol, shows how to install and run a Mosquitto broker on CentOS, and demonstrates how to collect MQTT messages with a custom Zabbix Agent2 plugin for real‑time monitoring in Zabbix.
MQTT Protocol Overview
MQTT (Message Queuing Telemetry Transport) is an ISO‑standard publish/subscribe protocol designed for low‑power devices and unreliable networks. It is widely used in automotive, manufacturing, telecom, oil & gas, satellite‑linked sensors, medical devices, home automation, and mobile apps due to its small footprint and low power consumption.
Components
MQTT broker – the central hub that routes messages between clients.
MQTT client – any device that connects to the broker; publishers send messages, subscribers receive them by subscribing to topics.
Deploying an MQTT Broker (Mosquitto) on CentOS
Install and build Mosquitto from source:
mkdir data && cd data
wget http://mosquitto.org/files/source/mosquitto-1.6.8.tar.gz
tar -zxvf mosquitto-1.6.8.tar.gz
cd mosquitto-1.6.8
make && make install
ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
ldconfigEdit mosquitto.conf to set the listening address and authentication, then start the broker:
mosquitto -vTesting the Broker
mosquitto_sub -v -t sensor mosquitto_pub -t sensor -m 12Subscribers will receive the published messages.
Collecting MQTT Messages with Zabbix Agent2
Zabbix Agent2 acts as an MQTT subscriber. The agent is written in Go, allowing custom plugins. The MQTT plugin implements a watcher that pushes new data to the Zabbix server.
1. Build Zabbix Agent2 with the MQTT Plugin
yum install golang
git clone https://git.zabbix.com/scm/zbx/zabbix.git --depth 1 zabbix-agent2
cd zabbix-agent2
git submodule add https://github.com/v-zhuravlev/zbx_plugin_mqtt.git src/go/plugins/mqtt2. Import the Plugin
vi src/go/plugins/plugins.go package plugins
import (
_ "zabbix.com/plugins/log"
_ "zabbix.com/plugins/systemrun"
_ "zabbix.com/plugins/zabbix/async"
_ "zabbix.com/plugins/zabbix/stats"
_ "zabbix.com/plugins/zabbix/sync"
_ "zabbix.com/plugins/mqtt"
)3. Compile and Install Agent2
./bootstrap.sh
pushd .
cd src/go/
go mod vendor
popd
./configure --enable-agent2 --enable-static
make install4. Configure the Plugin
Add entries to zabbix_agent2.conf such as:
Plugins.MQTTSubscribe.Username = <mqtt_user>
Plugins.MQTTSubscribe.Password = <mqtt_password>
Plugins.MQTTSubscribe.ClientID = zabbix-agent2-mqtt-client
Plugins.MQTTSubscribe.Timeout = 55. Start the Agent
cd /root/zabbix_agent/src/go/bin
./zabbix_agent2 -c ../conf/zabbix_agent2.confThe plugin pushes received MQTT data to the Zabbix server.
6. Create a Zabbix Item
Use a key of the form: mqtt.subscribe[<MQTT broker URL>,<MQTT topic>] Set the item type to “active”. The data appears in the Zabbix frontend in real time.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
