ExplainerInternet of ThingsIoT PlatformsIoT Software&ToolsTutorials/DIY

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

  1. Update System Packages
sudo apt update && sudo apt upgrade -y
  1. Install Dependencies
sudo apt install -y software-properties-common curl
  1. 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
  1. Install VerneMQ
sudo apt install -y vernemq
  1. Start and Enable VerneMQ
sudo systemctl start vernemq
sudo systemctl enable vernemq

Installing VerneMQ on CentOS/RHEL

  1. Add Repository and Install VerneMQ
sudo yum install epel-release -y
sudo yum install vernemq -y
  1. Start and Enable VerneMQ
sudo systemctl start vernemq
sudo systemctl enable vernemq

Installing VerneMQ using Docker

  1. Pull VerneMQ Docker Image
docker pull vernemq/vernemq
  1. Run VerneMQ Container
docker run -d --name vernemq -p 1883:1883 -p 8080:8080 vernemq/vernemq
  1. 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

  1. 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
  1. 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

  1. Allow External Connections:
listener.tcp.default = 0.0.0.0:1883
  1. Enable WebSockets:
listener.ws.default = 0.0.0.0:8080
  1. 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
  1. 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
  1. 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

  1. On Node 1:
vmq-admin cluster join discovery-node=<IP_OF_NODE_1>
  1. On Node 2:
vmq-admin cluster join discovery-node=<IP_OF_NODE_2>
  1. 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

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

7 thoughts on “VerneMQ – Clustering MQTT for high availability and scalability

Leave a Reply

Your email address will not be published. Required fields are marked *