[root@salt-master ~]# salt-master --version
salt-master 2015.5.10 (Lithium)
#master 的配置文件
[root@salt-master ~]# cat /etc/salt/roster
web1:
host: 192.168.50.101
user: root
passwd: 123456
web2:
host: 192.168.50.99
user: root
passwd: 123456
#操作命令
salt-ssh "web2" -ir "uptime" #第一次执行命令需要认证用户 需要加上-ir 参数
salt-ssh "web2" -r "uptime" #第二次只需要加上-r
#安装客户端,先安装WGET ,在安装epel源。在安装salt-minion
salt-ssh "web2" -r "yum install wget -y"
salt-ssh "web3" -r "wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo"
salt-ssh "web2" -r "yum install salt-minion -y"
salt-ssh "web3" -r "/etc/init.d/salt-minion start"
#设置master 的地址和认证KEY
salt-ssh "web2" -r "sed -i '17amaster: 192.168.50.100' /etc/salt/minion"
salt-key
salt-key -A -y
#执行命令
[root@salt-master html]# salt 'BJ-M5-02' cmd.run "echo 'BJ-M5-02 192.168.50.98' >> /etc/hosts"
BJ-M5-02:
[root@salt-master html]# salt 'BJ-M5-02' cmd.run "cat /etc/hosts"
BJ-M5-02:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
BJ-M5-02 192.168.50.98
salt "*" cmd.run "ss |wc -l"