[master端]
修改完master和minion的配置文件后
啟動(dòng)服務(wù):service salt-master start
查看是否獲取到minion端IP(打印出所有授權(quán)或未授權(quán)的minion節(jié)點(diǎn)):salt-key -L
沒有獲取到的話(沒在master配置自動(dòng)獲?。瑘?zhí)行(授權(quán)所有節(jié)點(diǎn)) salt-key -A
或者salt-key -a NAME
(授權(quán)NAME節(jié)點(diǎn))
在授權(quán)完成后,我們就可以通過master對minion端進(jìn)行控制了
基本命令
master:192.168.135.128;minion:192.168.135.129
## 查看當(dāng)前的salt key信息
salt-key '*' -L
## 測試被控主機(jī)的連通性
salt '*' test.ping
## 遠(yuǎn)程執(zhí)行命令
salt '192.168.135.129' cmd.run 'ifconfig' 或者 salt '*' cmd.run 'ifconfig'
## 根據(jù)被控主機(jī)的grains信息進(jìn)行匹配過濾
## -G 參數(shù)回=會(huì)根據(jù)默認(rèn)的grain的結(jié)果來指定最新的grain
salt -G 'os:Centos' test.ping
## 顯示被控主機(jī)的操作類型
salt '*' grains.item os
## 遠(yuǎn)程代碼執(zhí)行測試
salt '*' cmd.exec_code python'import sys;print sys.version'
## 遠(yuǎn)程拷貝(拷貝123.txt到所有客戶端的/root目錄下)
salt-cp '*' 123.txt /root
## 分組操作
## 列出模塊的函數(shù)
#grains模塊#
salt 192.168.184.129 sys.list_functions grains
#cmd模塊#
salt 192.168.184.129 sys.list_functions cmd
## 查看函數(shù)說明
salt 192.168.184.129 sys.doc grains
安裝包管理
- 對于程序安裝,salt提供了pkg模塊:
salt 192.168.184.133 pkg.install "httpd"
pkg.version ## 查看已安裝軟件的基本信息
pkg.remove ## 刪除已安裝的軟件
管理服務(wù)模塊
[root@localhost ~]# salt 192.168.184.133 service.status httpd
192.168.184.133:
True
- 通過遠(yuǎn)程執(zhí)行命令查看httpd進(jìn)程確實(shí)存在
[root@localhost ~]# salt 192.168.184.133 cmd.run 'ps -ef|grep httpd|grep -v grep'
192.168.184.133:
root 4999 1 0 10:49 ? 00:00:00 /usr/sbin/httpd
apache 5002 4999 0 10:49 ? 00:00:00 /usr/sbin/httpd
apache 5003 4999 0 10:49 ? 00:00:00 /usr/sbin/httpd
apache 5004 4999 0 10:49 ? 00:00:00 /usr/sbin/httpd
apache 5005 4999 0 10:49 ? 00:00:00 /usr/sbin/httpd
apache 5006 4999 0 10:49 ? 00:00:00 /usr/sbin/httpd
apache 5007 4999 0 10:49 ? 00:00:00 /usr/sbin/httpd
apache 5008 4999 0 10:49 ? 00:00:00 /usr/sbin/httpd
apache 5009 4999 0 10:49 ? 00:00:00 /usr/sbin/httpd
文件管理模塊
- 對于文件管理salt提供了file模塊,常用的如下:
[root@localhost ~]# salt 192.168.184.133 file.stats /etc/yum.conf
[root@localhost ~]# salt 192.168.184.133 file.chown /etc/passwd root root
用戶管理模塊
salt 192.168.184.133 user.add mysql
salt 192.168.184.133 user.delete mysql
salt 192.168.184.133 user.info mysql
復(fù)合匹配