> For the complete documentation index, see [llms.txt](https://enterprise-ua.hideez.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://enterprise-ua.hideez.com/korporativnii-server-hideez/administration/vvimknennya-balansuvannya-navantazhennya.md).

# Ввімкнення балансування навантаження

В деяких випадках, необхідно забезпечити відмовостійкість сервера HES.

Можна умовно розділити відмовостійкість сервера бази даних (MySQL) та відмовостійкість самого HES.

Що стосується відмовостійкості баз даних, то цей процес детально розписаний у відповідній документації, наприклад - [тут](https://www.mysql.com/products/cluster/mcm/).

Тут будемо вести мову тільки про HES, і далі йде невелика інструкція як це зробити.

Розглянемо приклад, коли маємо окремий сервер MySQL, три окремих сервери HES, та проксі Nginx, через який кінцевий клієнт має доступ до групи серверів HES. Розподіл навантаження, у такому випадку буде полягати в тому, що nginx буде намагатися рівномірно розподіляти запити до трьох серверів HES, а відмовостійкість у тому, що при "падінні" якогось із серверів, користувачі будуть продовжувати користуватись сервером HES.

В такому разі, в доповнення до наших інструкцій до встановлення, потрібно зробити наступне:

* В налаштуваннях сервера MySQL потрібно дозволити віддалене підключення користувачів. За замовчуванням,  доступ до бази мають тільки локальні користувачі, тому у файлі налаштування MySQL /etc/mysql/mysql.conf.d/mysqld.cnf треба внести зміни - замість

```
bind-address = 127.0.0.1
```

потрібно зробити

```
bind-address = 0.0.0.0
```

(можна просто додати цей рядок до секції \[mysqld], якщо його там немає).

Після перезавантаження сервера MySQL ви зможете мати до нього доступ з віддалених серверів HES.

* При створенні користувача MySQL замість команди&#x20;

```
CREATE USER 'user'@'127.0.0.1' IDENTIFIED BY '<user_password>';
```

слід використовувати

```
CREATE USER 'user'@'%' IDENTIFIED BY '<user_password>';
```

Це дасть змогу користувачу `user`’ підключитись до бази з будь-якого комп'ютера.

* При редагуванні файлу /opt/HES/appsettings.Production.json слід зробити наступне:

1\) у рядку

```
"ConnectionStrings":
{
"DefaultConnection":
"server=127.0.0.1;
port=3306;
database=db;
uid=user;
pwd=<user_password>"
},
```

127.0.0.1 потрібно змінити на ip Вашого серверу MySQL

appsettings.Production.json має бути однаковим, на всіх серверах!

Однак, якщо ви хочете візуально “бачити” який сервер зараз обробляє Ваші дані, то допускається невеликі відмінності в параметрах ServerFullName та ServerShortName.

```
"ServerFullName": "Hideez Enterprise Server",
"ServerShortName": "HES",
```

2\) за замовчуванням сервер HES отримує запити тільки з localhost, але оскільки проксі з nginx у нас може бути розміщений за іншою адресою, то потрібно дозволити доступ з інших адрес. Зробити це можна, додавши в /opt/HES/appsettings.Production.json наступні рядки, after "AllowedHosts": "\*" add the following (via comma):

```
,
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:5000"
}
}
}
```

* у файлі nginx.conf на сервері nginx, потрібно закоментувати рядок

```
server localhost:5000;
```

та розкоментувати рядки:

```
#ip_hash;
#server <ip or name of hes1 server>:5000 weight=3;
#server <ip or name of hes2 server>:5000;
#server <ip or name of hes1 server>:5000;
```

Та ввівши відповідні ip-адреси своїх трьох серверів HES.

Звичайно необхідно також налаштувати правила фаєрволів.\
\
Зважайте на те, що MySQL зазвичай використовує TCP порт 3306 а HES порт TCP 5000.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://enterprise-ua.hideez.com/korporativnii-server-hideez/administration/vvimknennya-balansuvannya-navantazhennya.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
