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

news/2024/7/7 16:11:23

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

转载于:https://www.cnblogs.com/reblue520/p/6732865.html


http://www.niftyadmin.cn/n/4289873.html

相关文章

解决终端xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun 出现这个问题 和更新了系统有关系 一行代码解决 终端下 进行安装即可 xcode-select --install

行家解疑:BT下载到底伤不伤硬盘?

为什么频繁读写会损坏硬盘呢?磁头寿命是有限的&#xff0c;频繁的读写会加快磁头臂及磁头电机的磨损&#xff0c;频繁的读写磁盘某个区域更会使 <script language"JavaScript1.1" src"http://ad.ccw.com.cn/adshow.asp?positionID35&js1&innerJs1&…

neo4j使用问题总结

2019独角兽企业重金招聘Python工程师标准>>> 问题&#xff1a;linux启动时报错 &#xff1a;WARNING: Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual. 解决&#xff1a;https://my.oschina.net/sunyouling/blog/886051 问题&am…

解决element中Radio 单选框无法选中的问题

定义了数据没办法被选中 因为后台要数据类型 所以 <el-form-item label"运营商"> <el-radio v-model"ruleForm.source" :label"1">电信</el-radio> <el-radio v-model"ruleForm.source" :label"2">…

对比软件艺术与个人素质

就当我是在夸夸其谈吧&#xff0c;现在我要谈的是软件艺术和个人素质间的隐含关系。 软件&#xff0c;其实是门艺术。它需要能工巧匠精心雕刻&#xff0c;同其它手工艺品一样&#xff0c;它也需要用“心”呵护。手艺的好坏直接影响到它的成败&#xff0c;而雕琢这件艺术品的巧匠…

oracle多实例的启动与关闭

Oracle/oracle登录 1、启监听器 lsnrctl start 监听一般不需要动&#xff0c;如果机器重新启动的话需要将监听启动。 查看当前SID:echo $ORACLE_SID 2、启动数据库实例&#xff1a; 设置需要操作的实例&#xff1a;export ORACLE_SIDa&#xff08;需要启动的实例&#xff09; 进…

element多选框select下拉框数据回显的问题value.push is not a function

昨天弄了一下午 才解决这个问题 选择这个省份是下拉框 我传入的是省份的编号 因为数据库mysql是int结构 所以传过来的是个字符串 那么大家可能会遇到这个问题 数据不回显的问题 昨天一天都在搞这个 我之前做过的 新建的时候根据省份编号存进去 编辑的时候 根据编号显示对应的…

手动配置 Linux 路由器

2019独角兽企业重金招聘Python工程师标准>>> Linux 系统的机器很简单就可以配置为路由器&#xff0c;使内网的其他机器能通过该机器连接到其他网络&#xff08;如公网&#xff09;。 首先要允许 IP 转发&#xff1a; 编辑 /etc/sysctl.conf 文件&#xff0c;添加一行…