VerneMQ – Clustering MQTT for high availability and scalability
Introduction to VerneMQ
VerneMQ is a high-performance, scalable, and distributed MQTT broker tailored for the Internet of Things (IoT) and M2M (Machine-to-Machine) communication. It is designed to handle large-scale message delivery, ensuring high availability and fault tolerance. VerneMQ is an open-source project written in Erlang, which makes it inherently capable of handling concurrent connections efficiently.
Key Features of VerneMQ
- Scalability: Built to handle millions of concurrent connections by distributing the load across multiple nodes.
- High Availability: Supports clustering to ensure zero downtime and automatic failover.
- Security: Offers TLS/SSL encryption, client authentication, and access control mechanisms.
- Plugin Support: Allows custom functionality with plugins in languages like Lua, Python, and Elixir.
- MQTT Compliance: Supports MQTT v3.1.1 and MQTT v5 standards.
- Persistence: Ensures data retention to manage disconnections and message storage effectively.
- WebSocket Support: Allows real-time bidirectional communication with browser clients.
Installation Guide
Installing VerneMQ on Ubuntu
- Update System Packages
sudo apt update && sudo apt upgrade -y
- Install Dependencies
sudo apt install -y software-properties-common curl
- Add VerneMQ Repository
echo "deb https://packages.erlang-solutions.com/debian/ focal contrib" | sudo tee /etc/apt/sources.list.d/erlang-solutions.list
curl https://packages.erlang-solutions.com/debian/erlang_solutions.asc | sudo apt-key add -
sudo apt update
- Install VerneMQ
sudo apt install -y vernemq
- Start and Enable VerneMQ
sudo systemctl start vernemq
sudo systemctl enable vernemq
Installing VerneMQ on CentOS/RHEL
- Add Repository and Install VerneMQ
sudo yum install epel-release -y
sudo yum install vernemq -y
- Start and Enable VerneMQ
sudo systemctl start vernemq
sudo systemctl enable vernemq
Installing VerneMQ using Docker
- Pull VerneMQ Docker Image
docker pull vernemq/vernemq
- Run VerneMQ Container
docker run -d --name vernemq -p 1883:1883 -p 8080:8080 vernemq/vernemq
- Configuration in Docker Environment For custom configurations, use environment variables:
docker run -d --name vernemq \
-e "DOCKER_VERNEMQ_ACCEPT_EULA=yes" \
-e "DOCKER_VERNEMQ_USER_myuser=mypassword" \
-p 1883:1883 \
vernemq/vernemq
Installing VerneMQ on Debian
- Add Repository and Install VerneMQ
echo "deb https://packages.erlang-solutions.com/debian/ buster contrib" | sudo tee /etc/apt/sources.list.d/erlang-solutions.list
curl https://packages.erlang-solutions.com/debian/erlang_solutions.asc | sudo apt-key add -
sudo apt update
sudo apt install -y vernemq
- Start VerneMQ
sudo systemctl start vernemq
sudo systemctl enable vernemq
Configuration Guide
VerneMQ’s primary configuration file is located at:
/etc/vernemq/vernemq.conf
Basic Configuration
- Allow External Connections:
listener.tcp.default = 0.0.0.0:1883
- Enable WebSockets:
listener.ws.default = 0.0.0.0:8080
- Create Users with Passwords:
vmq-passwd /etc/vernemq/passwd <username>
Add the following line to the config file:
allow_anonymous = off
password_file = /etc/vernemq/passwd
- Enable SSL for Secure Communication:
listener.ssl.default = 0.0.0.0:8883
ssl.cafile = /etc/vernemq/ssl/ca.crt
ssl.certfile = /etc/vernemq/ssl/server.crt
ssl.keyfile = /etc/vernemq/ssl/server.key
- Restart VerneMQ Service:
sudo systemctl restart vernemq
Clustering with VerneMQ
VerneMQ supports clustering to achieve fault tolerance and improved performance.
Steps to Create a Cluster
- On Node 1:
vmq-admin cluster join discovery-node=<IP_OF_NODE_1>
- On Node 2:
vmq-admin cluster join discovery-node=<IP_OF_NODE_2>
- Verify Cluster Status:
vmq-admin cluster show
VerneMQ Commands
Command | Description |
---|---|
vmq-admin status |
Show VerneMQ status |
vmq-admin cluster show |
Display cluster status |
vmq-admin session show |
List active sessions |
vmq-admin listener show |
Show active listeners |
Testing VerneMQ
Subscribe to a Topic:
mosquitto_sub -h localhost -t "test/topic"
Publish a Message:
mosquitto_pub -h localhost -t "test/topic" -m "Hello VerneMQ!"
Use Cases of VerneMQ
- IoT Applications: Efficiently handles thousands of sensors, devices, and clients.
- Smart Homes: Supports secure communication between home automation devices.
- Industrial Automation: Enables real-time data exchange in factories and plants.
- Healthcare Systems: Securely handles medical devices’ data streams.
Conclusion
VerneMQ is an excellent choice for building scalable and robust MQTT systems. Its strong clustering capabilities, security features, and efficient message handling make it ideal for various IoT and M2M solutions. With proper setup and configuration, VerneMQ can power secure and large-scale MQTT networks seamlessly.
Read This : How To Install VerneMQ on UbunTu, RHEL, Docker, Debian and CentOS
Pingback: VerneMQ – Clustering MQTT for high availability and scalability — IoTbyHVM – Explore TechBytes – hashstacks
Pingback: How To Install VerneMQ on UbunTu, RHEL, Docker, Debian and CentOS
Pingback: 6LoWPAN | ZigBee | 6LoWPAN Vs ZigBee - Explainer
Pingback: WiFi LoRA 32 (V2) ESP32 | Overview | Introduction
Pingback: Websockets with VerneMQ - IoTbyHVM - Bits & Bytes of IoT
Pingback: Connecting to VerneMQ Tutorial - IoTbyHVM - Bits & Bytes of IoT
Pingback: Vernemq Notes - Phanix's Blog