salt数据同步方式
方式一:
minion自动向master进行数据同步:
默认是60秒自动同步一次数据
自动同步时间间隔由参数loop_interval来决定(minion端)
[[email protected] salt]# grep loop_interval /etc/salt/minion
# The loop_interval sets how long in seconds the minion will wait between
#loop_interval: 60
如果我们想让minion永远不要自动同步,可以把这个参数值改大一点
loop_interval: 3153600000 (设置100年同步一次)
方式二:
master端通过执行命令进行数据同步:
测试配置是否正确,并没有真正的推送数据:
salt ‘*‘ state.highstate -v test
salt ‘*‘ state.highstate -v test=true
salt ‘*‘ state.highstate -v test=True
向所有minion推送所有数据:
salt ‘*‘ state.highstate
向某一台minion推送所有数据:
salt ‘192.168.186.129‘ state.highstate
向某一个分组推送所有数据:
salt -N ‘BJwebgroup‘ state.highstate
向所有minion只推送web这个模板目录的数据
salt ‘*‘ state.sls web
注意:
[[email protected] salt]# cat top.sls
base:
‘BJwebgroup‘:
- match: nodegroup
- web
向所有minion只推送web模板下面的httpd.sls文件:
salt ‘*‘ state.sls web.httpd
注意:
[[email protected] web]# pwd
/srv/salt/web
[[email protected] web]# ls
files httpd.sls init.sls
向所有minion只推送web模板下面php目录下面的conf.sls文件:
salt ‘*‘ state.sls web.php.conf
注意:
[[email protected] php]# pwd
/srv/salt/web/php
[[email protected] php]# ls
conf.sls
附加:
salt常用命令:
salt ‘*‘ grains.ls 查看grains分类
salt ‘*‘ grains.items 查看grains所有信息
salt ‘*‘ grains.item os 查看grains某个信息
salt ‘*‘ pillar.items 查看pillar所有信息
salt ‘*‘ pillar.item users 查看pillar某个信息
[[email protected] salt]# salt ‘*‘ grains.item os
192.168.186.129:
----------
os:
CentOS
[[email protected] salt]# salt ‘*‘ grains.item fqdn
192.168.186.129:
----------
fqdn:
scj.51.com
[[email protected] salt]# salt ‘*‘ grains.item host
192.168.186.129:
----------
host:
scj
salt ‘匹配正则‘ state.highstate 匹配正则
[[email protected] salt]# salt ‘*‘ state.highstate
salt -N ‘GroupName‘ state.highstate 指定某个组
[[email protected] salt]#salt -N ‘BJwebgroup‘ state.highstate
salt -L ‘minion1,minion2,minion3‘ state.highstate 指定多个minion
[[email protected] salt]# salt -L ‘192.168.186.129,192.168.186.128‘ state.sls web.php.conf