1.SaltStack数据系统
Grains:存储在minion端,启动时收集信息,静态数据,重启时才会重新收集,
a.应用场景:信息查询,
[[email protected] salt]# salt ‘salt-master‘ grains.ls # 显示ls [[email protected] salt]# salt ‘salt-master‘ grains.items # 显示所有 [[email protected] salt]# salt ‘salt-master‘ grains.get fqdn salt-master: salt-master.xiao.com [[email protected] salt]# salt ‘salt-master‘ grains.get server_id salt-master: 894500124 [[email protected] salt]# salt ‘salt-master‘ grains.get ip_interfaces:eth0 salt-master: - 192.168.2.12 - fe80::20c:29ff:fe99:4d5e
b.匹配minion
[[email protected] 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 [email protected] 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 [email protected] IDLE JCPU PCPU WHAT root pts/0 192.168.2.1 04:30 25:21 0.15s 0.15s -bash
自定义grains,
[[email protected] salt]# vim /etc/salt/minion # 打开注释 88 grains: 89 roles: 90 - webserver 91 - memcache [[email protected] salt]# salt -G ‘roles:memcache‘ cmd.run ‘echo hehe‘ # 在memcached的机器上执行echo hehe salt-master: hehe
或者在vim /etc/salt/grains建立
[[email protected] salt]# vim /etc/salt/grains # 自定义建立一个grains的nginxweb规则 nginxweb: nginx ~ [[email protected] salt]# /etc/init.d/salt-minion restart [[email protected] 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 [email protected] IDLE JCPU PCPU WHAT root pts/0 192.168.2.1 04:19 1.00s 0.85s 0.53s /usr/bin/python [[email protected] salt]# vim /srv/salt/top.sls # 建立高级sls命令 base: ‘nginxweb:nginx‘: # 关联上面grain中自定义的规则 - match: grain - apache [[email protected] salt]# salt ‘*‘ state.hightstate # 执行
时间: 2024-11-03 20:57:10