centos6.3_x86_64node
安裝EPEL第三方軟件源centos
wget -c http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmapp
rpm -ivh epel-release-6-8.noarch.rpmdom
安裝ide
yum install salt-master -y //master測試
yum install salt-minion //clientsserver
chkconfig --list|grep salt //master默認監聽兩個端口, 4505(publish_port)爲salt的消息發佈系統,4506(ret_port)爲salt客戶端與服務端通訊的端口,因此確保客戶端能跟服務端的這2個端口通訊進程
salt-master 0:off 1:off 2:off 3:on 4:on 5:on 6:offget
salt-syndic 0:off 1:off 2:off 3:on 4:on 5:on 6:offcmd
chkconfig --list|grep salt //clients 沒有端口,只有進程
salt-minion 0:off 1:off 2:off 3:on 4:on 5:on 6:off
配置
/etc/init.d/salt-master start //master直接啓動,若也要做爲clients,install salt-minino,修改master和id
vi /etc/salt/minion //clients
master: 192.168.2.18 //冒號後面有空格
/etc/init.d/salt-minion start
認證
salt-key -L //all list 詳細可salt-key --help
實時管理
salt "localhost.localdomain" cmd.run "df -Th"
localhost.localdomain:
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
ext4 19G 6.5G 11G 38% /
tmpfs tmpfs 244M 0 244M 0% /dev/shm
/dev/sda1 ext4 485M 40M 420M 9% /boot
羣發
salt "*" cmd.run "ls -al /opt/io.sh"
localhost.localdomain:
-rwxr-xr-x 1 root root 396 Jun 8 18:22 /opt/io.sh
過濾匹配
salt '192.168.*' cmd.run 'echo hi'
正常咱們每臺主機的HOSTS都是這樣
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
爲了區分開來而且MASTER也做爲客戶端
vi /etc/salt/minion
39 id: 192.168.2.18 //或者修改成自定義名稱 好比 id: salt-master,修改id後客戶端必須重啓,salt-keys -L 才能認獲得 而後加入-a 若是修改過ID,最好把舊的刪掉 -d
salt-key -D //刪除全部KEY
salt-key -d key //刪除單個key
salt-key -A //接受全部KEY
salt-key -a key //接受單個key
[root@server1 salt]# salt-key -L
Accepted Keys:
Unaccepted Keys:
192.168.2.18
192.168.2.19
Rejected Keys:
[root@server1 salt]# salt-key -a 192.168.2.18
Key for minion 192.168.2.18 accepted.
[root@server1 salt]# salt-key -a 192.168.2.19
Key for minion 192.168.2.19 accepted.
[root@server1 salt]# salt-key -L
Accepted Keys:
192.168.2.18
192.168.2.19
Unaccepted Keys:
Rejected Keys:
測試服務端和客戶端通信
salt "192.168.2.19" test.ping //單引號也能夠
192.168.2.19:
True
salt "*" salt.modules.disk //salt.modules.disk 模塊
組
服務端:
vi /etc/salt/master
nodegroups:
mytest1: 'S@192.168.2.0/24'
salt -N mytest1 test.ping
192.168.2.18:
True
client1_2.19:
True
KEYS名字 nodegroups:
test1: 'L@192.168.2.18,client1_2.19' //多個
test2: 'client1_2.19' //單個