SaltStack遠程執行詳解
●目標(Targeting)
●模塊(Module)
●返回(Returnners)
混合模式-C 選項
主機名設置參照:
redis-node1-redis03-idc04-soa.example.com(電商)
1.1模塊介紹
[root@linux-node1 salt]# salt '*' service.available sshd
linux-node1.zhurui.com:
True
linux-node2.zhurui.com:
True
服務重載:
[root@linux-node1 salt]# salt '*' service.reload httpd
linux-node2.zhurui.com:
True
linux-node1.zhurui.com:
True
服務狀態:
[root@linux-node1 salt]# salt '*' service.status httpd
linux-node1.zhurui.com:
True
linux-node2.zhurui.com:
True
[root@linux-node1 salt]#
1.2network模塊介紹
1.2.1返回tcp狀態
1.2.1在master設置規則容許特定用戶,可以使用的特定方法
[root@linux-node1 salt]# vim /etc/salt/master
245 client_acl:
246 zhurui1:
247 - test.ping
248 - network.
[root@linux-node1 salt]# /etc/init.d/salt-master restart
Stopping salt-master daemon: [ OK ]
Starting salt-master daemon: [ OK ]
[root@linux-node1 salt]# useradd zhurui1 ##建立用戶,而且設置密碼
[root@linux-node1 salt]# echo '123456'|passwd --stdin zhurui1
Changing password for user zhurui.
passwd: all authentication tokens updated successfully.
[root@linux-node1 salt]#
[root@linux-node1 home]# chmod 777 /var/log/salt/master
[root@linux-node1 home]# su - zhurui1
[zhurui1@linux-node1 ~]$ salt '*' test.ping
linux-node2.zhurui.com:
True
linux-node1.zhurui.com:
True
[zhurui1@linux-node1 ~]$
截圖以下:
運行其餘模塊跟方法會報錯,沒有權限
1.2.2 指定特定主機,在特定用戶下容許的操做
client_acl:
zhurui1:
- test.ping
- network.*
user01:
- linux-node1*:
- test.ping
[root@linux-node1 home]# /etc/init.d/salt-master restart
Stopping salt-master daemon: [ OK ]
Starting salt-master daemon: [ OK ]
[root@linux-node1 home]# su - user01
[user01@linux-node1 ~]$ salt '*' test.ping
Failed to authenticate! This is most likely because this user is not permitted to execute commands, but there is a small possibility that a disk error occurred (check disk/inode usage).
[user01@linux-node1 ~]$ salt 'linux-node1*' test.ping
linux-node1.zhurui.com:
True
1.2.3 指定黑名單,禁止特定用戶的操做
開啓以下行: