3422饿111111 发表于 2017-2-22 10:44:58

saltstack批量安装zabbix agent

1、准备zabbix agent的配置文件

1
2
3
由于没有啥特别要求,这里我选择yum安装zabbix22-agent
# yum -y install zabbix22-agent
# cp zabbix_agentd.conf /etc/salt/states/init/files/




2、创建zabbix_agent.sls


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# vim /etc/salt/states/init/zabbix_agent.sls
zabbix_agent:
pkg.installed:
    - name: zabbix22-agent
file.managed:
    - name: /etc/zabbix_agentd.conf
    - source: salt://init/files/zabbix_agentd.conf
    - user: root
    - group: root
    - mode: '0644'
service.running:
    - name: zabbix-agent
    - enable: True
    - restart: True
说明:
pkg.installed:安装zabbix22-agent
file.managed: 管理并下发文件
service.running: 管理服务的状态




3、编辑top.sls文件


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# cd /etc/salt/states/
# ls
initprodtop.sls
# cat top.sls
base:
'*':
    - init.pkg
    - init.limit
    - init.ntp-crontab
    - init.hosts
    - init.zabbix_agent
查看文件的目录结构
# tree init/
init/
├── files
│   ├── hosts.conf
│   ├── limits.conf
│   ├── ntp-crontab.conf
│   └── zabbix_agentd.conf
├── hosts.sls
├── limit.sls
├── ntp-crontab.sls
├── pkg.sls
└── zabbix_agent.sls
1 directory, 9 files




4、推送测试


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# salt '*' state.highstate
中间步骤略:
----------
          ID: zabbix_agent
    Function: service.running
      Name: zabbix-agent
      Result: True
   Comment: Service zabbix-agent has been enabled, and is running
   Started: 14:04:45.625235
    Duration: 410.618 ms
   Changes:   
            ----------
            zabbix-agent:
                  True
Summary
------------
Succeeded: 9 (changed=1)
Failed:    0
------------
Total states run:   9




5、在客户端进行测试:

1
2
3
4
5
6
7
8
9
10
# salt '*' cmd.run '/etc/init.d/zabbix-agentd status'
node01.saltstack.com:
    zabbix_agentd (pid6084) is running...
node02.saltstack.com:
    zabbix_agentd (pid5782) is running...
# salt '*' cmd.run "egrep -v '^#|^$' /etc/zabbix_agentd.conf|grep -w Server"
node01.saltstack.com:
    Server=10.10.10.140
node02.saltstack.com:
    Server=10.10.10.140




6、变更zabbix Server后,进行测试与验证


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
如果zabbix server变更了IP地址(由10.10.10.140改为10.10.10.148):
# egrep -v '^#|^$' /etc/salt/states/init/files/zabbix_agentd.conf | grep -w Server
Server=10.10.10.148
推送下,更新服务器的agent ip状态:
# salt '*' state.highstate
----------
          ID: zabbix_agent
    Function: file.managed
      Name: /etc/zabbix_agentd.conf
      Result: True
   Comment: File /etc/zabbix_agentd.conf updated
   Started: 14:22:29.306875
    Duration: 16.102 ms
   Changes:   
            ----------
            diff:
                  ---
                  +++
                  @@ -79,7 +79,7 @@
                   # Server=
                  
                   #Server=127.0.0.1
                  -Server=10.10.10.140
                  +Server=10.10.10.148
                  
                   ### Option: ListenPort
                   #Agent will listen on this port for connections from the server.
----------
Summary
------------
Succeeded: 9 (changed=1)
Failed:    0
------------
Total states run:   9
检查下客户端,看agent的ip地址是否已经调整了:
#salt '*' cmd.run "egrep -v '^#|^$' /etc/zabbix_agentd.conf|grep -w Server"
node01.saltstack.com:
    Server=10.10.10.148
node02.saltstack.com:
    Server=10.10.10.148



页: [1]
查看完整版本: saltstack批量安装zabbix agent