Zabbix监控Nginx连接状态

在lnmp安装zabbix
//解压
[root@localhost ~]# tar xf zabbix-5.2.0.tar.gz 

[root@localhost ~]# ls
anaconda-ks.cfg
zabbix-5.2.0
zabbix-5.2.0.tar.gz

//安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel


//创建zabbix用户
[root@localhost ~]# useradd  -r -M -s /sbin/nologin zabbix
//配置zabbix数据库
创建数据库
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

//授权
mysql>  grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123';
Query OK, 0 rows affected, 2 warnings (0.00 sec)

//刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)


[root@localhost zabbix-5.2.0]# cd database/
[root@localhost database]# ls
elasticsearch  Makefile.in  oracle      sqlite3
Makefile.am    mysql        postgresql
[root@localhost database]# cd mysql/
[root@localhost mysql]# pwd
/root/zabbix-5.2.0/database/mysql
[root@localhost mysql]# ll
total 10232
-rw-r--r-- 1 1000 1000 8308118 Oct 26 23:44 data.sql
-rw-r--r-- 1 1000 1000     282 Oct 26 19:18 double.sql
-rw-r--r-- 1 1000 1000 1978341 May 11 01:36 images.sql
-rw-r--r-- 1 1000 1000     482 Oct 26 19:18 Makefile.am
-rw-r--r-- 1 1000 1000   15982 Oct 26 23:44 Makefile.in
-rw-r--r-- 1 1000 1000  160579 Oct 26 23:44 schema.sql
[root@localhost mysql]# 



[root@localhost mysql]# mysql -uzabbix  -p'zabbix123' zabbix  < schema.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@localhost mysql]# mysql -uzabbix  -p'zabbix123' zabbix  < images.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@localhost mysql]# mysql -uzabbix  -p'zabbix123' zabbix  <data.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.


[root@localhost zabbix-5.2.0] ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2

[root@localhost ~]#  make install 


//修改服务端配置文件及修改
[root@localhost ~]# ls /usr/local/etc/
zabbix_agentd.conf    zabbix_server.conf
zabbix_agentd.conf.d  zabbix_server.conf.d
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
DBPassword=zabbix123456   //找到此行,取消注释,写上数据库授权密码

//修改/etc/php.ini的配置并重启php-fpm
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# 

//重启
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@localhost ~]# 

zabbix网页配置

//修改nginx配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

        location /zabbix {          //添加zabbix监控页面
            root   /usr/local/nginx/html/;
            index  index.php index.html index.htm;
        }
[root@localhost ]# nginx -s reload

//修改zabbix配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
//开启自定义监控,取消注释,改值为1
UnsafeUserParameters=1     

//追加自定义监控的参数内容
 UserParameter=check_status[*],/bin/bash /root/nginx_status.sh $1

//iu为前端网页放置的目录
[root@localhost ~]# cd zabbix-5.2.0
[root@localhost zabbix-5.2.0]# mkdir /usr/local/nginx/html/zabbix
[root@localhost zabbix-5.2.0]# cp -a ui/* /usr/local/nginx/html/zabbix

[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html  index.html  index.php  zabbix
[root@localhost html]# chown zabbix.zabbix zabbix/
[root@localhost zabbix]# chmod 777 /usr/local/nginx/html/zabbix/conf


//启动服务
[root@localhost ~]# zabbix_server 
[root@localhost ~]# zabbix_agentd 
[root@localhost ~]# ss -antl
State   Recv-Q   Send-Q     Local Address:Port                   Peer Address:Port                
LISTEN  0        128              0.0.0.0:10050                       0.0.0.0:*                   
LISTEN  0        128            127.0.0.1:9000                        0.0.0.0:*                   
LISTEN  0        128              0.0.0.0:80                          0.0.0.0:*                   
LISTEN  0        128              0.0.0.0:22                          0.0.0.0:*                   
LISTEN  0        80                     *:3306                              *:*                   
LISTEN  0        128                 [::]:22                             [::]:*   
检测Nginx模块

Nginx性能监控需要ngx_http_stub_status_module模块来收集指标: 1)检测是否编译ngx_http_stub_status_module模块

[root@localhost ~]# nginx -V
nginx version: nginx/1.18.0
built by gcc 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC) 
built with OpenSSL 1.1.1g FIPS  21 Apr 2020
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 --add-module=../echo-nginx-module-master

如果未启用ngx_http_stub_status_module模块则平滑升级

2.Nginx配置文件添加模块配置

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

 location /ngx_status {
            stub_status on; #开启stub_status模块
            allow 127.0.0.1/8;  #只允许127.0.0.1本地访问
            deny all;  #除了以上允许127.0.0.1以外,拒绝所有地址访问
      
        }
//重读配置文件
[root@localhost ~]# nginx -s reload

通过网页访问stub_statub模块
在这里插入图片描述
访问stub_statub模块

[root@localhost ~]# curl http://127.0.0.1/status
Active connections: 1 
server accepts handled requests
 12 12 8 
Reading: 0 Writing: 1 Waiting: 0 

编写Nginx监控脚本

编写监控脚本

//编写监控脚本
vim /usr/local/zabbix/scripts/ngx_status.sh


[root@localhost ~]# cat nginx_status.sh 
#!/bin/bash
#本机IP
host="192.168.152.135"

function active {
    curl -s http://$host/status |awk 'NR==1{print $3}'
}
function Reading {
    curl -s http://$host/status |awk 'NR==4{print $2}'
}
function Writing {
    curl -s http://$host/status |awk 'NR==4{print $4}'
}
function Waiting {
    curl -s http://$host/status |awk 'NR==4{print $6}'
}
function accepts {
    curl -s http://$host/status |awk 'NR==3{print $1}'
}
function handled {
    curl -s http://$host/status |awk 'NR==3{print $2}'
}
function requests {
    curl -s http://$host/status |awk 'NR==3{print $3}'
}

$1
[root@localhost ~]# chmod +x nginx_status.sh

1.添加监控项
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2.添加触发器
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值