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 指定黑名单,禁止特定用户的操做
开启以下行: