What's up good people ? Hope well.
Ok, Few days back was trying to setup MQTT cluster server and choose HAProxy to use as load balancer.
This is a short guide how I managed everything.

I have 3 server from digital ocean (vps service provider).
Assume they are :

  1. lb.example.com (
  2. node1.example.com (
  3. node2.example.com (

lb.example.com is load balancer where I setup HAProxy.
node1.example.com is first server of mqtt and
node2.example.com is second server of mqtt.

I used emqttd as MQTT broker. Download link

After emqttd setup on node1 and node2 to enable clustering enter into node1.example.com change hostname to

change in etc/emq.conf as :

node.name = emqttd@node1.example.com

Do same for node2 but here with node2.example.com

Now from node1 or node2 execute

emqttd_ctl cluster join emqttd@node2.example.com
# Assuming you are on node1

now to check cluster status execute,

emqttd_ctl cluster status

Result should be,


Now time to setup HAProxy for load balancing,
Enter into lb.example.com and

sudo apt-get install haproxy

To enable HAProxy change in /etc/default/haproxy to


change in /etc/haproxy/haproxy.cfg

log     global
mode    tcp
option  tcplog

And add

frontend mqtt
    default_backend mqtt

backend mqtt
    mode tcp
    balance roundrobin
    server node1 node1.example.com:1883 check
    server node2 node2.example.com:1883 check

frontend mqtt_dashboard
    default_backend mqtt_dashboard

backend mqtt_dashboard
    mode http
    balance roundrobin
    server node1 node1.example.com:18083 check
    server node2 node2.example.com:18083 check

And you are done.
Now browse http://lb.example.com:18083
Mqtt URL : tcp://lb.example.com:1883
you will see server are swapping.
Emqttd dashboard default
user : admin,
pass : public