概述
在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.添加触发器
最后
以上就是花痴镜子为你收集整理的Zabbix监控Nginx连接状态的全部内容,希望文章能够帮你解决Zabbix监控Nginx连接状态所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复