1.SaltStack Data System
Grains: Stored on the minion side, collect information at startup, static data, and re-collect it when it restarts.
A. Application scenario: Information query,
[[email protected] salt]# Salt ' salt-master ' grains.ls # show Ls[[email protected] salt]# salt ' salt-master ' Grains.item S # Show all [[email protected] salt]# Salt ' salt-master ' grains.get FQDN salt-master: salt-master.xiao.com[[ Email protected] salt]# Salt ' salt-master ' grains.get server_idsalt-master: 894500124[[email protected] salt]# salt ' Salt-master ' grains.get ip_interfaces:eth0salt-master: -192.168.2.12 -fe80::20c:29ff:fe99:4d5e
B. Matching 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 Root pts/0 192.168.2.1 04:19 0.00s 0.80s 0.55s/usr/bin/pythonsalt-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
Custom Grains,
[[email protected] salt]# vim/etc/salt/minion # Open Comment grains:89 roles:90 -webserver- Memcach E[[email protected] salt]# salt-g ' roles:memcache ' cmd.run ' echo hehe ' # perform echo memcached on Hehesalt-master:
hehe
or set up in Vim/etc/salt/grains
[[email protected] salt]# vim/etc/salt/grains # Custom Create a grains nginxweb rule nginxweb:nginx~ [[email protected] salt]#/etc/init.d/salt-minion restart[[email protected] salt]# salt-g nginxweb:nginx cmd.run ' W ' # Find minion matches to a machine with Nginxweb:nginx execute w command 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 # Build Advanced SLS Command base: ' Nginxweb:nginx ': # Associate the custom rule in grain above -match:grain -Apache [[email protected] salt]# Salt ' * ' state.hightstate # Execute
Saltsack automatic operation and maintenance 2