centos7.9 openresty1.21 增加nginx_upstream_check_module第三方模块

1、背景说明:


OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

简单地说OpenResty 的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应
本次教学操作是在rpm已安装openresty1.21的前提下(dockerfile安装),动态加入第三方模块nginx_upstream_check_module因此我们选择安装OpenResty1.21(目前最新版本)。

nginx_upstream_check_module是阿里的检测后端relaserver 真实状态的模块,使用前端负载均衡器nginx做到后端服务出错时,自动将出错的节点路踢掉,使得正常请求不发往出错的后端节点,当出错的后端节点恢复后,又能将节点自动加入集群中。nginx自身虽然带有简单的健康检测,但并不有效。因此我们选择单独安装nginx_upstream_check_module更好的做健康检查

首先根据rpm安装openresty1.21后发现三方模块无法在dockerfile加入,所以本次安装为手动动态添加

2、下载最新 openresty1.21(此版本要和你rpm安装的版本相同,必须相同)

https://openresty.org/download/openresty-1.21.4.1.tar.gz

从GitHub下载三方zip 包
https://github.com/yaoweibin/nginx_upstream_check_module.git

3、nginx_upstream_check_module-master打补丁


cd /root
tar -zxvf openresty-1.21.4.1.tar.gz
unzip nginx_upstream_check_module-master.zip

打nginx_upstream_check_module补丁:
因为我们nginx是1.21版本,因此需要选择check_1.20.1+.patch进行打补丁,这个地方版本需要对应好,不然会报错
打补丁过程中,因为安装的不是默认Nginx,是openresty,因此需要手工指定安装文件的路径和名称
打补丁过程中共需要手工录入5个文件的路径信息,其实就是要更新这5个文件的内容,使其兼容nginx_upstream_check_module-master的功能:

test# cd openresty-1.21.4.1
test# patch -p1 < /root/nginx_upstream_check_module-master/check_1.21.1+.patch

file to patch:/root/openresty-1.21.4.1/bundle/nginx-1.21.4.1/src/http/modules/ngx_http_upstream_hash_module.c
file to patch:/root/openresty-1.21.4.1/bundle/nginx-1.21.4.1/src/http/modules/ngx_http_upstream_ip_hash_module.c
file to patch:/root/openresty-1.21.4.1/bundle/nginx-1.21.4.1/src/http/modules/ngx_http_upstream_least_conn_module.c

file to patch:/root/openresty-1.21.4.1/bundle/nginx-1.21.4.1/src/http/ngx_http_upstream_round_robin.c
file to patch:/root/openresty-1.21.4.1/bundle/nginx-1.21.4.1/src/http/ngx_http_upstream_round_robin.h

4、编译openresty,动态添加三方模块

yum -y install ccache pcre-devel openssl-devel gcc curl openldap-devel openresty-openssl111-devel

test# cd /root/openresty-1.21.4.1

openresty-1.21.4.1# ./configure --prefix=/usr/local/openresty --add-module=/root/nginx_upstream_check_module-master

## 切记 如果是动态添加模块,只执行gmake,不要执行gmake install,执行install 会把线上的-V得覆盖了
test# gmake


执行完之后,进入该目录下
cd /root/openresty-1.21.4.1/build/1.21.4.1/objs
## 停nginx
objs# /usr/local/openresty/nginx/sbin/nginx -s stop
objs# mv /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/nginx/sbin/nginxbak
objs# cp nginx /usr/local/openresty/nginx/sbin/

sbin# ./nginx -V
nginx version: openresty/1.21.4.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.21 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.11 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --add-module=/root/nginx_upstream_check_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值