使用分组
修改minon的ID,做一个标识
[root@node2 ~]# vim /etc/salt/minion
master: 172.25.254.130 id: web1 #node2
[root@node2 ~]# systemctl restart salt-minion [root@node3 ~]# vim /etc/salt/minion
master: 172.25.254.130 id: web2 #node3 [root@node3 ~]# vim /etc/salt/minion
[root@node4 ~]# systemctl restart salt-minion
master: 172.25.254.130 id: web3 #node3
[root@node4 ~]# systemctl restart salt-minion [root@node5 ~]# vim /etc/salt/minion
master: 172.25.254.130 id: db1 #node4
[root@node5 ~]# systemctl restart salt-minion [root@node6 ~]# vim /etc/salt/minion
master: 172.25.254.130 id: db2 #node5
[root@node6 ~]# systemctl restart salt-minion
master重新添加秘钥
[root@node1 ~]# salt-key -D
[root@node1 ~]# salt-key -A
[root@node1 ~]# salt-key -L
Accepted Keys:
db1
db2
web1
web2
web3
Denied Keys:
Unaccepted Keys:
Rejected Keys:
测试连通性
[root@node1 ~]# salt '*' test.ping web2: True web3: True db1: True db2: True web1: True [root@node1 ~]# salt '*' cmd.run 'date' db2: Wed Apr 3 08:31:03 CST 2019 web3: Wed Apr 3 08:31:04 CST 2019 web2: Wed Apr 3 08:31:05 CST 2019 db1: Wed Apr 3 08:31:04 CST 2019 web1: Wed Apr 3 08:31:06 CST 2019 [root@node1 ~]# salt -E "web\d" test.ping #\d 匹配一个数字 \d+ 匹配 1..n 个数字 web2: True web3: True web1: True [root@node1 ~]# salt -L "web1,web2,db2" test.ping #L 列表 后面跟随主机的名称,用 “,”分割 web2: True web1: True db2: True
分组
[root@node1 ~]# vim /etc/salt/master
nodegroups: group1: "L@web1,web2,db2" groupweb: "L@web1,web2,web3" groupdb: "L@db1,db2"
[root@node1 ~]# systemctl restart salt-master
测试组
[root@node1 ~]# salt -S "172.25.254.0/24" test.ping web2: True web3: True web1: True db1: True db2: True [root@node1 ~]# salt -N group1 test.ping web2: True web1: True db2: True [root@node1 ~]# salt -N groupweb test.ping web2: True web1: True web3: True [root@node1 ~]# salt -N groupdb test.ping db2: True db1: True
发送文件和文件夹
[root@node1 ~]# mkdir -p /srv/salt/files
[root@node1 ~]# cd /srv/salt/files
[root@node1 files]# echo testfile >> testfile
[root@node1 files]# salt -N groupweb cp.get_file salt://files/testfile /var/tmp/f1
检测
[root@node1 files]# salt -N groupweb cmd.run 'md5sum /var/tmp/f1'
源文件对比
[root@node1 files]# md5sum testfile
e9409172a4036cc688f169c72131e921 testfile
查看内容
[root@node1 files]# salt -N groupweb cmd.run 'cat /var/tmp/f1'
修改文件内容传递,内容覆盖
[root@node1 files]# echo 11111111 >>testfile [root@node1 files]# salt -N groupweb cp.get_file salt://files/testfile /var/tmp/f1 web3: /var/tmp/f1 web1: /var/tmp/f1 web2: /var/tmp/f1 [root@node1 files]# salt -N groupweb cmd.run 'cat /var/tmp/f1' web3: testfile 11111111 web2: testfile 11111111 web1: testfile 11111111
传输文件夹
[root@node1 files]# cd ..
[root@node1 salt]# salt -N groupweb cp.get_dir salt://files /var/tmp/testdir
检测:
[root@node1 salt]# salt -N groupweb cmd.run 'cat /var/tmp/testdir/files/testfile'
查看模块,功能和使用方法
[root@node1 salt]# salt 'web1' sys.list_modules
web1: - acl - aliases - alternatives - archive - artifactory - beacons - bigip - blockdev - btrfs - buildout - cloud - cmd - composer - config - consul - container_resource - cp - cron - data - defaults - devmap - disk - django - dnsmasq - dnsutil - drbd - elasticsearch - environ - etcd - ethtool - event - extfs - file - firewalld - gem - genesis - gnome - grains - group - hashutil - hipchat - hosts - http - img - incron - infoblox - ini - inspector - introspect - ip - ipset - iptables - jboss7 - jboss7_cli - k8s - key - keyboard - kmod - locale - locate - logrotate - lowpkg - lvm - match - mine - minion - modjk - mount - nagios_rpc - network - nova - nspawn - openscap - openstack_config - pagerduty - pagerduty_util - pam - partition - pillar - pip - pkg - pkg_resource - postfix - publish - pushover - pyenv - random - random_org - rbenv - rest_sample_utils - ret - rvm - s3 - s6 - salt_proxy - saltutil - schedule - scsi - sdb - seed - serverdensity_device - service - shadow - slack - slsutil - smbios - smtp - sqlite3 - ssh - state - status - supervisord - sys - sysctl - sysfs - syslog_ng - system - telemetry - temp - test - timezone - tuned - udev - uptime - user - vbox_guest - virtualenv - xfs - zenoss