salt/README.md

251 lines
5.9 KiB
Markdown
Raw Normal View History

2024-03-13 15:50:41 +03:00
# Краткое руководство по Salt Stack
В качестве тестового стенда используется виртуальная лаборатория
2024-03-13 15:53:40 +03:00
![stand](./stand.png)
2024-03-13 15:50:41 +03:00
2024-03-20 14:06:12 +03:00
## Установка Salt
процесс установки описан в документации <https://docs.saltproject.io/salt/install-guide/en/latest/index.html>
### Master на Альт сервер
```bash
apt-get update && apt-get install -y salt-master salt-minion salt-api
systemctl enable --now salt-master
systemctl enable --now salt-minion
```
### Minion на CentOS Stream 9
```bash
sudo rpm --import https://repo.saltproject.io/salt/py3/redhat/9/x86_64/SALT-PROJECT-GPG-PUBKEY-2023.pub
curl -fsSL https://repo.saltproject.io/salt/py3/redhat/9/x86_64/latest.repo | sudo tee /etc/yum.repos.d/salt.repo
sudo dnf install -y salt-minion
sudo systemctl enable --now salt-minion
```
### Minion на Debian 12
```bash
su -
mkdir /etc/apt/keyrings
curl -fsSL -o /etc/apt/keyrings/salt-archive-keyring-2023.gpg https://repo.saltproject.io/salt/py3/debian/12/amd64/SALT-PROJECT-GPG-PUBKEY-2023.gpg
echo "deb [signed-by=/etc/apt/keyrings/salt-archive-keyring-2023.gpg arch=amd64] https://repo.saltproject.io/salt/py3/debian/12/amd64/latest bookworm main" | tee /etc/apt/sources.list.d/salt.list
apt update
apt install -y salt-minion
systemctl enable --now salt-minion
```
### Minion на Альт Сервер 10.2
```bash
su -
apt-get update
apt-get install -y salt-minion
systemctl enable --now salt-minion
```
## Настройка master
Описание возможных директив конфигурационного файла приводится в файле `/etc/salt/master` или в документации <https://docs.saltproject.io/en/latest/ref/configuration/master.html>
Хорошим тоном является создание своих конфигурационных файлов в директории `*.d`
```bash
vim /etc/salt/master.d/master.conf
```
```bash
# The network interface to bind to
interface: 0.0.0.0
# The Request/Reply port
# Для файлового сервера, аутентификации, возврата результатов и проч.
ret_port: 4506
# The port minions bind to for commands, aka the publish port
publish_port: 4505
# Писать статистику после выполнения команд
cli_summary: true
worker_threads: 5
```
## Настройка minion
<https://docs.saltproject.io/en/latest/ref/configuration/minion.html>
```bash
cat /etc/salt/minion.d/minion.conf
```
```bash
# Адрес мастера
master: 10.1.4.1
# Уникальный идентификатор миньона
2024-03-20 15:01:17 +03:00
# по-умолчанию берётся hostname
2024-03-20 14:06:12 +03:00
id: centos-minion-1
```
2024-03-20 15:01:17 +03:00
## Ключи
2024-03-20 14:06:12 +03:00
2024-03-20 15:01:17 +03:00
Для аутентификации и авторизации в Salt используются пары ключей (закрытый, открытый). При включении службы миньона формируется пара ключей, открытый ключ отправляется на мастер.
2024-03-20 14:06:12 +03:00
2024-03-20 15:01:17 +03:00
У мастера есть специальная утилита для работы с ключами - `salt-key`
Некоторые примеры работы с ней:
Посмотреть все ключи
```bash
[root@alt-master ~]# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
alt-minion-5
alt-minion-6
centos-minion-1
centos-minion-2
deb-minion-3
deb-minion-4
Rejected Keys:
```
Принять ключ конкретного миньона
```bash
[root@alt-master ~]# salt-key -l accepted
Accepted Keys:
[root@alt-master ~]# salt-key -a centos-minion-1
The following keys are going to be accepted:
Unaccepted Keys:
centos-minion-1
Proceed? [n/Y]
Key for minion centos-minion-1 accepted.
```
Принять ключи по маске идентификаторов
```bash
[root@alt-master ~]# salt-key -a 'deb*'
The following keys are going to be accepted:
Unaccepted Keys:
deb-minion-3
deb-minion-4
Proceed? [n/Y]
Key for minion deb-minion-3 accepted.
Key for minion deb-minion-4 accepted.
```
Показать только принятые ключи
```bash
salt-key -l accepted
```
Принять все предлагаемые ключи
```bash
salt-key -A
```
Удалить ключи по маске
```bash
salt-key -d 'deb*'
```
Удалить конкретный ключ
```bash
salt-key -d deb-minion-3
```
Удалить все ключи
```bash
salt-key -D
```
2024-03-20 15:17:23 +03:00
Для дальнейшей работы необходимо принять ключи миньонов *(уверены в том, что в текущем окружении только проверенные узлы)*
2024-03-20 15:01:17 +03:00
```bash
[root@alt-master ~]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
alt-minion-5
alt-minion-6
centos-minion-2
Proceed? [n/Y]
Key for minion alt-minion-5 accepted.
Key for minion alt-minion-6 accepted.
Key for minion centos-minion-2 accepted.
```
Таким образом должен получиться такой вывод
```bash
[root@alt-master ~]# salt-key -L
Accepted Keys:
alt-minion-5
alt-minion-6
centos-minion-1
centos-minion-2
deb-minion-3
deb-minion-4
Denied Keys:
Unaccepted Keys:
Rejected Keys:
```
## Первый тест
```bash
[root@alt-master ~]# salt '*' test.ping
centos-minion-2:
True
deb-minion-3:
True
deb-minion-4:
True
centos-minion-1:
True
alt-minion-6:
True
alt-minion-5:
True
-------------------------------------------
Summary
-------------------------------------------
# of minions targeted: 6
# of minions returned: 6
# of minions that did not return: 0
# of minions with errors: 0
-------------------------------------------
```
2024-03-20 14:06:12 +03:00
## Источники
<https://www.youtube.com/watch?v=6zY41M2anrY></br>
2024-03-20 15:17:23 +03:00
<https://gitlab.com/bergentroll-docs/saltstack-tutorial>
2024-03-20 14:06:12 +03:00
<https://docs.saltproject.io/en/latest/contents.html>
2024-03-20 15:17:23 +03:00