zabbix监控nginx状态
程序员文章站
2022-07-12 19:40:18
...
zabbix监控nginx状态
1 . 部署zabbix
#安装依赖包
[aaa@qq.com ~]# yum -y install wget vim net-snmp-devel libevent-devel
#下载zabbix
[aaa@qq.com ~]# cd /usr/src/
[aaa@qq.com src]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.2.tar.gz
#解压
[aaa@qq.com src]# tar xf zabbix-5.0.2.tar.gz
#创建zabbix用户和组
[aaa@qq.com src]# useradd -r -M -s /sbin/nologin zabbix
#配置zabbix数据库
[aaa@qq.com src]# mysql -uroot -p10063607
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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 statement.
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 aaa@qq.com identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[aaa@qq.com src]# cd zabbix-5.0.2/database/mysql/
[aaa@qq.com mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[aaa@qq.com mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[aaa@qq.com mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
#编译安装zabbix
[aaa@qq.com mysql]# cd /usr/src/zabbix-5.0.2
[aaa@qq.com zabbix-5.0.2]# ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2
[aaa@qq.com zabbix-5.0.2]# make install
# zabbix服务端配置
#修改服务端配置文件、设置数据库信息
[aaa@qq.com zabbix-5.0.2]# cd /usr/local/etc/
[aaa@qq.com etc]# vim zabbix_server.conf
...
DBPassword=zabbix123! //设置zabbix数据库连接密码
...
#启动zabbix_server和zabbix_agentd
[aaa@qq.com etc]# zabbix_server
[aaa@qq.com etc]# zabbix_agentd
[aaa@qq.com etc]# ss -antl|grep -E '10050|10051'
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
配置zabbix服务web界面
#修改/etc/php.ini的配置并重启php-fpm
[aaa@qq.com ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[aaa@qq.com ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[aaa@qq.com ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[aaa@qq.com ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[aaa@qq.com ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[aaa@qq.com ~]# cd /usr/src/zabbix-5.0.2
[aaa@qq.com zabbix-5.0.2]# cp -r ui /usr/local/nginx/html/zabbix
[aaa@qq.com zabbix-5.0.2]# chown -R nginx.nginx /usr/local/nginx/html/zabbix/
#配置nginx虚拟主机
[aaa@qq.com ~]# vim /usr/local/nginx/conf/nginx.conf
...
location / {
root html/zabbix; //这里修改为zabbix的web界面目录
index index.php index.html index.htm;
}
...
location ~ \.php$ {
root html/zabbix; //这里修改为zabbix的web界面目录
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
[aaa@qq.com ~]# chmod 777 /usr/local/nginx/html/zabbix/conf
[aaa@qq.com ~]# nginx -s reload
2 . 配置nginx服务状态页面
[aaa@qq.com ~]# vim /usr/local/nginx/conf/nginx.conf
...
location /status {
stub_status on;
allow 192.168.25.0/24;
deny all;
}
...
[aaa@qq.com ~]# nginx -s reload
#查看
[aaa@qq.com ~]# curl http://192.168.25.131/status
Active connections: 3
server accepts handled requests
16 16 85
Reading: 0 Writing: 1 Waiting: 2
3 . 配置监控脚本
[aaa@qq.com ~]# mkdir /scripts
[aaa@qq.com ~]# vim /scripts/handled.sh
#!/bin/bash
status=$(curl -s http://192.168.25.131/status |awk 'NR==3{print $3}')
echo $status
[aaa@qq.com ~]# vim /scripts/Reading.sh
#!/bin/bash
status=$(curl -s http://192.168.25.131/status |awk 'NR==4{print $2}')
echo $status
[aaa@qq.com ~]# vim /scripts/Writing.sh
#!/bin/bash
status=$(curl -s http://192.168.25.131/status |awk 'NR==4{print $4}')
echo $status
[aaa@qq.com ~]# chmod +x /scripts/*
4 . 配置zabbix_agent文件
[aaa@qq.com ~]# vim /usr/local/etc/zabbix_agentd.conf
...
# Default:
UnsafeUserParameters=1 //将此行取消注释,并将0改为1
...
# Default:
UserParameter=check_handled,/bin/bash /scripts/handled.sh //将此行取消注释,并修改后面的内容
UserParameter=check_Reading,/bin/bash /scripts/Reading.sh
UserParameter=check_Writing,/bin/bash /scripts/Writing.sh
...
[aaa@qq.com ~]# pkill zabbix;zabbix_server;zabbix_agentd
#查看key
[aaa@qq.com ~]# zabbix_get -s 127.0.0.1 -k check_handled
433
[aaa@qq.com ~]# zabbix_get -s 127.0.0.1 -k check_Reading
0
[aaa@qq.com ~]# zabbix_get -s 127.0.0.1 -k check_Writing
1
5 . web界面配置
6 . 查看
上一篇: zabbix监控nginx状态
下一篇: zabbix监控nginx状态
推荐阅读
-
Linux下shell脚本监控Tomcat的状态并实现自动启动的步骤
-
Shell脚本实现监控iptables运行状态
-
Python从ZabbixAPI获取信息及实现Zabbix-API 监控的方法
-
Nginx中配置开启Nginx Status来查看服务器运行状态
-
HTTP 499 状态码 nginx下 499错误的解决办法
-
Percona监控MySQL数据库,配置zabbix-agent和配置MySQL连接教程
-
zabbix自定义监控redis
-
php实现监控varnish缓存服务器的状态
-
以实现MongoDB副本集状态的监控为例,看Telegraf系统中Exec输入插件如何编写部署
-
zabbix--监控MySQL主从状态