zabbix监控nginx

环境:

主机名IP服务
Sunako192.168.32.129lnmp,zabbix

配置lnmp环境详见文章 lnmp架构

1. 安装zabbix

#安装依赖包
[root@Sunako ~]# yum -y install wget vim gcc gcc-c++ pcre-devel

#下载并解压
[root@Sunako ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.2.tar.gz
[root@Sunako ~]# tar xf zabbix-5.0.2.tar.gz

#创建zabbix用户和组
[root@Sunako ~]# useradd -r -M -s /sbin/nologin zabbix

#配置zabbix数据库
[root@Sunako ~]# mysql -uroot -p123456
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 589
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.05 sec)

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

mysql> flush privileges;
Query OK, 0 rows affected (0.10 sec)

mysql> quit
Bye

[root@Sunako ~]# cd zabbix-5.0.2/database/mysql/
[root@Sunako mysql]# mysql -uzabbix -pzabbix123 zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@Sunako mysql]# mysql -uzabbix -pzabbix123 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@Sunako mysql]# mysql -uzabbix -pzabbix123 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

#编译安装
[root@Sunako zabbix-5.0.2]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
[root@Sunako zabbix-5.0.2]# make install

#配置文件
[root@Sunako zabbix-5.0.2]# cd /usr/local/etc/
[root@Sunako etc]# vim zabbix_server.conf
DBPassword=zabbix123    //设置zabbix数据库连接密码

#启动server和agentd
[root@Sunako ~]# zabbix_server
[root@Sunako ~]# zabbix_agentd 
[root@Sunako ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128              *:10050                        *:*                  
LISTEN      0      128              *:10051                        *:*                  
LISTEN      0      128              *:9000                         *:*                  
LISTEN      0      128              *:80                           *:*                  
LISTEN      0      128              *:22                           *:*                  
LISTEN      0      100      127.0.0.1:25                           *:*                  
LISTEN      0      80              :::3306                        :::*                  
LISTEN      0      128             :::22                          :::*                  
LISTEN      0      100            ::1:25                          :::* 
#修改/etc/php.ini配置
[root@Sunako ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@Sunako ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@Sunako ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@Sunako ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini

#重启php-fpm
[root@Sunako ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
#创建数据存放目录并修改属主
[root@Sunako ~]# cd zabbix-5.0.2
[root@Sunako zabbix-5.0.2]# cp -a ui /usr/local/nginx/html/zabbix
[root@Sunako zabbix-5.0.2]# chown -R nginx.nginx /usr/local/nginx/html/zabbix/

#配置apache虚拟主机
[root@Sunako ~]# 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;
         }
         

#设置权限
[root@Sunako ~]# chmod 777 /usr/local/nginx/html/zabbix/conf
[root@Sunako ~]# ll -d /usr/local/nginx/html/zabbix/conf
drwxrwxrwx 3 nginx nginx 94 Jul  6 17:54 /usr/local/nginx/html/zabbix/conf

#重启服务
[root@Sunako ~]# nginx -s reload
[root@Sunako ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128              *:10050                        *:*                  
LISTEN      0      128              *:10051                        *:*                  
LISTEN      0      128              *:9000                         *:*                  
LISTEN      0      128              *:80                           *:*                  
LISTEN      0      128              *:22                           *:*                  
LISTEN      0      100      127.0.0.1:25                           *:*                  
LISTEN      0      80              :::3306                        :::*                  
LISTEN      0      128             :::22                          :::*                  
LISTEN      0      100            ::1:25                          :::* 

1.1 访问web界面

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

用户名密码
Adminzabbix

恢复zabbix/conf目录的权限为755

[root@Sunako ~]# chmod 755 /usr/local/nginx/html/zabbix/conf
[root@Sunako ~]# ll -d /usr/local/nginx/html/zabbix/conf
drwxr-xr-x 3 nginx nginx 117 Aug 11 11:46 /usr/local/nginx/html/zabbix/conf

1.2 配置nginx服务状态页面

[root@Sunako ~]# vim /usr/local/nginx/conf/nginx.conf
.....
        location /status {
            stub_status on;
            allow 192.168.32.0/24;
            deny all;
        }
.....
[root@Sunako ~]# nginx -s reload
[root@Sunako ~]# curl http://192.168.32.129/status
Active connections: 1 
server accepts handled requests
 95 95 110 
Reading: 0 Writing: 1 Waiting: 0 

在这里插入图片描述

1.3 配置监控脚本

[root@Sunako ~]# mkdir /scripts
[root@Sunako ~]# vim /scripts/handled.sh
#!/bin/bash

status=$(curl -s http://192.168.32.129/status |awk 'NR==3{print $3}')
echo $status
[root@Sunako ~]# vim /scripts/Reading.sh
#!/bin/bash

status=$(curl -s http://192.168.32.129/status |awk 'NR==4{print $2}')
echo $status

[root@Sunako ~]# vim /scripts/Writing.sh
#!/bin/bash

status=$(curl -s http://192.168.32.129/status |awk 'NR==4{print $4}')
echo $status
[root@Sunako ~]# chmod +x /scripts/*
[root@Sunako ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1      //此行取消注释,修改为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@Sunako ~]# zabbix_server 
[root@Sunako ~]# zabbix_agentd 
[root@Sunako ~]# zabbix_get -s 127.0.0.1 -k check_handled
315
[root@Sunako ~]# zabbix_get -s 127.0.0.1 -k check_Reading
0
[root@Sunako ~]# zabbix_get -s 127.0.0.1 -k check_Writing
1

2. web界面配置

2.1 添加监控项

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

2.2 查看数据

在这里插入图片描述

2.2.1 handled

在这里插入图片描述

2.2.2 Reading

在这里插入图片描述

2.2.3 Writing

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值