﻿# Configure HAProxy for Redis Sentinel

> [HTML Version](haproxy-redis.html)

The architecture of a high-availability BRIX cluster involves interaction between the BRIX application microservices and Redis Sentinel. To ensure reliable load balancing within the system, configure HAProxy for Redis Sentinel. This setup allows traffic to be redirected to the primary Redis server in case of a technical failure, ensuring continuous system operation

## Example HAProxy configuration for Redis Sentinel

ВThis article provides a configuration for identifying the primary Redis server and redirecting traffic to it. HAProxy will automatically check the \[OBJECT\] port on Redis servers and determine the current server with the \[OBJECT\] role.

Steps to create HAProxy configuration for Redis Sentinel:

1. Open the \[OBJECT\] configuration file for editing using the command:

````
sudo nano /etc/haproxy/haproxy.cfg

2. ````
Make changes to the \[OBJECT\] configuration file:

Configuration example

````
\### Redis ###  
frontend redis\_master  
   bind haproxy-server.your\_domain:6379  
   mode tcp  
   option tcplog  
   option clitcpka  
   timeout client 24h  
   default\_backend redis\_master  
  
backend redis\_master  
   balance first  
   mode tcp  
   timeout queue 2s  
   timeout connect 2s  
   timeout check 1s  
   option srvtcpka  
   timeout server 24h  
   option tcp-check  
   tcp-check connect  
   tcp-check send AUTH\\ <PASSWORD>\\r\\n  
   tcp-check send PING\\r\\n  
   tcp-check expect string +PONG  
   tcp-check send info\\ replication\\r\\n  
   tcp-check expect string role:master  
   tcp-check send QUIT\\r\\n  
   tcp-check expect string +OK  
   server redis-server1 redis-server1.your\_domain:6379 check inter 5s  
   server redis-server2 redis-server2.your\_domain:6379 check inter 5s  
   server redis-server3 redis-server3.your\_domain:6379 check inter 5s  
\### Redis ###
````

3. ````
Restart HAProxy to apply changes:

````
sudo systemctl restart haproxy

````
After completing the HAProxy configuration, traffic will be directed to the primary Redis server (master). In case of failures, this setup ensures the stable operation of the system.