Skip to content

Commit 41e54c0

Browse files
committed
2018-01-29 补充 nginx 监控
1 parent 1baa2b1 commit 41e54c0

File tree

1 file changed

+67
-15
lines changed

1 file changed

+67
-15
lines changed

Nginx-Install-And-Settings.md

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@
6969
- 进入解压后目录:`cd nginx-1.8.1/`
7070
- 编译配置:
7171

72-
``` ini
73-
./configure \
74-
--prefix=/usr/local/nginx \
75-
--pid-path=/var/local/nginx/nginx.pid \
76-
--lock-path=/var/lock/nginx/nginx.lock \
77-
--error-log-path=/var/log/nginx/error.log \
78-
--http-log-path=/var/log/nginx/access.log \
79-
--with-http_gzip_static_module \
80-
--http-client-body-temp-path=/var/temp/nginx/client \
81-
--http-proxy-temp-path=/var/temp/nginx/proxy \
82-
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
83-
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
84-
--with-http_ssl_module \
85-
--http-scgi-temp-path=/var/temp/nginx/scgi
86-
```
72+
``` ini
73+
./configure \
74+
--prefix=/usr/local/nginx \
75+
--pid-path=/var/local/nginx/nginx.pid \
76+
--lock-path=/var/lock/nginx/nginx.lock \
77+
--error-log-path=/var/log/nginx/error.log \
78+
--http-log-path=/var/log/nginx/access.log \
79+
--with-http_gzip_static_module \
80+
--http-client-body-temp-path=/var/temp/nginx/client \
81+
--http-proxy-temp-path=/var/temp/nginx/proxy \
82+
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
83+
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
84+
--with-http_ssl_module \
85+
--http-scgi-temp-path=/var/temp/nginx/scgi
86+
```
8787

8888
- 编译:`make`
8989
- 安装:`make install`
@@ -498,6 +498,57 @@ http {
498498
```
499499

500500

501+
## Nginx 监控模块
502+
503+
- 如果你需要监控 nginx 情况可以安装的加入这个模块 http_stub_status_module:
504+
505+
``` ini
506+
./configure \
507+
--prefix=/usr/local/nginx \
508+
--pid-path=/var/local/nginx/nginx.pid \
509+
--lock-path=/var/lock/nginx/nginx.lock \
510+
--error-log-path=/var/log/nginx/error.log \
511+
--http-log-path=/var/log/nginx/access.log \
512+
--with-http_gzip_static_module \
513+
--http-client-body-temp-path=/var/temp/nginx/client \
514+
--http-proxy-temp-path=/var/temp/nginx/proxy \
515+
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
516+
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
517+
--with-http_ssl_module \
518+
--http-scgi-temp-path=/var/temp/nginx/scgi \
519+
--with-http_stub_status_module
520+
```
521+
522+
- 然后在 nginx.conf 文件的 location 区域增加:stub_status on;
523+
524+
525+
```ini
526+
location /nginx_status {
527+
#allow 192.168.1.100;
528+
#deny all;
529+
stub_status on;
530+
access_log off;
531+
}
532+
```
533+
534+
- 当你访问:http://127.0.0.1/nginx_status,会得到类似下面的结果
535+
- 其中配置的 `allow 192.168.1.100;` 表示只允许客户端 IP 为这个才能访问这个地址
536+
- `deny all;` 除了被允许的,其他所有人都不可以访问
537+
538+
```
539+
Active connections: 1
540+
server accepts handled requests
541+
3 6 9
542+
Reading: 0 Writing: 5 Waiting: 0
543+
```
544+
545+
- Active connections: 对后端发起的活动连接数(最常需要看的就是这个参数)
546+
- Server accepts handled requests: Nginx总共处理了 3 个连接,成功创建 6 次握手(证明中间没有失败的),总共处理了 9 个请求.
547+
- Reading: Nginx 读取到客户端的 Header 信息数.
548+
- Writing: Nginx 返回给客户端的 Header 信息数.
549+
- Waiting: 开启keep-alive的情况下,这个值等于 active – (reading + writing),意思就是 Nginx 已经处理完成,正在等候下一次请求指令的驻留连接.
550+
- 所以,在访问效率高,请求很快被处理完毕的情况下,Waiting数比较多是正常的.如果reading +writing数较多,则说明并发访问量非常大,正在处理过程中.
551+
501552
## Nginx 配置文件常用配置积累
502553

503554
### location 配置
@@ -687,3 +738,4 @@ limit_conn slimits 5;
687738
- <http://www.ydcss.com/archives/466>
688739
- <http://blog.sae.sina.com.cn/archives/2107>
689740
- <http://www.nginx.cn/273.html>
741+
- <http://printfabcd.iteye.com/blog/1200382>

0 commit comments

Comments
 (0)