目录
一、理论
1.Zabbix监控Nginx
(1)环境
zabbix服务端:192.168.204.214
zabbix客户端:192.168.204.215
(2)客户端安装nginx(yum方式)
#安装epel扩展源,然后安装nginx并启动
yum install epel-release -y
yum install nginx -y
systemctl start nginx
systemctl start nginx
#修改nginx主页内容,nginx01修改为nginx01 test,nginx02修改nginx02 test
echo nginx01 test >/usr/share/nginx/html/index.html
(3)编辑nginx子配置文件
#直接在nginx子配置文件夹中创建一个新的子配置文件,因为是yum安装无须在主配置文件中指定子配置文件
vim /etc/nginx/conf.d/upstream.conf
文件内容:
upstream nginxtest{
server 192.168.204.215:8080;
}
#反向代理模块,将2个tomcat的ip和端口号写入其中,反代模块名称为nginxtest
#server模块中的第一个location模块,指定了根为html,支持主页文件类型三个,注意分号结尾
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|css)$ {
root /usr/share/nginx/html;
}
#server模块中第二个location模块,配置不区分大小写的任意开头只要以.()括号内的任意一个内容结尾则为静态资源访问/usr/share/nginx/html下的页面
location ~ .*\.jsp$ {
proxy_pass http://nginxtest;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#server模块中第三个location模块,配置不区分大小写的任意开头只要.jsp结尾就由nginx反向代理模块nginxtest进行处理
在server{}中添加以下内容
ocation /nginx_status
{
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
(3)重载nginx配置
nginx -s reload
(4)测试
curl http://127.0.0.1/nginx_status
Active connections: 1
server accepts handled requests
1 1 1
Reading: 0 Writing: 1 Waiting: 0
nginx状态信息已显示

(5) 添加监控脚本
vim /usr/local/sbin/ngx_status.sh</

本文详细介绍了如何使用Zabbix监控Nginx,包括理论步骤(环境配置、安装Nginx、配置文件编辑等)、实验部署过程以及遇到的问题与解决方案,如重启zabbix客户端、zabbix服务端测试、nginx启动失败和权限不足等。

6990

被折叠的 条评论
为什么被折叠?



