zabbix案例--zabbix监控nginx状态
一. 搭建一套LNMP环境:
1. 首先搭建一套LNMP环境,部署discuz论坛用于后面监控案例。搭建一个测试用论坛
1. 配置epel源:
[root@node1 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epo
2>. 安装centos-release-scl源:
[root@node1 ~]# yum install centos-release-scl -y
3>. 部署Inmp环境:
[root@node1 ~]# yum -y install nginx mariadb-serverrh-php72-php rh-php72-php-cli
rh-php72-php-common rh-php72-php-fpm rh-php72-php-gd rh-php72-php-mibstring
rh-php72-php-pdo rh-php72-php-xml rh-php72-php-mysqlnd rh-redis5
sclo-php72-php-pecl-redis5
其中rh-redis5 sclo-php72-php-pecl-redis5 用于redis加速,即缓存功能
4>. 配置php-fpm:
[root@node1 ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/www.conf
......
;user = apache
user = nginx
;group = apache
group = nginx
......
将默认用户apache修改成nginx
5>. 准备论坛代码:
[root@node1 ~]# yum install unzip -y -q
[root@node1 ~]# mkdir/code/discuz-p
论坛代码可到官网下载∶https∶//www.discuz.net/forum-10-1.html
[root@node1 ~]# unzip -q Discuz_X3.4_SC_UTF8.zip -d /code/discuz/
[root@node1 ~]# chown -R nginx:nginx /code/discuz/
6>. 配置论坛首页:
[root@node1 ~]# vim/etc/nginx/conf.d/discuz.conf
server {
listen 80
server_name discuz.xxq.com;
root /code/discuz/upload;
location / {
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
7>. 启动服务:
[root@node1 ~]# systemctl enable nginx,service mariadb,service
rh-php72-php-fpm.service rh-redis5-redis.service --now
8>. 配置论坛用数据库:
[root@node1 ~]# mysql -e "create database discuz character set utf8;"
[root@node1 ~]# mysql -e "grant all on discuz.* to discuz@locathost
identified by '123456';"
9>.配置windows hosts解析:打开C:\Windows\System32\drivers\etc\hosts文件,添加一行:
192.168.188.111 discuz.xxq.com
10>. 登录discuz论坛:
11>. 登录后台,配置redis加速:
修改 config_global.php文件:
[root@node1 ~]# vim /code/discuz/upload/config/config_global.php
.......
$_config['memory']['redis']['server'] = '127.0.0.1';
.......
刷新页面查看是否已经开启:
二. 配置Nginx监控:
Nginx提供了status模块监控内部的运行状态,如需查看当前Nginx是否支持status模块,则可使用nginx-V命令查看是否输出--with stub_status_modules。RPM包安装默认支持,为--with-http_stub_status_module。
1>. 开启Nginx状态数据的配置:
开启Nginx状态数据配置,需要在nginx.conf中添加一个虚拟主机:
[root@node1~]# cat/htc/nginx/conf.d/monitor.conf
server {
listen 127.0.0.1:80;
server_name 127.0.0.1;
location /nginxstatus {
stub_status on;
access_log off;
allow 127.0.0.1;#这里是允许的IP地址
deny all;
}
}
## 检查配置文件语法
[root@node1 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx:
configuration file /etc/nginx/nginx.conf test is successful
## 加载配置
[root@node1 ~]# nginx -s reload
## 访问测试
[rootenode4-]e curl http://127.0.0.1/nginxstatus
Active connections:1
server accepts handled requests
8 8 122
Reading: O writing: 1 waiting: 0
## 各字段的含义
Active connections∶当前活跃的客户端连接数,包括waiting连接数。
accepts∶接受的客户端连接总数。
handled∶已处理的连接总数。通常与“accepts”的值相同,除非达到某些资源限制,如"worker__connections"。
requests∶客户端请求总数,一个客户端连接可能包含多个请求。
Reading∶Nginx正在读取请求标头的当前连接数。
Writing∶Nginx正在将响应写回给客户端的当前连接数。
waiting∶当前等待请求的空闲连接数。
2>. 使用模板监控:
首先将主机上的模板清空:
注意:取消链接:是仅仅将模板取消,而已经套用在主机上的监控项,触发器等仍然生效。
取消链接并清理:会将套用在主机上的应用全部清理干净。
要套用zabbix模板,可以参照官方方法:
zabbix模板:https://www.zabbix.com/integration_search?
主机链接zabbix提供的nginx模板:
修改宏变量,zabbix官网中有要修改的宏变量,将宏变量的值修改为自己配置的值,修改完宏变量后更新即可: