标签:
1.SaltStack数据系统
Grains:存储在minion端,启动时收集信息,静态数据,重启时才会重新收集,
a.应用场景:信息查询,
[root@salt-master salt]# salt ‘salt-master‘ grains.ls # 显示ls [root@salt-master salt]# salt ‘salt-master‘ grains.items # 显示所有 [root@salt-master salt]# salt ‘salt-master‘ grains.get fqdn salt-master: salt-master.xiao.com [root@salt-master salt]# salt ‘salt-master‘ grains.get server_id salt-master: 894500124 [root@salt-master salt]# salt ‘salt-master‘ grains.get ip_interfaces:eth0 salt-master: - 192.168.2.12 - fe80::20c:29ff:fe99:4d5e
b.匹配minion
[root@salt-master salt]# salt -G os:CentOS cmd.run ‘w‘ salt-master: 05:26:01 up 1:07, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.2.1 04:19 0.00s 0.80s 0.55s /usr/bin/python salt-minion: 05:36:34 up 1:07, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.2.1 04:30 25:21 0.15s 0.15s -bash
自定义grains,
[root@salt-master salt]# vim /etc/salt/minion # 打开注释 88 grains: 89 roles: 90 - webserver 91 - memcache [root@salt-master salt]# salt -G ‘roles:memcache‘ cmd.run ‘echo hehe‘ # 在memcached的机器上执行echo hehe salt-master: hehe
或者在vim /etc/salt/grains建立
[root@salt-master salt]# vim /etc/salt/grains # 自定义建立一个grains的nginxweb规则 nginxweb: nginx ~ [root@salt-master salt]# /etc/init.d/salt-minion restart [root@salt-master salt]# salt -G nginxweb:nginx cmd.run ‘w‘ # 查找minion匹配到有nginxweb:nginx的机器执行w命令 salt-master: 05:39:53 up 1:21, 1 user, load average: 0.08, 0.02, 0.01 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.2.1 04:19 1.00s 0.85s 0.53s /usr/bin/python [root@salt-master salt]# vim /srv/salt/top.sls # 建立高级sls命令 base: ‘nginxweb:nginx‘: # 关联上面grain中自定义的规则 - match: grain - apache [root@salt-master salt]# salt ‘*‘ state.hightstate # 执行
标签:
原文地址:http://www.cnblogs.com/sunmmi/p/5877828.html