﻿# Install HAProxy 

> [HTML Version](haproxy-load-balance.html)

HAProxy is a tool for ensuring high availability and load balancing. In the BRIX system, HAProxy is employed to build a resilient architecture for organizing a highly available BRIX cluster. The necessary HAProxy configuration is chosen based on the architecture being established. This article divides the HAProxy configuration into a basic setup (the HAProxy service config) and configurations for balancing BRIX components, which can be added to the HAProxy config alongside the basic section.

The installation consists of 3 steps:

1. [Install HAProxy](#install-haproxy).

2. [Configure basic HAProxy settings](#set-up-haproxy-configuration).

3. [Add configurations for balancing BRIX components](#add-configurations).

## Step 1: Install HAProxy

1. Install HAProxy using the following command:

````
sudo apt install haproxy -y

2. ````
Start the HAProxy service and enable it at boot:

````
sudo systemctl enable --now haproxy

## ````
Step 2: Configure basic HAProxy settings

1. Move the default configuration file:

````
sudo mv /etc/haproxy/haproxy.cfg\{,.original\}

2. ````
Create and open a new configuration file for editing:

````
sudo nano /etc/haproxy/haproxy.cfg

````
The basic section of the configuration file describes the parameters of the HAProxy server, such as the operating mode, timeouts, connection counts, enabling the web interface, and more. The provided example includes the necessary configuration for the HAProxy server to function. For more details about the parameters used, refer to the [official HAProxy documentation](http://docs.haproxy.org/).

Example basic HAProxy configuration for the haproxy.cfg file

````
global  
    maxconn 100000  
    log /dev/log local0  
    log /dev/log local1 notice  
    chroot /var/lib/haproxy  
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners  
    stats timeout 30s  
    user haproxy  
    group haproxy  
    daemon  
  
defaults  
    mode tcp  
    log global  
    retries 2  
    timeout queue 5s  
    timeout connect 5s  
    timeout client 60m  
    timeout server 60m  
    timeout check 15s  
  
listen stats  
    mode http  
    bind haproxy-server.your\_domain:7000  
    stats enable  
    stats uri /  
  
\### Web BRIX ###  
\### Web BRIX ###  
  
\### PostgreSQL ###  
\### PostgreSQL ###  
  
\### Valkey/Redis ###  
\### Valkey/Redis ###  
  
\### RabbitMQ ###  
\### RabbitMQ ###  
  
\### S3 MinIO ###  
\### S3 MinIO ###  
  
\### Docs Server ###  
\### Docs Server ###
````

3. ````
Restart HAProxy:

````
sudo systemctl restart haproxy

## ````
Step 3: Add configurations for balancing BRIX components

Configurations for BRIX components are added to the \[OBJECT\] file as needed. 

Depending on the architecture being built, you can add the following configurations:

- [HAProxy for PostgreSQL](haproxy-postgresql.md).

- [HAProxy for RabbitMQ](haproxy-rabbitmq.md)

- [HAProxy for S3 Minio](haproxy-s3-minio.md).

- [HAProxy for BRIX web](haproxy-web-elma365.md).

- [HAProxy for document server](haproxy-docs-server.md).