docs/ref/modules/cluster/lb.md
A load balancer distributes workloads across multiple resources. In a Wazuh server cluster, it distributes Wazuh agents among worker nodes to improve scalability, availability, and performance.
Load balancers allow agents to enroll and report to different Wazuh server nodes transparently. If a node becomes unavailable, agents reconnect to another available node.
This document covers two commonly used load balancers:
NGINX can be used as a TCP load balancer to distribute Wazuh agent traffic across cluster nodes.
Install NGINX using the packages provided by your Linux distribution.
Edit the nginx.conf file and add the following configuration:
stream {
upstream master {
server <MASTER_NODE_IP>:1515;
}
upstream cluster {
hash $remote_addr consistent;
server <MASTER_NODE_IP>:1514;
server <WORKER_NODE_IP>:1514;
server <WORKER_NODE_IP>:1514;
}
server {
listen 1515;
proxy_pass master;
}
server {
listen 1514;
proxy_pass cluster;
}
}
Replace the placeholder IP addresses with your cluster node addresses.
Reload the service to apply changes:
nginx -t
nginx -s reload
HAProxy provides high availability and load balancing for TCP-based services such as Wazuh agent connections.
Install HAProxy using system packages or Docker, depending on your environment.
Create /etc/haproxy/haproxy.cfg with the following configuration:
global
maxconn 4000
user haproxy
group haproxy
daemon
defaults
mode tcp
timeout connect 10s
timeout client 1m
timeout server 1m
frontend wazuh_register
bind :1515
default_backend wazuh_register
backend wazuh_register
balance leastconn
server master <MASTER_NODE>:1515 check
server worker1 <WORKER_NODE>:1515 check
frontend wazuh_reporting
bind :1514
default_backend wazuh_reporting
backend wazuh_reporting
balance leastconn
server master <MASTER_NODE>:1514 check
server worker1 <WORKER_NODE>:1514 check
Start the service:
service haproxy start
The HAProxy helper automatically updates HAProxy backend servers based on cluster status.
Create a Dataplane API configuration file:
dataplaneapi:
host: 0.0.0.0
port: 5555
user:
- name: <USER>
password: <PASSWORD>
insecure: true
haproxy:
config_file: /etc/haproxy/haproxy.cfg
haproxy_bin: /usr/sbin/haproxy
reload:
reload_cmd: service haproxy reload
Add the following section to wazuh-manager.conf:
<haproxy_helper>
<haproxy_disabled>no</haproxy_disabled>
<haproxy_address><HAPROXY_ADDRESS></haproxy_address>
<haproxy_user><USER></haproxy_user>
<haproxy_password><PASSWORD></haproxy_password>
</haproxy_helper>
Restart the manager:
systemctl restart wazuh-manager
Verify logs:
tail /var/wazuh-manager/logs/cluster.log