Cluster Load Balancing
Less than 1 minute
Cluster Load Balancing
This page describes how to use HAProxy to expose MQTT and MQTT WebSocket traffic for FMQ cluster nodes. Replace the sample internal IP addresses with your real node addresses before deployment.
HAProxy Configuration
Prepare haproxy.cfg. The reference file is located under the deployment package path a-Deployment/load-balance/haproxy/haproxy.cfg.
global
log 127.0.0.1 local3 info
daemon
maxconn 100000
defaults
log global
mode tcp
option tcplog
timeout connect 10000
timeout client 240s
timeout server 240s
maxconn 50000
backend mqtt_backend
mode tcp
stick-table type string len 32 size 1000k expire 30m
stick on req.payload(0,0),mqtt_field_value(connect,client_identifier)
server fastbeeA 10.x.x.x:1884 check
server fastbeeB 10.x.x.x:1884 check
frontend mqtt_servers
bind *:1883
mode tcp
tcp-request inspect-delay 10s
tcp-request content reject unless { req.payload(0,0),mqtt_is_valid }
default_backend mqtt_backend
backend mqtt_ws_backend
mode tcp
balance roundrobin
server fastbeeA 10.x.x.x:8084 check
server fastbeeB 10.x.x.x:8084 check
frontend mqtt_ws_frontend
bind *:8083
mode tcp
default_backend mqtt_ws_backendUpdate server fastbeeA and server fastbeeB with the internal IPs of your FMQ nodes.
Docker Compose Installation
Copy haproxy.cfg to /opt/haproxy, then use the reference docker-compose.yml:
version: '3'
services:
haproxy:
image: haproxy:latest
ports:
- "8083:8083"
- "1883:1883"
volumes:
- /opt/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
restart: alwaysStart the service:
docker compose up -dPackage Manager Installation
CentOS:
sudo yum update -y
sudo yum install haproxy -y
sudo systemctl start haproxy
sudo systemctl enable haproxy
sudo systemctl status haproxyUbuntu:
sudo apt update
sudo apt install haproxy -y
sudo systemctl start haproxy
sudo systemctl enable haproxy
sudo systemctl status haproxyAfter installation, modify /etc/haproxy/haproxy.cfg according to the target nodes and required load-balancing strategy.
