您的位置:首页 > 大数据 > 人工智能

1.1 salt 常用命令以及 grain pillar

2017-04-12 09:52 309 查看
Saltstack 常用命令
salt 'slaver.test.com' cp.get_file salt://apache.sls /tmp/cp.txt
salt 'slaver.test.com' cp.get_dir salt://test /tmp
salt-run manage.up
salt 'slaver.test.com' cmd.script salt://test/shell.sh
显示存活的客户端

salt
# 更新所有的minion的状态
salt '*' state.highstate

salt-call '192.168.0.100' state.sls webserver

调试Salt
#开启debug日志
salt-minion -l debug

#设置默认超时
salt '*' state.highstate -t 60

salt '*' state.sls apache

使用salt对所有的机器使用state这个模块下的sls方法来执行apache这个状态模块
salt '*' state.highstate
使用高级状态 有一个入口文件默认是top.sls
Grains and Pillar
Grains里面收集了minion启动时候的所有系统信息,存储在minion端。静态数据,只有重启的时候才重新收集
salt 'linux-node1*' grains.ls

主机匹配
salt -G roles:cgt cmd.run 'uptime'
如果你觉得写在配置文件中不方便,可以写在他的一个默认文件中
vim /etc/salt/grains
web:nginx

在top.sls中匹配使用
[root@linux-node1 salt]# cat /srv/salt/top.sls
base:
'os:CentOS':
- match: grain
- apache
[root@linux-node1 salt]# salt '*' state.highstate

Pillar:给minion指定它想要的数据
# 在服务端开启pillar
[root@linux-node1 ~]# vim /etc/salt/master
529 pillar_roots:
530 base:
531 - /srv/pillar
552 pillar_opts: False

cat /srv/pillar/apache.sls
{%if grains['os'] == 'CentOS' %}
apache: httpd
{% elif grains['os'] == 'Debian' %}
apache: apache2
{% endif %}
# 告诉pillar下面哪些主机可以来使用apache.sls文件,这是所有主机*
[root@linux-node1 ~]# cat /srv/pillar/top.sls
base:
'*':
- apache
salt '*' pillar.items
给定标签后
对apache:httpd的minion执行命令
# 刷新pillar,grains是需要重启minion端,pillar是需要刷新
salt '*' saltutil.refresh_pillar
salt -I 'apache:httpd' test.ping

新建用户,且不允许登录
[root@linux-node1 prod]# mkdir user
[root@linux-node1 prod]# cd user/
[root@linux-node1 user]# vim www.sls
www-user-group:
group.present:
- name: www
- gid: 1000
user.present:
- name: www
- fullname: www
- shell: /sbin/nologin
- uid: 1000
- gid: 1000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  salt grain pillar