openresty下配置sysguard做过载保护

介绍

openresty 是什么?

@agentzh 基于nginx全功能的 Web 应用服务器。它打包了标准的 Nginx 核心,很多的常用的第三方模块,以及它们的大多数依赖项。具体参考:http://openresty.org/

sysguard 是什么?

阿里针对nginx开发的过载保护扩展,具体参考: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配置中,加入如下进行配置,然后重载配置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;

}


运行测试

使用命令$uptime 查看服务器负载

如果不高使用 $ab -c 100 -n 10000 http://localhost 压测,增加负载

在$curl http://127.0.0.1 访问将返回50x.html 证明保护生效了

参考:

http://www.ttlsa.com/nginx/nginx-modules-sysgurad/

你可能感兴趣的:(openresty下配置sysguard做过载保护)