@cdmonkey
2022-03-22T11:18:50.000000Z
字数 5295
阅读 1616
Nginx
http://hugoren.iteye.com/blog/2289411
http://hugoren.iteye.com/blog/2289960
https://xiangxianzui.github.io/2017/11/nginx-lua%E5%8A%A8%E6%80%81%E6%94%B9%E5%8F%98upstream/
https://github.com/cubicdaiya/ngx_dynamic_upstream
https://github.com/yaoweibin/nginx_upstream_check_module
首先下载相关软件包。
LuaJIT-2.0.5 http://luajit.org/download.html
ngx_devel_kit (NDK) module https://github.com/simplresty/ngx_devel_kit/releases
lua-nginx-module https://github.com/openresty/lua-nginx-module/releases
首先要安装好 LuaJIT,然后解压 NDK module
及 lua-nginx-module
,继续。
http://luajit.org/install.html
[root@testnginx01 tools]# tar zxvf LuaJIT-2.0.5.tar.gz
[root@testnginx01 tools]# cd LuaJIT-2.0.5
make PREFIX=/usr/local/nginx/lua/luajit
make install PREFIX=/usr/local/nginx/lua/luajit
然后进行编译。下面包含生产中完整之三个第三方模块。首先要准备好这三个模块:
[root@testnginx01 tools]# unzip ngx_dynamic_upstream-master.zip
[root@testnginx01 tools]# unzip nginx_upstream_check_module-master.zip
[root@testnginx01 tools]# unzip nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip
[root@testnginx01 tools]# mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 nginx-sticky-module
首先处理 nginx-sticky-module
:
[root@testnginx01 tools]# cd nginx-sticky-module
[root@testnginx01 nginx-sticky-module]# patch -p0 < ../nginx_upstream_check_module-master/nginx-sticky-module.patch
patching file ngx_http_sticky_module.c
Hunk #1 succeeded at 15 with fuzz 2 (offset 5 lines).
Hunk #2 succeeded at 304 (offset 12 lines).
Hunk #3 succeeded at 330 (offset 12 lines).
Hunk #4 succeeded at 352 (offset 12 lines).
接下来处理 nginx_upstream_check_module
:
[root@testnginx01 tools]# tar zxvf nginx-1.12.1.tar.gz
[root@testnginx01 tools]# cd nginx-1.12.1
[root@testnginx01 nginx-1.12.1]# patch -p1 < ../nginx_upstream_check_module-master/check_1.12.1+.patch
patching file src/http/modules/ngx_http_upstream_hash_module.c
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
patching file src/http/ngx_http_upstream_round_robin.h
最后为安装 ngx_dynamic_upstream
进行准备:
[root@testnginx01 tools]# tar zxvf ngx_devel_kit-0.3.0.tar.gz
[root@testnginx01 tools]# tar zxvf lua-nginx-module-0.10.13.tar.gz
匹配环境变量:
[root@testnginx01 ~]# vim .bash_profile
# 加入如下内容,告诉 Nginx 编译程序在哪里能找到 LuaJIT。
export LUAJIT_LIB=/usr/local/nginx/lua/luajit/lib
export LUAJIT_INC=/usr/local/nginx/lua/luajit/include/luajit-2.0
# 配置生效:
[root@testnginx01 ~]# . .bash_profile
make
./configure \
--prefix=/usr/local/nginx \
--user=nginx --group=nginx \
--with-openssl=/root/tools/openssl-1.0.2l \
--with-http_ssl_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre=/root/tools/pcre-8.39 \
--with-http_realip_module \
--with-ld-opt="-Wl,-rpath,/usr/local/nginx/lua/luajit/lib" \
--add-module=/root/tools/nginx_upstream_check_module-master \
--add-module=/root/tools/nginx-sticky-module \
--add-module=/root/tools/ngx_devel_kit-0.3.0 \
--add-module=/root/tools/lua-nginx-module-0.10.13 \
--add-module=/root/tools/ngx_dynamic_upstream-master
# 完成配置后仅只执行 make 操作:
make
进行备份及替换操作:
[root@testnginx01 ~]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
#
[root@testnginx01 ~]# killall nginx
[root@testnginx01 ~]# cp tools/nginx-1.12.1/objs/nginx /usr/local/nginx/sbin/nginx
[root@testnginx01 ~]# nginx -V
nginx version: nginx/1.12.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.2l 25 May 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-openssl=/root/tools/openssl-1.0.2l --with-http_ssl_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/root/tools/pcre-8.39 --with-http_realip_module --with-ld-opt=-Wl,-rpath,/usr/local/nginx/lua/luajit/lib --add-module=/root/tools/nginx_upstream_check_module-master --add-module=/root/tools/nginx-sticky-module --add-module=/root/tools/ngx_devel_kit-0.3.0 --add-module=/root/tools/lua-nginx-module-0.10.13 --add-module=/root/tools/ngx_dynamic_upstream-master
首先测试一下 Lua
这个模块用于调试。
https://github.com/openresty/echo-nginx-module
http://tool.oschina.net/uploads/apidocs/nginx-zh/HttpEchoModule.htm#Installation
安装很简单,先把 zip 压缩包解压缩,然后于配置时直接指定路径即可。
[root@PBSNGX03 tools]# unzip echo-nginx-module-master.zip
# Configure:
[root@PBSNGX03 tools]# cd nginx-1.12.2
[root@PBSNGX03 nginx-1.12.2]# ./configure
...
--add-module=/root/tools/echo-nginx-module-master
curl "https://stageloan.vbillbank.com/dynamic?upstream=stageloan"
server 18.10.30.150:8080;
server 18.10.30.151:8080;
curl "https://stageloan.vbillbank.com/dynamic?upstream=stageloan&server=18.10.30.150:8080&down="
server 18.10.30.150:8080 weight=1 max_fails=1 fail_timeout=10 down;
server 18.10.30.151:8080 weight=1 max_fails=1 fail_timeout=10;
于 CentOS7 编译安装时,当执行 make
时,会报错误信息:
...
/root/tools/pcre-8.39/missing: line 81: aclocal-1.15: command not found
WARNING: 'aclocal-1.15' is missing on your system.
You should only need it if you modified 'acinclude.m4' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'aclocal' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
make[2]: *** [aclocal.m4] Error 127
make[2]: Leaving directory '/root/tools/pcre-8.39'
make[1]: *** [/root/tools/pcre-8.39/Makefile] Error 2
make[1]: Leaving directory '/root/tools/nginx-1.12.1'
make: *** [build] Error 2
结论是重新解压 pcre 就行了。
可能还需要重新解压 openssl。