0、学习目的
http://docs.saltstack.cn/topics/execution/index.html 官方文档
0.1 命令解释
[root@host-192-168-23-39 ~]# salt '*' cmd.run 'w' salt 命令 * 指定目标 cmd 模块 run 模块的方法 w 模块的参数
0.2 学习目的
1、目标Target
Targets也可以使用正则表达式: salt -E 'virtmach[0-9]' test.ping Targets也可以指定列表: salt -L 'foo,bar,baz,quo' test.ping
# Ip地址
# 或者在一个命令中混合使用多target类型:
2、模块Module
http://docs.saltstack.cn/ref/modules/all/index.html#all-salt-modules
2.1 network模块
# 活动的tcp
# 查看arp
# 查看网卡接口
# 测试连接性
salt '*' network.connect archlinux.org 80 salt '*' network.connect baidu.com 80
2.2 service
salt '*' service.get_all salt '*' service.get_all |grep sshd
# 服务开启着
# 获取所有服务
# 服务是否关闭
# 重新加载,重启,状态
# 停止服务
2.3 state模块
https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.state.html
2.4 file模块
批量文件分发
# cp文件目录 [root@linux-node1 salt]# salt-cp '*' /etc/passwd /tmp/hehe {'linux-node1.example.com': {'/tmp/hehe': True}, 'linux-node2.example.com': {'/tmp/hehe': True}} # ls [root@linux-node1 salt]# salt \* cmd.run 'ls /tmp/hehe' linux-node1.example.com: /tmp/hehe linux-node2.example.com: /tmp/hehe
2.5 模块用户访问控制
http://docs.saltstack.cn/topics/eauth/access_control.html
1. 要求:redhat用户只能用这两个模块
2.[root@master ~]# vim /etc/salt/master
重启master服务
3.PERMISSION授权
[root@master ~]# chmod 775 /var/cache/salt /var/cache/salt/master /var/cache/salt/master/jobs /var/run/salt /var/run/salt/master
4. 创建redhat用户,切换用户,执行命令
[root@linux-node1 ~]# useradd redhat
[root@linux-node1 ~]# passwd redhat
5. 只在某个机器执行
6.问题:
错误,表明用户没有写log权限,
解决方式:
把test用户加到root用户组,
并对root用户组赋予/var/log/salt/master 文件的写权限
3
4