文章目录
1.环境
主机名 | IP | 安装的服务 |
---|---|---|
zabbix | 192.168.216.188 | zabbix-server zabbix-agentd |
nginx | 192.168.216.215 | nginx zabbix-agentd |
2.确保nginx状态界面打开
[root@nginx ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
// --with-http_stub_status_module为状态界面的模块
修改配置文件见往期文章点此
确保能看到这个页面
3. 在nginx端编写脚本来监控nginx端的状态页面
//这里选择监控Waiting的值
[root@nginx ~]# curl -s 192.168.216.215/status |awk 'NR==4'|awk -F: {'print $4'}
0
3.1 配置从机上的zabbix_agent
//安装zabbix_agent
[root@nginx ~]# yum -y install gcc gcc-c++ bzip2 pcre* make wget
[root@nginx ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.6.tar.gz
[root@nginx ~]# yum -y install gcc gcc-c++ bzip2 pcre* make wget
[root@nginx ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.6.tar.gz
[root@nginx ~]# tar xf zabbix-5.4.6.tar.gz
[root@nginx ~]# useradd -r -M -s /sbin/nologin zabbix
[root@nginx ~]# chown zabbix.zabbix zabbix-5.4.6
[root@nginx ~]# cd zabbix-5.4.6/
[root@nginx zabbix-5.4.6]# ./configure --enable-agent
[root@nginx zabbix-5.4.6]# make install
//修改配置文件
[root@nginx ~]# vim /usr/local/etc/zabbix_agentd.conf
······
Server=192.168.216.188 #修改成zabbix服务端IP
······
ServerActive=192.168.216.188 #修改成zabbix服务端IP
······
Hostname=nginx #主机名
UnsafeUserParameters=1 //添加这行
UserParameter=status,/scripts/status.sh //添加这行指明脚本位置
//编写监控脚本
[root@nginx ~]# mkdir /scripts
[root@nginx ~]# cd /scripts/
[root@nginx scripts]# vim status.sh
[root@nginx scripts]# chmod +x status.sh
[root@nginx scripts]# cat status.sh
#!/bin/bash
status=$(curl -s 192.168.216.215/status |awk 'NR==4'|awk -F: {'print $4'})
if [ $status -ge 1 ];then
echo "1" //如果驻留连接大于等于1就触发报警
else
echo "0"
fi
//开启zabbix
[root@nginx ~]# zabbix_agentd
[root@nginx ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:443 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
//zabbix端测试是否有问题
[root@zabbix ~]# zabbix_get -s 192.168.216.215 -k status
0
//去网页访问,出现变化
[root@zabbix ~]# zabbix_get -s 192.168.216.215 -k status
1
3.2 关闭两端的防火墙和selinux
略
4. web界面配置
同样的办法添加触发器
访问nginx端手动触发