salt/README.md

249 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Краткое руководство по Salt Stack
В качестве тестового стенда используется виртуальная лаборатория
![stand](./stand.png)
## Установка 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
# Уникальный идентификатор миньона
# по-умолчанию берётся hostname
id: centos-minion-1
```
## Ключи
Для аутентификации и авторизации в Salt используются пары ключей (закрытый, открытый). При включении службы миньона формируется пара ключей, открытый ключ отправляется на мастер.
У мастера есть специальная утилита для работы с ключами - `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
```
Для дальнейшей работы необходимо принять ключи миньонов (уверены в том, что в текущем окружении только проверенные узлы)
```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
-------------------------------------------
```
## Источники
<https://www.youtube.com/watch?v=6zY41M2anrY></br>
<https://docs.saltproject.io/en/latest/contents.html>