saltstack安装
服务端安装
1)到阿里云镜像地址http://mirrors.aliyun.com/repo/ 下载对应版本的扩展源配置 文件epel.repo 上传到本机的/etc/yum.repos.d目录
2)yum install salt-master
systemctl enable salt-master.service
mkdir -p /srv/salt/{dev,prod}
编辑配置文件/etc/salt/master
【
file_roots:
base:- /srv/salt/
dev: - /srv/salt/dev
prod: - /srv/salt/prod
】
systemctl start salt-master.service
- /srv/salt/
客户端安装
1)同服务端安装一样,上传epel.repo 上传到本机的/etc/yum.repos.d目录
2)yum install salt-minion
systemctl enable salt-minion.service
编辑配置文件/etc/salt/minion
【
master: 192.168.233.100
id: test01
】
systemctl start salt-minion.service- 添加主机
在master节点上执行salt-key -L查看可添加的minion节点
执行salt-key -A 添加所有节点 ,选择y,再用salt-key -L查看如下:
4 . 常用命令
1) 测试联通性 salt 'test01' test.ping
2) 远程执行命令 salt 'test01' cmd.run 'df -h'
3)文件分发 salt-cp '' /etc/hosts /etc
4) 使用sls脚本
①只传文件
目录及文件准备如图
hosts.sls样例:
/etc/hosts:
file.managed:
- source: salt://files/hosts
- user: root
- group: root
- mode: 644
执行 salt 'test01' state.sls saltenv='prod' sls.hosts
②传文件并执行命令
目录及文件准备如图:
jq.sls:
/usr/local/src/oniguruma-5.9.5-3.el7.art.x86_64.rpm:
file.managed:
- source: salt://base/files/oniguruma-5.9.5-3.el7.art.x86_64.rpm
- user: root
- group: root
- mode: 755
/usr/local/src/jq-1.5-1.el7.art.x86_64.rpm:
file.managed:
- source: salt://base/files/jq-1.5-1.el7.art.x86_64.rpm
- user: root
- group: root
- mode: 755
/usr/local/src/jq.sh:
file.managed:
- source: salt://base/scripts/jq.sh
- user: root
- group: root
mode: 755
cmd.run:
- cwd: /usr/local/src
- name: sh /usr/local/src/jq.sh
- unless: test -d /usr/local/src/jq.sh
- require:
- file: /usr/local/src/jq.sh
jq.sh:
cd /usr/local/src
rpm -ivh oniguruma-5.9.5-3.el7.art.x86_64.rpm
rpm -ivh jq-1.5-1.el7.art.x86_64.rpm
执行 salt 'test01' state.sls saltenv='prod' sls.jq