masterless
masterless配置
- 修改配置文件minion
- 注释master行
- 取消注释file_client并设其值为local
- 设置file_roots
- 设置pillar_roots
[root@minion ~]# 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.20 //添加注释
......
# Set the file client. The client defaults to looking on the master server for
# files, but can be directed to look at the local file directory setting
# defined below by setting it to "local". Setting a local file_client runs the
# minion in masterless mode.
file_client: local //这一行取消注释改remote为local
......
file_roots: //设置file_roots的路径
base:
- /srv/salt/base //取消注释或者自行添加
关闭salt-minion服务
使用 masterless 模式时是不需要启动任何服务的,包括salt-master和salt-minion。
[root@minion ~]# systemctl stop salt-minion
[root@minion ~]# systemctl disable salt-minion
Removed /etc/systemd/system/multi-user.target.wants/salt-minion.service.
salt-call
masterless模式执行模块或状态时需要使用salt-call命令,而不再是salt或者salt-ssh。
[root@minion ~]# salt-call --local cmd.run 'uptime'
local:
09:47:25 up 36 min, 2 users, load average: 0.25, 0.22, 0.24
[root@minion ~]# salt-call --local cmd.run 'date'
local:
Wed Jul 21 09:50:48 EDT 2021
[root@minion ~]# mkdir -p /srv/salt/base
[root@minion ~]# cd /srv/salt/base/
[root@minion base]# vim wget.sls
test_wget:
pkg.installed:
- name: wget
[root@minion base]# salt-call --local state.sls wget
local:
----------
ID: test_wget
Function: pkg.installed
Name: wget
Result: True
Comment: All specified packages are already installed
Started: 09:53:22.047074
Duration: 1321.579 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 1.323 s
[root@minion base]# which wget
/usr/bin/wget