状态页面信息详解:
状态码 | 表示的意义 |
---|---|
Active connections 2 | 当前所有处于打开状态的连接数 |
accepts | 总共处理了多少个连接 |
handled | 成功创建多少握手 |
requests | 总共处理了多少个请求 |
Reading | nginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数 |
Writing | nginx返回给客户端的Header信息数,表示请求已经接收完成,且正处于处理请求或发送响应的过程中的连接数 |
Waiting | 开启keep-alive的情况下,这个值等于active - (reading + writing),意思就是Nginx已处理完正在等候下一次请求指令的驻留连接 |
部署
主机名 | IP | 服务 |
---|---|---|
wyt1 | 192.168.179.128 | lnmp,zabbix |
zabbix搭建
先安装lnmp详见文章lnmp部署
安装依赖包
[root@wyt1 ~]# yum -y install net-snmp-devel libevent-devel
下载zabbix与解压
[root@wyt1 ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.1.tar.gz
[root@wangyitong ~]# ls
anaconda-ks.cfg lamp zabbix-5.0.1.tar.gz
[root@wyt1 ~]# tar xf zabbix-5.0.1.tar.gz
创建zabbix用户和组
[root@wyt1 ~]# useradd -r -M -s /sbin/nologin zabbix
配置zabbix数据库
[root@wyt1 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be inre.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserv
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input state.
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123';
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye
[root@wyt1 ~]# cd zabbix-5.0.1/database/mysql/
[root@wyt1 mysql]# ls
data.sql double.sql images.sql Makefile.am Makefile.in schema.sql
[root@wyt1 mysql]# mysql -uzabbix -pzabbix123 zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@wyt1 mysql]# mysql -uzabbix -pzabbix123 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@wyt1 mysql]# mysql -uzabbix -pzabbix123 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
编译安装zabbix
[root@wyt1 mysql]# cd zabbix-5.0.1
[root@wyt1 zabbix-5.0.1]# ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2
....
[root@wyt1 zabbix-5.0.1]# make install
zabbix服务端配置
[root@wyt1 zabbix-5.0.1]# cd /usr/local/etc/
[root@wyt1 etc]# ls
zabbix_agentd.conf zabbix_server.conf
zabbix_agentd.conf.d zabbix_server.conf.d
[root@wyt1 etc]# vim zabbix_server.conf
DBPassword=zabbix123 //设置zabbix数据库连接密码
启动zabbix_server和zabbix_agentd
[root@wyt1 ~]# zabbix_server
[root@wyt1 ~]# zabbix_agentd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
zabbix web界面安装前配置
修改/etc/php.ini的配置并重启php-fpm
[root@wyt1 ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@wyt1 ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@wyt1 ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@wyt1 ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@wyt1 ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
创建数据存放目录并修改目录属主和属组
[root@wyt1 ~]# cd zabbix-5.0.1
[root@wyt1 zabbix-5.0.1]# cp -a ui /usr/local/nginx/html/zabbix
[root@wyt1 zabbix-5.0.1]# chown -R nginx.nginx /usr/local/nginx/html/zabbix/
配置apache虚拟主机
[root@wyt1 ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root html/zabbix; //添加zabbix
index index.php index.html index.htm;
location ~ \.php$ {
root html/zabbix; //添加zabbix
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@wyt1 ~]# chmod 777 /usr/local/nginx/html/zabbix/conf
[root@wyt1 ~]# ll -d /usr/local/nginx/html/zabbix/conf
drwxrwxrwx 3 nginx nginx 94 5月 25 20:15 /usr/local/nginx/html/zabbix/conf
重载配置文件
[root@wyt1 ~]# nginx -s reload
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 *:9000 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 80 [::]:3306 [::]:*
LISTEN 0 128 [::]:22 [::]:*
访问web界面
恢复zabbix/conf目录的权限为755
[root@wyt1 ~]# chmod 755 /usr/local/nginx/html/zabbix/conf
[root@wyt1 ~]# ll -d /usr/local/nginx/html/zabbix/conf
drwxr-xr-x 3 nginx nginx 117 8月 11 11:44 /usr/local/nginx/html/zabbix/conf
开启状态界面
[root@wyt1 ~]# vim /usr/local/nginx/conf/nginx.conf
location /status {
stub_status on;
allow 192.168.179.0/24;
deny all;
}
访问
配置监控脚本取出想要的数据
[root@wyt1 ~]# mkdir /scripts
[root@wyt1 scripts]# ls
handled.sh Reading.sh Writing.sh
[root@wyt1 scripts]# cat handled.sh
#!/bin/bash
status=$(curl -s http://192.168.179.128/status|awk 'NR==3{print $3}')
echo $status
[root@wyt1 scripts]# cat
handled.sh Reading.sh Writing.sh
[root@wyt1 scripts]# cat Reading.sh
#!/bin/bash
status=$(curl -s http://192.168.179.128/status|awk 'NR==4{print $2}')
echo $status
[root@wyt1 scripts]# cat Writing.sh
#!/bin/bash
status=$(curl -s http://192.168.179.128/status|awk 'NR==4{print $4}')
echo $status
[root@wyt1 scripts]# chmod +x *
启用自定义脚本监控功能
//添加下列三行
UnsafeUserParameters=1
UserParameter=check_handled,/bin/bash /scripts/handled.sh
UserParameter=check_Reading,/bin/bash /scripts/Reading.sh
UserParameter=check_Writing,/bin/bash /scripts/Writing.sh
重启服务
[root@wyt1 ~]# zabbix_server
[root@wyt1 ~]# zabbix_agentd
[root@wyt1 ~]# zabbix_get -s 127.0.0.1 -k check_handled //测试脚本能否取出值
296
[root@wyt1 ~]# zabbix_get -s 127.0.0.1 -k check_Reading
0
[root@wyt1 ~]# zabbix_get -s 127.0.0.1 -k check_Writing
1
web界面配置
添加监控项
查看handled数据
查看Reading数据
查看Writing数据