[root@centos5 ~]# cat /etc/hosts
- 172.1.1.5 centos4
172.1.1.6 centos5
172.1.1.7 centos6
rpm -Uvh http://mirrors.yun-idc.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
master端:yum install salt-master -y
minion端:yum install salt-minion -y
chkconfig salt-master on #服务端开机自启动
chkconfig salt-minion on #客户端开机自启动
[root@centos6 ~]# vim /etc/salt/minion
master: 172.1.1.7
[root@centos6 ~]# /etc/init.d/salt-minion start #启动服务
[root@centos5 ~]# cd /etc/salt/pki/minion/
[root@centos5 minion]# ls
minion.pem minion.pub
[root@centos6 ~]# cd /etc/salt/pki/master/
[root@centos6 master]# ls
master.pem minions minions_denied minions_rejected
master.pub minions_autosign minions_pre
[root@centos6 master]# tree ./
./
├── master.pem
├── master.pub
├── minions
├── minions_autosign
├── minions_denied
├── minions_pre
│ └── centos6
└── minions_rejected
[root@centos6 master]# salt-key
Accepted Keys: #通过接受的主机列表
Denied Keys: #黑名单
Unaccepted Keys: #待接收的主机列表
centos4
centos5
centos6
Rejected Keys: #拒绝接入的名单
salt-key -L #列出
salt-key -A #添加全部未认证的keys
salt-key -a centos* #单个添加(或者通配符)
salt-key -D #删除所有
salt-key -d centos* #单个删除或者统配
[root@centos6 master]# salt ‘*‘ test.ping #
测试指令centos5:
True
centos4:
True
centos6:
Minion did not return. [Not connected] #未连接状态
[root@centos6 master]# salt ‘*‘ cmd.run ‘uptime‘
centos5:
22:42:29 up 20 min, 1 user, load average: 0.00, 0.00, 0.00
centos4:
22:40:34 up 20 min, 1 user, load average: 0.12, 0.05, 0.08
vim /etc/salt/master #打开下面的注释
file_roots:
base:
- /srv/salt
[root@centos6 srv]# mkdir /srv/salt #配置文件目录的创建
[root@centos6 srv]# /etc/init.d/salt-master restart #重启服务 Stopping salt-master daemon: [ OK ] Starting salt-master daemon: [ OK ]
[root@centos6 salt]# cd /srv/salt/
[root@centos6 salt]# vim apache.sls (严格控制空格,不要用tab键)
- apache-install: pkg.installed: - names: - httpd - httpd-devel apache-service: service.running: - name: httpd - enable: True - reload: True
- [root@centos6 salt]# salt ‘*‘ state.sls apache #执行命令
- ‘’返回结果‘’
- centos5: ---------- ID: apache-install Function: pkg.installed Name: httpd Result: True Comment: Package httpd is already installed. Started: 23:04:40.668754 Duration: 810.705 ms Changes: ---------- ID: apache-install Function: pkg.installed Name: httpd-devel Result: True Comment: Package httpd-devel is already installed. Started: 23:04:41.479650 Duration: 0.509 ms Changes: ---------- ID: apache-service Function: service.running Name: httpd Result: True Comment: Service httpd has been enabled, and is running Started: 23:04:41.480874 Duration: 507.976 ms Changes: ---------- httpd: True Summary ------------ Succeeded: 3 (changed=1) Failed: 0 ------------ Total states run: 3 centos4: ---------- ID: apache-install Function: pkg.installed Name: httpd Result: True Comment: Package httpd is already installed. Started: 23:02:47.847090 Duration: 1554.792 ms Changes: ---------- ID: apache-install Function: pkg.installed Name: httpd-devel Result: True Comment: Package httpd-devel is already installed. Started: 23:02:49.402300 Duration: 0.817 ms Changes: ---------- ID: apache-service Function: service.running Name: httpd Result: True Comment: Service httpd has been enabled, and is running Started: 23:02:49.403861 Duration: 381.817 ms Changes: ---------- httpd: True Summary ------------ Succeeded: 3 (changed=1) Failed: 0 ------------ Total states run: 3
[root@centos6 salt]# vim top.sls
base: ‘centos*‘: - apache
- [root@centos6 salt]# salt ‘*‘ state.highstate #执行入口文件
原文:http://www.cnblogs.com/wanghui1991/p/6285182.html