安裝完Saltstack
後能夠當即執行shell
命令,更新軟件包並將文件同時分不到全部受管系統。全部回覆都以一致的可配置格式返回。遠程執行參考文檔:http://docs.saltstack.cn/topics/tutorials/modules.htmlhtml
[root@salt-master ~]# salt '*' cmd.run "uptime" salt-minion01: 15:23:08 up 1 day, 58 min, 2 users, load average: 0.00, 0.03, 0.08 salt-minion02: 15:23:08 up 21:38, 2 users, load average: 0.00, 0.04, 0.10 salt-minion03: 15:23:08 up 21:36, 2 users, load average: 0.00, 0.04, 0.10
salt '<target>' <function> [arguments]
一、通配符匹配node
[root@salt-master ~]# salt '*' test.ping [root@salt-master ~]# salt 'salt-minion01' test.ping [root@salt-master ~]# salt '*01' test.ping [root@salt-master ~]# salt 'salt-minion0[1|2]' test.ping [root@salt-master ~]# salt 'salt-minion0[!1|2]' test.ping [root@salt-master ~]# salt 'salt-minion0?' test.ping
二、列表匹配web
[root@salt-master ~]# salt -L 'salt-minion01,salt-minion02' test.ping
三、正則匹配算法
[root@salt-master ~]# salt -E '^salt' test.ping [root@salt-master ~]# salt -E '^salt.*2$' test.ping
四、IP匹配shell
[root@salt-master ~]# salt -S '192.168.1.32' test.ping [root@salt-master ~]# salt -S '192.168.1.0/24' test.ping
五、複合匹配vim
[root@salt-master ~]# salt -C 'G@os:CentOS and S@192.168.1.32' test.ping
六、分組匹配app
[root@salt-master ~]# vim /etc/salt/master nodegroups: webserver: 'salt-minion01,salt-minion02' dbserver: 'salt-minion03 [root@salt-master ~]# systemctl restart salt-master [root@salt-master ~]# salt -N 'webserver' test.ping [root@salt-master ~]# salt -N 'dbserver' test.ping
七、Grains匹配ssh
[root@salt-master ~]# salt -G 'os:CentOS' test.ping [root@salt-master ~]# salt -G 'localhost:salt-minion02' test.ping
說明:上面這些匹配方式在top.sls
文件中一樣適用。測試
test 模塊多用於測試
user 模塊用於用戶管理
cmd 模塊能夠執行任意shell命令
pkg 模塊用於軟件包管理
file 模塊多用於配置
service 模塊用於服務管理
全部模塊列表ui
test模塊
模塊名:test 功能:用於測試 [root@salt-master ~]# salt '*' test.ping
user模塊
參考:http://docs.saltstack.cn/ref/modules/all/salt.modules.useradd.html#module-salt.modules.useradd # salt '*' user.add name <uid> <gid> <groups> <home> <shell> [root@salt-master ~]# salt '*' user.add testuser
cmd模塊
模塊名:cmd 功能:實現遠程的命令行調用執行(默認具有root操做權限,使用時需評估風險) #查看全部minion內存和磁盤使用狀況 [root@salt-master ~]# salt '*' cmd.run "free -m" [root@salt-master ~]# salt '*' cmd.run "df -h"
pkg模塊
模塊名:pkg 功能:軟件包狀態管理,會根據操做系統不一樣,選擇對應的安裝方式(如CentOS系統默認使用yum,Debian系統默認使用apt-get) #安裝 [root@salt-master ~]# salt '*' pkg.install "vsftpd" #卸載 [root@salt-master ~]# salt '*' pkg.remove "vsftpd" #安裝最新版本 [root@salt-master ~]# salt '*' pkg.latest_version "vsftpd" #更新軟件包 [root@salt-master ~]# salt '*' pkg.upgrade "vsftpd" #查看幫助手冊 [root@salt-master ~]# salt '*' pkg
file模塊
模塊名:file 功能:被控主機常見的文件操做,包括文件讀寫、權限、查找、校驗 #校驗全部minion主機文件的加密信息,支持md五、sha一、sha22四、shs25六、sha38四、sha512加密算法 [root@salt-master ~]# salt '*' file.get_sum /etc/passwd md5 #修改全部minion主機/etc/passwd文件的屬組、用戶權限、等價於chown root:root /etc/passwd [root@salt-master ~]# salt '*' file.chown /etc/passwd root root #獲取全部minion主機/etc/passwd的stats信息 [root@salt-master ~]# salt '*' file.stats /etc/passwd #獲取全部minion主機/etc/passwd的權限mode,如755,644 [root@salt-master ~]# salt '*' file.get_mode /etc/passwd #修改全部minion主機/etc/passwd的權限mode爲0644 [root@salt-master ~]# salt '*' file.set_mode /etc/passwd 0644 #在全部minion主機建立/opt/test目錄 [root@salt-master ~]# salt '*' file.mkdir /opt/test #在全部minion主機穿件/tmp/test.conf文件 [root@salt-master ~]# salt '*' file.touch /tmp/test.conf #將全部minion主機/tmp/test.conf文件追加內容'maxclient 100' [root@salt-master ~]# salt '*' file.append /tmp/test.conf 'maxclient 100' #刪除全部minion主機的/tmp/test.conf文件 [root@salt-master ~]# salt '*' file.remove /tmp/test.conf
service模塊
模塊名:service 功能:被控主機程序包服務管理 #開啓(enable)禁用(disable) salt '*' service.enable <service name> salt '*' service.disabled <service name> #reload、restart、start、stop、status操做 salt '*' service.reload <service name> salt '*' service.restart <service name> salt '*' service.start <service name> salt '*' service.stop <service name> salt '*' service.status <service name>