Openresty+Nginx+Lua+Nginx_http_upstream_check_module 搭建
- 下载Openresty与Nginx_http_upstream_check_module
https://openresty.org/cn/download.html
https://github.com/yaoweibin/nginx_upstream_check_module
- 解压Openresty
tar -zxvf openresty-1.13.6.1.tar.gz
- 解压Nginx_http_upstream_check_module到openresty-1.13.6.1/bundle
unzip nginx_upstream_check_module-master.zip
mv nginx_upstream_check_module-master openresty-1.13.6.1/bundle
- 加补丁Nginx_http_upstream_check_module
cd openresty-1.13.6.1/bundle/nginx-1.13.6
patch -p1 < ../nginx_upstream_check_module-master/check_1.12.1+.patch
cd ../..
- 安装依赖
yum -y install pcre-devel
yum -y install postgresql-devel
yum -y install openssl openssl-devel
- 配置
./configure --prefix=/opt/soft/nginx --with-luajit --with-http_iconv_module --with-http_postgres_module --with-pcre --add-module=./bundle/nginx_upstream_check_module-master/ -j8
- 编译安装
make -j8 && make install
- 配置
vim /opt/soft/nginx/nginx/conf/nginx.conf
worker_processes 16;
error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 102400; } http { include mime.types; default_type application/octet-stream; log_format main '$time_local|$request_time|$upstream_response_time|$http_x_forwarded_for|$remote_addr|$upstream_addr|$server_addr|'
'$http_host|$request|$status|$body_bytes_sent|$http_referer|$http_user_agent';
access_log logs/access.log main; sendfile on; keepalive_timeout 5; lua_code_cache on; lua_package_path '/opt/soft/nginx/lualib/?.lua;;'; lua_package_cpath '/opt/soft/nginx/lualib/?.so;;'; server { listen 9595; server_name localhost; location / { root html; index index.html index.htm; } location /nstatus { check_status; access_log off; #allow SOME.IP.ADD.RESS; #deny all; } } upstream test { server 192.168.0.21:80; server 192.168.0.22:80; check interval=3000 rise=2 fall=5 timeout=1000; check_http_send "GET /ip=127.0.0.1 HTTP/1.0\r\n\r\n"; check_http_expect_alive http_2xx; } }
参考文献:
https://openresty.org/cn/installation.html
https://www.cnblogs.com/zdz8207/p/Nginx-Lua-OpenResty.html
http://blog.csdn.net/moqiang02/article/details/42846375
http://jinnianshilongnian.iteye.com/blog/2186270