天天看點

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

[[email protected] ~]

# yum -y install libxslt-devel gd-devel lua-devel geoip-devel

[[email protected] ~]

# groupadd -r nginx

[[email protected] ~]

# useradd -r -g nginx nginx

[[email protected] ~]

# tar zxvf tengine-1.5.2.tar.gz

[[email protected] ~]

# cd tengine-1.5.2

[[email protected] 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

[[email protected] tengine-1.5.2]

# make && make install

[[email protected] ~]

# ls /usr/local/nginx/modules/ | grep sys

ngx_http_sysguard_module.so

[[email protected] ~]

# /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf

[[email protected] ~]

# 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

[[email protected] ~]

# 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

[[email protected] ~]

# /usr/local/nginx/sbin/nginx -s reload

5.驗證過載保護功能

1 2 3 4

在測試機發起壓力測試:

[[email protected] ~]

# ab -c 5000 -n 20000 http://192.168.30.117/index2.html

觀察伺服器負載:

[[email protected] ~]

# htop

Tengine ngx_http_sysguard_module 過載保護子產品使用

繼續通路頁面發現403:

Tengine ngx_http_sysguard_module 過載保護子產品使用

6.tengine過載保護功能生效

     本文轉自ljl_19880709 51CTO部落格,原文連結:http://blog.51cto.com/luojianlong/1382463 ,如需轉載請自行聯系原作者