1: 安装agent 的playbook:
---
- hosts: funmall-200
remote_user: root
tasks:
- name: stop zabbix-agent
shell: pkill zabbix
ignore_errors: True
- name: get running app
shell: ps aux |grep java |grep -v grep | awk -F "/" '{print $NF}' | awk -F "." '{print $1}'
register: app
- name: copy zabbix_agent to dest host
copy: src=/home/appsvr/zabbix-agent-3.4.5-1.el7.x86_64.rpm dest=/root
- name: install zabbix_agent
shell: rpm -ivh /root/zabbix-agent-3.4.5-1.el7.x86_64.rpm
ignore_errors: True
- name: backup zabbix_agent config file
shell: cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agent.conf.bak
- name: rm zabbix config
shell: rm -rf /etc/zabbix/zabbix_agentd.conf
- name: set zabbix_agent config file
template: src=/home/appsvr/zabbix_agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf
- name: start zabbix-agent
shell: service zabbix-agent start
2: j2模板文件:
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.16.123.5
ServerActive=172.16.123.5
#Hostname={{ app.stdout }}-{{ ansible_eth0['ipv4']['address'] }}
3: 相关说明:
agent-->proxy-->zabbix-server, 配置文件中的172.16.123.5 为proxy的地址
4: proxy的配置文件:
Server=172.16.252.9
Hostname=funmall-proxy
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=172.16.123.253
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=Pass2018
DBPort=3306
ConfigFrequency=30
StartPollers=30
StartPollersUnreachable=60
StartTrappers=30
StartPingers=10
StartDiscoverers=10
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
CacheSize=1G
Timeout=4
ExternalScripts=/usr/lib/zabbix/externalscripts
FpingLocation=/usr/sbin/fping
LogSlowQueries=3000
其中,172.16.252.9为zabbix-server的地址,"Hostname=funmall-proxy" 中的funmall-proxy的名称,是需要和在zabbix-web中的设置pxory代理是的名称一致的
5: zabbix-web上的配置为:
1; 创建代理:

image.png
2: 创建自动发现规则:

image.png
3: 创建群组:

image.png
4: 创建动作

image.png
动作的详情:

image.png

image.png