基本环境
服务器:
test11:192.168.37.11
test22:192.168.37.12
test33:192.168.37.13
系统版本:CentOS Linux release 7.6.1810 (Core)
测试方便关闭防火墙:systemctl stop firewalld.service
安装
安装参考文档:https://repo.saltstack.com
添加yum源:yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest.el7.noarch.rpm
服务器 test11:
安装master端:yum install salt-master
服务器 test22,test33:
安装minion端:yum install salt-minion
master添加自定义配置文件,开启file和pillar模块:
cat > /etc/salt/master.d/file_dir.conf << EOF
pillar_roots:
base:
- /srv/salt/pillar
file_roots:
base:
- /srv/salt/state
EOF
创建目录:mkdir /srv/salt/{state,pillar} -p
minion端添加自定义配置文件,设置salt_master及id:
cat > /etc/salt/minion.d/test.conf << EOF
# Set the location of the salt master server. If the master server cannot be
# resolved, then the minion will fail to start.
master: 192.168.37.11 #指定master端,有条件的建议指定的域名。
# Explicitly declare the id for this minion to use, if left commented the id
# will be the hostname as returned by the python call: socket.getfqdn()
# Since salt uses detached ids it is possible to run multiple minions on the
# same machine but with different ids, this can be useful for salt compute
# clusters.
id: `hostname`
EOF
master端启动及添加到开机启动:
systemctl start salt-master
systemctl enable salt-master
minion端启动及添加到开机启动:
systemctl start salt-minion
systemctl enable salt-minion
查看版本:salt --version
salt 2019.2.0 (Fluorine)
在master端查看、添加、删除minion端
查看minion端:salt-key -L
添加单个minion端:salt-key -a test22 -y #test22替换成你相应的客户端主机名就可以
添加所有minion端:salt-key -A -y
删除单个minion端:salt-key -d test22 -y #test22替换成你相应的客户端主机名就可以
删除所有minion端:salt-key -D -y
salt-master迁移
1、把原salt-master上的pki文件夹打包到新的salt-master机器上:
scp -rp /etc/salt/pki root@192.168.139.44:/etc/salt
2、更改salt的client的hosts文件,指向新的salt-master
3、重启client的salt-minion
4、到44的机器上测试一下有没有迁移成功了
salt ‘*’ test.ping
minion端更改主机名
1、master上踢除要更改主机名的client,
2、在client上更改主机名,删除minion_id文件和pki目录,重启minion服务