saltstack搭建叢集3

weixin_34026276發表於2017-11-12

系統初始化模組--------------zabbix-agent


在配置檔案裡設定pillar路徑

1
2
3
4
5
[root@node1 init]# vim /etc/salt/master
pillar_roots:
  base:
- /srv/pillar/base
[root@node1 init]# /etc/init.d/salt-master restart

 

pillar裡建立top.slszabbix.sls

1
2
3
4
5
6
7
8
9
10
[root@node1 init]# mkdir /srv/pillar/base
[root@node1 pillar]# cd base/
[root@node1 base]# cat top.sls
base:
  '*':
- zabbix
  
[root@node1 base]# cat zabbix.sls
zabbix-agent:
  Zabbix_Server: 192.168.10.129
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@node1 init]# cd /srv/salt/base/init/
[root@node1 init]# cat zabbix_agent.sls
zabbix-agent-install:
  pkg.installed:
    - name: zabbix-agent
  file.managed:
    - name: /etc/zabbix/zabbix_agentd.conf
    - source: salt://init/files/zabbix_agentd.conf
    - template: jinja
    - defaults:
      Server: {{ pillar['zabbix-agent']['Zabbix_Server'] }}  #這裡將pillar裡ID為zabbix-agent,Zabbix_Server的值賦給變數Server
    - require:
      - pkg: zabbix-agent-install
  service.running:
    - name: zabbix-agent
    - enable: True
    - watch:
      - pkg: zabbix-agent-install
      - file: zabbix-agent-install

編寫配置檔案利用jinjaServer變數的值傳給Server,也就是指定zabbix-Server地址

1
2
3
cp /etc/zabbix/zabbix_agentd.conf /srv/salt/base/init/files/
[root@node1 base]#vim /srv/salt/base/init/files/zabbix_agent.conf
Server=`Server`

zabbix_agent.sls includeenv_init.sls

1
2
3
4
5
6
7
8
9
[root@node1 init]# cat env_init.sls
include:
  - init.dns
  - init.history
  - init.audit
  - init.sysctl
  - init.zabbix_agent
  
[root@node1 init]# salt '*' state.highstate




本文轉自 fxl風 51CTO部落格,原文連結:http://blog.51cto.com/fengxiaoli/1958159

相關文章