实验环境
-
zabbix-server:
-
centos 7
-
192.168.14.216
-
-
nginx
-
centos7
-
192.168.14.210
介绍:
zabbix默认带有两个nginx的模板,可以直接链接模板使用。本文主要介绍根据实际情况自定义一些监控选项
一、Nginx(192.168.14.210)
1、安装
-
#配置epel源
-
[root@nginx ~]# vi /etc/yum.repos.d/epel.repo
-
[nginx]
-
name=aliyun epel
-
baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/
-
gpgcheck=0
-
#安装nginx
-
[root@nginx ~]# yum install -y nginx
-
#安装zabbix-agent
-
[root@nginx ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
-
[root@nginx ~]# yum install -y zabbix-agent
2、修改nginx配置文件,为了不影响默认/,添加新的/status
-
~]# vim /etc/nginx/nginx.conf
-
location /status {
-
stub_status on;
-
access_log off;
-
allow 127.0.0.1;
-
deny all;
-
}
3、查看监控内容
Active connections:当前所有处于打开状态的活动连接数(TCP连接数,即三次握手四次挥手次数)
accepts :已经接收连接数
handled : 已经处理过的连接数
requests : 已经处理过的请求数,在保持连接模式下,请求数量可能会大于连接数量
Reading: 正处于接收请求的连接数
Writing: 请求已经接收完成,处于响应过程的连接数
Waiting : 保持连接模式,处于活动状态的连接数
4、添加nginx监控选项
-
#拷贝自带的mysql配置文件并修改为nginx
-
[root@nginx ~]# cd /etc/zabbix/zabbix_agentd.d/
-
[root@nginx zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf
-
-
#删除有关mysql数据,添加nginx监控选项
-
[root@nginx zabbix_agentd.d]# vi userparameter_nginx.conf
-
UserParameter=nginx.active,curl -s http://127.0.0.1/status 2>/dev/null| grep ‘Active’ | awk ‘{print $NF}’
-
UserParameter=nginx.reading,curl -s http://127.0.0.1/status 2>/dev/null| grep ‘Reading’ | awk ‘{print $2}’
-
UserParameter=nginx.writing,curl -s http://127.0.0.1/status 2>/dev/null| grep ‘Writing’ | awk ‘{print $4}’
-
UserParameter=nginx.waiting,curl -s http://127.0.0.1/status 2>/dev/null| grep ‘Waiting’ | awk ‘{print $6}’
-
UserParameter=nginx.accepts,curl -s http://127.0.0.1/status 2>/dev/null| awk NR==3 | awk ‘{print $1}’
-
UserParameter=nginx.handled,curl -s http://127.0.0.1/status 2>/dev/null| awk NR==3 | awk ‘{print $2}’
-
UserParameter=nginx.requests,curl -s http://127.0.0.1/status 2>/dev/null| awk NR==3 | awk ‘{print $3}’
5、开启服务
-
[root@nginx ~]# systemctl start nginx
-
[root@nginx ~]# systemctl start zabbix-agent
6、防火墙允许端口访问
-
[root@nginx ~]# firewall-cmd –permanent –zone=public –add-port=80/tcp
-
[root@nginx ~]# firewall-cmd –permanent –zone=public –add-port=10050/tcp
-
[root@nginx ~]# firewall-cmd –reload
二、zabbix-server(192.168.14.216)
1、检查是否安装zabbi_get
-
[root@zabbix_server ~]# docker ps -a
-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-
e2e2a132cd5d zabbix/zabbix-agent:centos-latest “/sbin/tini — /usr/…” 25 hours ago Up 25 hours zabbix_zabbix-agent_1
-
f1e1da5d9083 zabbix/zabbix-web-apache-mysql:centos-latest “docker-entrypoint.sh” 25 hours ago Up 25 hours (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp zabbix_zabbix-web-apache-mysql_1
-
f96412915d59 zabbix/zabbix-server-mysql:centos-latest “/sbin/tini — /usr/…” 25 hours ago Up 25 hours 0.0.0.0:10051->10051/tcp zabbix_zabbix-server_1
-
dd4a1123fa5d mysql:5.7 “docker-entrypoint.s…” 30 hours ago Up 25 hours zabbix_mysql-server_1
-
9a4c101679e2 zabbix/zabbix-snmptraps:centos-latest “/usr/bin/supervisor…” 30 hours ago Up 25 hours 0.0.0.0:162->162/udp zabbix_zabbix-snmptraps_1
-
[root@zabbix_server ~]# docker exec -it zabbix_zabbix-server_1 /bin/bash
-
[root@f96412915d59 zabbix]# zabbix_get -s 192.168.14.210 -p 10050 -k ‘nginx.active’
-
1
2、添加监控选项(依次创建七个监控选项)
3、查看创建
4、创建图形
5、添加图形监控项
6、查看图形结果