verynginx +nginx_upstream_check_module模块,负载均衡检查模块。
yum -y install git
yum -y install patch
yum -y install pcre-devel
yum install -y zlib-devel
mkdir /opt/nginx/ && cd /opt/nginx/
wget https://openresty.org/download/openresty-1.9.15.1.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.8.6.tar.gz
tar xf xxx.tar.gz
git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
cp -a nginx_upstream_check_module /opt/nginx/openresty-1.9.15.1/bundle/nginx-1.9.15/
cd /opt/nginx/openresty-1.9.15.1/bundle/nginx-1.9.15/
patch -p0 < /opt/nginx/openresty-1.9.15.1/bundle/nginx-1.9.15/nginx_upstream_check_module/check_1.9.2+.patch
cd /opt/nginx/openresty-1.9.15.1/
./configure --prefix=/usr/local/verynginx --user=nginx --group=nginx --with-http_v2_module --with-http_sub_module --with-http_stub_status_module --with-luajit --with-openssl=/opt/nginx/openssl-1.0.2l --add-module=/opt/nginx/openresty-1.9.15.1/bundle/nginx-1.9.15/nginx_upstream_check_module/ make -j 4 make install
cd .. && cp –a VeryNginx/veryNginx /usr/local/vnginx/ && chown -R nginx:nginx /usr/local/vnginx/verynginx
vim nginx.conf
user nginx;
worker_processes auto;
- #daemon off; #如果要在docker运行,加这个参数让nginx在前台运行
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
include /usr/local/verynginx/verynginx/nginx_conf/in_external.conf;
http {
include mime.types;
default_type application/octet-stream;
log_format access '$host $remote_addr - - $time_local "$request" "$http_referer" "$http_user_agent" $body_bytes_sent "$http_x_forwarded_for" $request_length $status $request_time';
sendfile on;
keepalive_timeout 65;
client_body_buffer_size 128k;
gzip on;
include /usr/local/verynginx/verynginx/nginx_conf/in_http_block.conf;
# include /usr/local/verynginx/nginx/conf/vhosts/*.conf;
server {
listen 80;
include /usr/local/verynginx/verynginx/nginx_conf/in_server_block.conf;
location = / {
root html;
index index.html index.htm;
}
}
include /usr/local/verynginx/nginx/conf/vhosts/*.conf;
}
mkdir -p /usr/local/verynginx/nginx/conf/vhosts/
vim t.conf upstream nsignature { server 127.0.0.1:9998 weight=1; server 127.0.0.1:9998 weight=1; check interval=3000 rise=2 fall=5 timeout=1000; check_http_send "GET /1 HTTP/1.0\r\n\r\n"; check_http_expect_alive http_2xx http_3xx; } server { listen 80; server_name test.xxx.cn; location /{ proxy_pass http://nsignature; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /nstatus { check_status; access_log off; allow all; } access_log /var/log/test.log access; }
vim /usr/local/verynginx/verynginx/nginx_conf/in_http_block.conf
upstream vn_upstream{ server 127.0.0.1; balancer_by_lua_file /usr/local/verynginx/verynginx/lua_script/on_banlance.lua; keepalive 1024; #Connection pool } lua_package_path '/usr/local/verynginx/verynginx/lua_script/?.lua;;/usr/local/verynginx/verynginx/lua_script/module/?.lua;;'; lua_package_cpath '/usr/local/verynginx/verynginx/lua_script/?.so;;'; lua_code_cache on; lua_shared_dict status 1m; lua_shared_dict frequency_limit 10m; lua_shared_dict summary_long 10m; lua_shared_dict summary_short 10m; init_by_lua_file /usr/local/verynginx/verynginx/lua_script/on_init.lua; rewrite_by_lua_file /usr/local/verynginx/verynginx/lua_script/on_rewrite.lua; access_by_lua_file /usr/local/verynginx/verynginx/lua_script/on_access.lua; log_by_lua_file /usr/local/verynginx/verynginx/lua_script/on_log.lua;