masterless
应用场景
master与minion网络不通有延迟,即网络稳定或通信
想在minion端直接执行状态
传统的 SaltStack 是需要通过 master来执行状态控制 minion从而实现状态的管理,但是当网络不稳定的时候,当想在minion本地执行状态的时候,当在只有一台主机的时候,想执行状态该怎么办呢?这就需要用到 masterless 了。
有了masterless,即使你只有一台主机,也能玩saltstack,而不需要你有N台主机架构。(下面我们来玩一下这个配置)
masterless配置
注释大师行
取消注释file_client并设置其值为local
设置file_roots
设置pillar_roots
#修改minion配置文件
[root@slave02 ~]# vim /etc/salt/minion
修改处1:
12 #default_include: minion.d/*.conf
14 # Set the location of the salt master server. If the master server cannot be
15 # resolved, then the minion will fail to start.
16 #master: salt
17 master: 192.168.230.131 #这是之前配置的,现在需要删除
修改处2:
606# defined below by setting it to "local". Setting a local file_client runs the
607# minion in masterless mode.
608 file_client: local #把原来的remote修改为local,并取消注释
609# The file directory works on environments passed to the minion, each environment
修改处3:
#取消注释并加上base路径
file_roots:
base:
- /srv/salt/base
# Uncomment the line below if you do not want the file_server to follow
修改处4:
#取消注释并加上base路径
pillar_roots:
base:
- /srv/pillar/base
#创建文件中指定路径
[root@slave02 ~]# mkdir -p /srv/{salt,pillar}/base
#查看,没有tree的自行用yum进行下载即可
[root@slave02 ~]# tree /srv/
/srv/
├── pillar
│ └── base
└── salt
└── base
4 directories, 0 files
#因为要在没有master的情况下做,所以直接关闭minion服务
[root@slave02 ~]# systemctl stop salt-minion
[root@slave02 ~]# systemctl disable --now salt-minion
Removed /etc/systemd/system/multi-user.target.wants/salt-minion.service.
salt-call
masterless模式执行模块或状态时需要使用salt-call命令,而不再是salt或者salt-ssh。需要注意的是要使用salt-call的–local选项,表示是本地执行
实例:
[root@slave02 ~]# salt-call --local cmd.run 'date'
local:
Mon Nov 29 05:31:29 EST 2021
[root@slave02 ~]# salt-call --local cmd.run 'uptime'
local:
05:33:34 up 8:31, 4 users, load average: 0.02, 0.05, 0.01
#使用文件的形式和之前在master端上是一样的,下面进行masterless使用状态文件测试
[root@slave02 ~]# cd /srv/salt/base/
[root@slave02 base]