nginx监控及lnmp架构

系统级别监控
top
nginx监控及lnmp架构
ps
nginx监控及lnmp架构
netstat
nginx监控及lnmp架构
ss
nginx监控及lnmp架构
日志

配置Nginx状态信息
增加编译参数 --with-http_stub_status_module
配置文件中增加 stub_status on;
https://coding.net/u/aminglinux/p/nginx/git/blob/master/mon/stat.md

配置Nginx状态

Nginx有内置一个状态页,需要在编译的时候指定参数--with-http_stub_status_module参数方可打开。
也就是说,该功能是由http_stub_status_module模块提供,默认没有加载。

Nginx配置文件示例

server{
listen 80;
server_name www.aminglinux.com;

location /status/ {
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    allow 192.168.10.0/24;
    deny all;
}

}

配置说明

location /status/这样当访问/status/时即可访问到状态页内容。
stub_status on即打开了状态页。
access_log off不记录日志
allow和deny只允许指定IP和IP段访问,因为这个页面需要保护起来,并不公开,当然也可以做用户认证。

测试和结果说明

测试命令:curl -x127.0.0.1:80 www.aminglinux.com/status/

结果如下:
Active connections: 1
server accepts handled requests
11 11 11
Reading: 0 Writing: 1 Waiting: 0

说明:
active connections – 活跃的连接数量
server accepts handled requests — 总共处理的连接数、成功创建的握手 次数、总共处理的请求次数
需要注意,一个连接可以有多次请求。
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
nginx的监控我们用来zabbix
nginx监控及lnmp架构

监控图如下
nginx监控及lnmp架构

Nginx架构-LNMP

php-fpm以单独的一个服务存在
Nginx直接处理静态文件
Nginx会把php的请求通过代理的方式交给php-fpm
nginx监控及lnmp架构
LNMP架构搭建
安装MySQL/Mariadb
安装php-fpm
安装Nginx
参考http://www.apelearn.com/study_v2/chapter18.html
配置Nginx和php
https://coding.net/u/aminglinux/p/nginx/git/blob/master/lnmp/nginx_php.md

配置Nginx和php

配置如下(在server部分添加):
location ~ .php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

配置说明:
1 fastcgi_params文件在/usr/local/nginx/conf/下面,其内容为fastcgi相关的变量
2 fastcgi_pass后面跟的是php-fpm服务监听地址,可以是IP:PORT,也可以是unix socket地址,也支持upstream的地址
3 fastcgi_index定义索引页,如果在server内其他部分有定义index参数,该配置可以忽略
4 fastcgi_param这行其实可以在fastcgi_params文件里面定义SCRIPT_FILENAME变量,这个变量如果不定义,php的请求是没办法访问的。
我的监控用的就是lnmp架构的,具体可以查看zabbix的安装过程
nginx监控及lnmp架构

猜你喜欢

转载自blog.51cto.com/865516915/2461621