Tengine ngx_http_sysguard_module 过载保护模块使用,


简介

Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。


运行环境:Centos 6.4 x86_64

软件版本:tengine-1.5.2

软件下载地址:wget http://tengine.taobao.org/download/tengine-1.5.2.tar.gz

1.编译安装tengine


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 [root@localhost ~]# yum -y install libxslt-devel gd-devel lua-devel geoip-devel [root@localhost ~]# groupadd -r nginx [root@localhost ~]# useradd -r -g nginx nginx [root@localhost ~]# tar zxvf tengine-1.5.2.tar.gz [root@localhost ~]# cd tengine-1.5.2 [root@localhost tengine-1.5.2]# ./configure \ > --prefix=/usr/local/nginx \ > --conf-path=/etc/nginx/nginx.conf \ > --error-log-path=/var/log/nginx/error.log \ > --http-log-path=/var/log/nginx/access.log \ > --pid-path=/var/run/nginx/nginx.pid  \ > --lock-path=/var/lock/nginx.lock \ > --user=nginx \ > --group=nginx \ > --enable-mods-shared=all [root@localhost tengine-1.5.2]# make && make install [root@localhost ~]# ls /usr/local/nginx/modules/ | grep sys ngx_http_sysguard_module.so [root@localhost ~]# /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf [root@localhost ~]# ps aux | grep nginx root     25508  0.0  0.0  83684  1252 ?        Ss   13:58   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf nginx    25509  0.0  0.0  84088  1780 ?        S    13:58   0:00 nginx: worker process                         root     25547  0.0  0.0 103248   824 pts/0    S+   14:02   0:00 grep nginx


2.编译/etc/nginx/nginx.conf 动态加载ngx_http_sysguard_module 模块

1 2 3 4 5 6 [root@localhost ~]# vi /etc/nginx/nginx.conf http { dso {     load ngx_http_sysguard_module.so; } }


3.在server段中配置过载保护:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 server {         listen       80;         server_name  192.168.30.117;         sysguard on;         sysguard_load load=0.1 action=/loadlimit;         sysguard_mem swapratio=20% action=/swaplimit;         sysguard_mem free=100M action=/freelimit;         #charset koi8-r;         #access_log  logs/host.access.log  main;         root   /var/www/html;         index  index.html index.htm;         location / {         }         location /loadlimit {            return 403;         }

4.重启tengine

1 [root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload


5.验证过载保护功能


1 2 3 4 在测试机发起压力测试: [root@node1 ~]# ab -c 5000 -n 20000 http://192.168.30.117/index2.html 观察服务器负载: [root@localhost ~]# htop

wKioL1Mv2QPSuS-gAAYdvlcu4xs652.jpg


继续访问页面发现403:

wKioL1Mv2UzT_wO5AAFA8mAmmgc240.jpg


6.tengine过载保护功能生效








     本文转自ljl_19880709 51CTO博客,原文链接:http://blog.51cto.com/luojianlong/1382463,如需转载请自行联系原作者

相关内容