SaltStack进阶之salt-master高可用
1. salt-master高可用
我们需要用salt来管理公司的所有机器,那么salt的master就不能宕机,否则就会整个瘫痪,所以我们必须要对salt进行高可用。salt的高可用配置非常简单,只需要改一下minion配置文件,将master用列表的形式列出即可。
[root@minion ~]# vim /etc/salt/minion
master:
- 192.168.30.150
- 192.168.30.244
2. salt-master高可用之数据同步
涉及到高可用时,数据的同步是个永恒的话题,我们必须保证高可用的2个master间使用的数据是一致的,包括:
- /etc/salt/master配置文件
- /etc/salt/pki目录下的所有key
- /srv/下的salt和pillar目录下的所有文件
保障这些数据同步的方案有:
- nfs挂载
- rsync同步
- 使用gitlab进行版本控制
安全相关:
为保证数据的同步与防止丢失,可将状态文件通过gitlab进行版本控制管理。
3. salt-master高可用配置
主机 | IP |
---|---|
master001(主master) | 192.168.30.150/24 |
master002(备master) | 192.168.30.244/24 |
minion | 192.168.30.245/24 |
3.1 修改minion端的配置文件
[root@minion ~]# vim /etc/salt/minion
master:
- 192.168.30.150
- 192.168.30.244
[root@minion ~]# systemctl start salt-minion
3.2 启动主master,接收key
[root@master01 ~]# systemctl start salt-master
[root@master01 ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 128 *:4505 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:4506 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@master01 ~]# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
minion //key已经传过来了
[root@master01 ~]# salt-key -Ay
The following keys are going to be accepted:
Unaccepted Keys:
minion
Key for minion minion accepted.
[root@master01 ~]# salt-key -L
Accepted Keys:
minion //key接收
Denied Keys:
Unaccepted Keys:
Rejected Keys:
3.3 使主备master配置同步
[root@master01 ~]# scp -r /etc/salt/ 192.168.30.244:/etc/
root@192.168.30.244's password:
cloud 100% 2927 3.1MB/s 00:00
master 100% 50KB 14.8MB/s 00:00
minion 100% 36KB 8.2MB/s 00:00
minion 100% 451 389.2KB/s 00:00
master.pem 100% 1675 1.3MB/s 00:00
master.pub 100% 451 424.7KB/s 00:00
proxy 100% 28KB 15.7MB/s 00:00
roster 100% 344 448.4KB/s 00:00
3.4 启动备master
[root@master02 ~]# systemctl start salt-master
[root@master02 ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 128 *:4505 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:4506 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@master02 ~]# salt-key -L
Accepted Keys:
minion //key已接收
Denied Keys:
Unaccepted Keys:
minion
Rejected Keys:
3.5 测试备master
[root@master02 ~]# salt '*' test.ping
minion:
True