salt-master高可用
文章目录
salt-master高可用配置
我们需要用salt来管理公司的所有机器,那么salt的master就不能宕机,否则就会整个瘫痪,所以我们必须要对salt进行高可用。salt的高可用配置非常简单,只需要改一下minion配置文件,将master用列表的形式列出即可。
salt-master高可用之数据同步
涉及到高可用时,数据的同步是个永恒的话题,我们必须保证高可用的2个master间使用的数据是一致的,包括:
- /etc/salt/master配置文件
- /etc/salt/pki目录下的所有key
- /srv/下的salt和pillar目录下的所有文件
保障这些数据同步的方案有:
- nfs挂载
- rsync同步
- 使用gitlab进行版本控制
安全相关:
为保证数据的同步与防止丢失,可将状态文件通过gitlab进行版本控制管理。
salt-syndic分布式架构
salt-syndic架构图
salt-syndic的优劣势
优势:
- 可以通过syndic实现更复杂的salt架构
- 减轻master的负担
劣势:
- syndic的/srv目录下的salt和pillar目录内容要与最顶层的master下的一致,所以要进行数据同步,同步方案同salt-master高可用
- 最顶层的master不知道自己有几个syndic,它只知道自己有多少个minion,并不知道这些minion是由哪些syndic来管理的
salt-syndic部署
环境说明
主机IP | 角色 | 安装的应用 |
---|---|---|
192.168.10.201 | Master | salt-master |
192.168.10.202 | Syndic | salt-master salt-syndic |
192.168.10.203 | Minion | salt-minion |
安装salt-master与salt-syndic
主备节点提前测试能否单独ping通
[root@master ~]# salt master2 test.ping
master2:
True
[root@master2 ~]# salt master2 test.ping
master2:
True
修改salt-minion端配置文件
[root@lamp ~]# vim /etc/salt/minion
# Set the location of the salt master server. If the master server cannot be
# resolved, then the minion will fail to start.
#master: salt
master:
- 192.168.10.201 #添加主master
- 192.168.10.202 #添加备master
# Setting master_type to 'disable' lets you have a running minion (with engines and
# beacons) without a master connection
master_type: failover #取消注释并将值设置为failover
# set the value to -1. (This may be necessary on machines which have high numbers
# of TCP connections, such as load balancers.)
master_alive_interval: 3 #取消注释,并设置主备切换响应时间
master主节点ping
[root@master ~]# salt master2 test.ping
master2:
True
master备节点ping
[root@master2 ~]# salt master2 test.ping
master2:
Minion did not return. [No response]
The minions may not have all finished running and any remaining minions will return upon completion. To look up the return data for this job later, run the following command:
salt-run jobs.lookup_jid 20211129084254138475
ERROR: Minions returned with non-zero exit code
停掉master主节点的salt-master.service
[root@master ~]# systemctl stop salt-master.service
查看minion节点状态
[root@node2 ~]# systemctl status salt-minion.service
● salt-minion.service - The Salt Minion
Loaded: loaded (/usr/lib/systemd/system/salt-minion.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-11-29 03:41:51 EST; 4min 28s ago
Docs: man:salt-minion(1)
file:///usr/share/doc/salt/html/contents.html
https://docs.saltproject.io/en/latest/contents.html
Main PID: 201865 (salt-minion)
Tasks: 7 (limit: 11201)
Memory: 91.0M
CGroup: /system.slice/salt-minion.service
├─201865 /usr/bin/python3.6 /usr/bin/salt-minion
├─201891 /usr/bin/python3.6 /usr/bin/salt-minion
└─201893 /usr/bin/python3.6 /usr/bin/salt-minion
11月 29 03:41:51 node2 systemd[1]: Starting The Salt Minion...
11月 29 03:41:51 node2 systemd[1]: Started The Salt Minion.
11月 29 03:42:03 node2 salt-minion[201865]: [CRITICAL] 'master_type' set to 'failover' but 'retry_dns' is not 0. Setting 'retry_dns' to 0 to failover to the next master on DNS errors.
11月 29 03:46:12 node2 salt-minion[201865]: [WARNING ] Master ip address changed from 192.168.10.201 to 192.168.10.202
11月 29 03:46:12 node2 salt-minion[201865]: [WARNING ] Master ip address changed from 192.168.10.201 to 192.168.10.202
master备节点ping
[root@master2 ~]# salt node2 test.ping
node2:
True