介紹
openresty 是什么?
@agentzh 基于nginx全功能的 Web 應(yīng)用服務(wù)器。它打包了標(biāo)準(zhǔn)的 Nginx 核心,很多的常用的第三方模塊,以及它們的大多數(shù)依賴項苇羡。具體參考:http://openresty.org/
sysguard 是什么?
阿里針對nginx開發(fā)的過載保護(hù)擴(kuò)展,具體參考:https://github.com/alibaba/nginx-http-sysguard
安裝
下載sysguard
$wget https://github.com/alibaba/nginx-http-sysguard/archive/master.zip -O /tmp/nginx-http-sysguard-master.zip
$unzip nginx-http-sysguard-master.zip
下載openresty
$cd /tmp
$wget https://openresty.org/download/ngx_openresty-1.9.3.1.tar.gz
編譯安裝鼻弧,先要打一個patch 到 openresty 的nginx core中, 然后編譯安裝
$unzip nginx-http-sysguard-master.zip
$tar zxvf ngx_openresty-1.9.3.1.tar.gz
$cd ngx_openresty-1.9.3.1/bundle/nginx-1.9.3/
$patch -p1 < ../nginx-http-sysguard-master/nginx_sysguard_1.3.9.patch
$cd ../../
$./configure --with-luajit --with-http_stub_status_module --add-module=/tmp/nginx-http-sysguard-master/
$ gmake && gmake install
$/usr/local/openresty/nginx/sbin/nginx -V 查看版本设江,sysguard是否安裝上
配置
在其中的一個server配置中,加入如下進(jìn)行配置攘轩,然后重載配置nginx配置文件
Server {
listen? ? ? 80;
server_name? localhost;
root /mnt/htdocs;
error_page? 500 502 503 504? /50x.html;
location = /50x.html {
? ? ? ? ? ? ?root? html;
}
sysguard on;
sysguard_load load=0.01 action=/50x.html;
sysguard_mem swapratio=20% action=/50x.html;
}
運(yùn)行測試
使用命令$uptime 查看服務(wù)器負(fù)載
如果不高使用 $ab -c 100 -n 10000 http://localhost 壓測叉存,增加負(fù)載
在$curl http://127.0.0.1 訪問將返回50x.html 證明保護(hù)生效了
參考:
http://www.ttlsa.com/nginx/nginx-modules-sysgurad/