saltstack syndic安装配置使用
# pwd # 我们在master上定义top/srv/salt/base
# cat top.sls # 其实就是给大家传输了个文件
base:
'*':
- known-hosts.known-hosts
# cat known-hosts/known-hosts.sls
known-hosts:
file.managed:
- name: /root/.ssh/known_hosts
- source: salt://known-hosts/templates/known-hosts
- clean: True
# salt '*' state.highstate
linux-node3.example.com:
----------
>
Function: no.None
Result: False
Comment: No Top file or master_tops data matches found.
Changes:
Summary for linux-node3.example.com
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 0.000 ms
linux-node2.example.com:
----------
>
Function: file.managed
Name: /root/.ssh/known_hosts
Result: True
Comment: File /root/.ssh/known_hosts updated
Started: 11:15:35.210699
Duration: 37.978 ms
Changes:
----------
diff:
New file
mode:
0644
Summary for linux-node2.example.com
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time:37.978 ms
linux-node1.example.com:
----------
>
Function: file.managed
Name: /root/.ssh/known_hosts
Result: True
Comment: File /root/.ssh/known_hosts is in the correct state
Started: 11:15:35.226119
Duration: 51.202 ms
Changes:
Summary for linux-node1.example.com
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time:51.202 ms
ERROR: Minions returned with non-zero exit code
显而易见的node3发生了错误,而node1跟node2正常(很好理解),我们去看node3报出的“No Top file or master_tops data matches found”,言简意赅没有找到匹配的top执行文件,简单推断出是因为node3认证的master是node2,但是node2上没有写top,我们去node2上写一个不同的top再次测试下
# pwd
/srv/salt/base
# cat top.sls # 这个更简单了,就是ls /root
base:
'*':
- cmd.cmd
# cat cmd/cmd.sls
cmd:
cmd.run:
- name: ls /root
好的我们回到master上再次测试,我将node1、2正常执行的信息省略
# salt '*' state.highstate
linux-node3.example.com:
----------
>
Function: cmd.run
Name: ls /root
Result: True
Comment: Command "ls /root" run
Started: 11:24:42.752326
Duration: 11.944 ms
Changes:
----------
pid:
5095
retcode:
0
stderr:
stdout:
lvs.sh
Summary for linux-node3.example.com
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time:11.944 ms
我们已经可以看出一些端倪,我们再次修改master的配置文件并执行测试
# cat top.sls
base:
'linux-node3.example.com': # 只定义执行node3
- known-hosts.known-hosts
# salt '*' state.highstate
linux-node3.example.com:
----------
>
Function: cmd.run
Name: ls /root
Result: True
Comment: Command "ls /root" run
Started: 11:28:20.792475
Duration: 8.686 ms
Changes:
----------
pid:
5283
retcode:
0
stderr:
stdout:
lvs.sh
Summary for linux-node3.example.com
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 8.686 ms
linux-node2.example.com:
----------
>
Function: no.None
Result: False
Comment: No Top file or master_tops data matches found.
Changes:
Summary for linux-node2.example.com
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 0.000 ms
linux-node1.example.com:
----------
>
Function: no.None
Result: False
Comment: No Top file or master_tops data matches found.
Changes:
Summary for linux-node1.example.com
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 0.000 ms
ERROR: Minions returned with non-zero exit code
我们发现这次node1跟node2出刚才问题了,而node3执行的是node2上定义的top,好吧,这时候就要发挥小北方的作用!
北方的总结:
每个minion会去找自己master里定义的top并执行,即node1、2找的是master的,而node2找的是syndic(node2)的
“No Top file or master_tops data matches found”出现是因为我每次执行都是salt '*' state.highstate,即让所有机器都查找top文件并执行对应操作,第一次node3出现问题是因为它听从的top文件在syndic上,当时syndic上我还没有写top所以他找不到匹配自己的;第二次我把top里执行的*换成了node3单独一个,没有node1跟node2的相关操作了,他们接受到指令并来查找top文件想执行相关操作发现没匹配自己也因此报错,就跟刚才node3找不到是一个意思
一下子还是无法理解呢,那么怎么办呢,有一个规范的做法就是,将master的文件目录直接拷到所有的syndic上,这样就可以保证所有的操作都是统一的了,如同没有代理的时候一样
页:
[1]