SaltStack批量管理工具安装配置

cat /etc/redhat-release
CentOS release 6.5 (Final)
salt --version
salt 2015.5.10 (Lithium)
1、客户端安装
client
cat /etc/hosts
192.168.2.108 CentOS-6.5-2-108


rpm -Uvh http://mirrors.yun-idc.com/epel/6Server/x86_64/epel-release-6-8.noarch.rpm
yum install -y salt-minion
2、客户端配置
vim /etc/salt/minion
master: CentOS-6.5-2-108
/etc/init.d/salt-minion start


3、服务端安装
server
rpm -Uvh http://mirrors.yun-idc.com/epel/6Server/x86_64/epel-release-6-8.noarch.rpm
yum install -y salt-master
4、服务端认证
salt-key -L  #查看所有的请求
salt-key -A -y   #允许所有请求


5、使用实例
1)ping 测试
salt '*' test.ping
CentOS-6.5-2-110:
    True
CentOS-6.5-2-109:
    True
2)使用命令
salt '*' cmd.run 'hostname'
CentOS-6.5-2-110:
    CentOS-6.5-2-110
CentOS-6.5-2-109:
    CentOS-6.5-2-109




3)使用文件系统
vi /etc/salt/master
file_roots:
  base:
    - /srv/salt


mkdir -p /srv/salt/script
cd /srv/salt/script
vi test.sh
#!/bin/bash


ip1=`ifconfig eth0|awk -F "[: ]+" '/inet addr/ {print $4}'`
echo "localhostip $ip1" > /tmp/ip.txt


4)在目标机器执行本地脚本
salt '*' cmd.script salt://script/test.sh
 salt '*' cmd.run 'cat /tmp/ip.txt'
CentOS-6.5-2-110:
    localhostip 192.168.2.110
CentOS-6.5-2-109:

    localhostip 192.168.2.109

5)向远程机器上拷贝文件

salt '*' cp.get_file salt://script/test.sh /root/test.sh






cd /srv/salt/
vi top.sls
base:
  '*':
    - test


vi test.sls
/tmp/test.sh:
  file.managed:
   - source: salt://script/test.sh
   - user: root
   - group: root
   - mode: 600


执行指定某一个模块
salt '*' state.sls test
执行指定某一个模块下子模块(/srv/salt/下的目录)
mkdir -p /srv/salt/test;mv test.sls test
salt '*' state.sls test             #默认执行test目录下init.sls
salt '*' state.sls test.test
执行全部拷贝模块(top.sls包含的所有)
salt '*' state.highstate


http://docs.saltstack.cn/参考资料

猜你喜欢

转载自blog.csdn.net/qq_37594711/article/details/79128409