saltstack自动化运维系列③之saltstack的常用模块使用

本文介绍了SaltStack自动化运维中的一些常用模块,包括通过命令行指定主机运行命令,服务的管理如查看、启动和停止服务,以及权限控制模块的使用,如修改目录和日志权限,并详细讲解了如何设置用户权限执行特定命令。
摘要由CSDN通过智能技术生成

saltstack自动化运维系列③之saltstack的常用模块使用

1.命令的常用方法:

指定主机运行命令

# salt 'mini1' cmd.run 'date'
mini1:
Fri Apr 7 14:18:13 CST 2017

指定IP执行命令
# salt -S '192.168.3.19' test.ping
node2.chinasoft.com:
True

# salt -C 'S@192.168.3.19 or G@web:nginx' test.ping
mini1:
True
node2.chinasoft.com:
True

2.服务的管理
# salt '*' service.available sshd
node2.chinasoft.com:
True
mini1:
True

# salt '*' service.get_all

服务的管理:
可参考
https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.service.html#module-salt.modules.service

# salt '*' service.status httpd
node2.chinasoft.com:
True
mini1:
True
[root@mini1 ~]# salt '*' service.stop httpd
node2.chinasoft.com:
True
mini1:
True
[root@mini1 ~]# salt '*' service.status httpd
mini1:
False
node2.chinasoft.com:
False

3.权限控制模块:
可参考:https://docs.saltstack.com/en/latest/ref/publisheracl.html
修改目录权限
# chmod 755 /var/cache/salt /var/cache/salt/master /var/cache/salt/master/jobs /var/run/salt /var/run/salt/master
修改日志权限
# chmod 777 -R /var/log/salt/

# vim /etc/salt/master

client_acl:
jack:
- test.ping
- network.*
tom:
- mini*:
- test.ping

# useradd jack
# useradd tom

可以看到当切换到tom这个用户的时候可以在mini*开头的机器上执行test.ping
su - tom

$ salt 'mini*' 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).
[tom@mini1 ~]$ salt 'mini*' test.ping
mini1:
True

[tom@mini1 ~]$ salt 'mini*' 'w'
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).

切换到jack用户时可以执行test.ping
# su - jack
[jack@mini1 ~]$ salt '*' test.ping
mini1:
True
node2.chinasoft.com:
True

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值