openresty-1.19.3.2安装以及nginx_upstream_check_module健康检查模块安装

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

简单地说OpenResty 的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应
因此我们选择安装OpenResty。其中OpenResty1.17版本之前有bug,经常出现自动kill的问题,因此我们选择OpenResty1.19版本,可以很好的规避这个问题。

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

2、下载:
openresty进入官网网站进行下载,
wget https://openresty.org/download/openresty-1.19.3.2.tar.gz

nginx_upstream_check_module 从github上下载
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/refs/heads/master.zip

3、首次安装
./configure 主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系,然后生成make所需的makefile文件,如果源码目录已经有makefile了,也可以不需要./configure

make 命令会按makefile 配置文件编译源码,生成可执行文件和其他相关文件,编译好后的文件都放到当前目录

make install 命令会把编译好的可执行文件和其他相关文件拷贝到–prefix指定的目录或者默认的目录
3.1、解压安装介质:
cd /root
tar -zxvf openresty-1.19.3.2.tar.gz
unzip nginx_upstream_check_module-master.zip

3.2、打nginx_upstream_check_module补丁:
因为我们nginx是1.19版本,因此需要选择check_1.16.1+.patch进行打补丁,这个地方版本需要对应好,不然会报错
cd openresty-1.19.3.2
patch -p1 < /root/nginx_upstream_check_module-master/check_1.16.1+.patch
打补丁过程中,因为安装的不是默认Nginx,是openresty,因此需要手工指定安装文件的路径和名称
打补丁过程中共需要手工录入5个文件的路径信息,其实就是要更新这5个文件的内容,使其兼容nginx_upstream_check_module-master的功能:
/root/openresty-1.19.3.2/bundle/nginx-1.19.3/src/http/modules/ngx_http_upstream_hash_module.c
/root/openresty-1.19.3.2/bundle/nginx-1.19.3/src/http/modules/ngx_http_upstream_ip_hash_module.c
/root/openresty-1.19.3.2/bundle/nginx-1.19.3/src/http/modules/ngx_http_upstream_least_conn_module.c

/root/openresty-1.19.3.2/bundle/nginx-1.19.3/src/http/ngx_http_upstream_round_robin.c
/root/openresty-1.19.3.2/bundle/nginx-1.19.3/src/http/ngx_http_upstream_round_robin.h
在这里插入图片描述
3.3 安装openresty
安装时带上nginx_upstream_check_module模块
–with-http_stub_status_module模块是为了后面将nginx接入zabbix等监控工具所需要的,这里提前安装好。SSL等模块会自动安装,openresty默认安装路径是/usr/local/openresty

./configure --prefix=/usr/local/openresty --add-module=/root/nginx_upstream_check_module-master --with-http_stub_status_module
在这里插入图片描述
执行完毕configure后,新增了一个文件和一个文件夹

3.4 gmake
3.5 gmake install

安装完毕后我们nginx -V确认一下:
[root@prd-DTEST-psi: ~/openresty-1.19.3.2]# /usr/local/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.19.3.2
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.32 --add-module=…/form-input-nginx-module-0.12 --add-module=…/encrypted-session-nginx-module-0.08 --add-module=…/srcache-nginx-module-0.32 --add-module=…/ngx_lua-0.10.19 --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.7 --add-module=…/rds-json-nginx-module-0.15 --add-module=…/rds-csv-nginx-module-0.09 --add-module=…/ngx_stream_lua-0.0.9 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --add-module=/root/nginx_upstream_check_module-master --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module
[root@prd-DTEST-psi: ~/openresty-1.19.3.2]#

4、如果openresty-1.19.3.2已经正在运行,只是想新增nginx_upstream_check_module模块
4.1、先确认正在运行的nginx已经安装了哪些模块: /usr/local/openresty/nginx/sbin/nginx -V
确保后面configure 编译安装时不要有遗漏,并增加上新的模块。

4.2、执行3.1、3.2、3.3、3.4步,不要执行3.5,(注意:此处只make,编译参数需要和之前的一样,不要执行make install,否则就会覆盖正在使用的nginx)

4.3、停止ng,并替换nginx文件
/usr/local/openresty/nginx/sbin/nginx -s stop
mv /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/nginx/sbin/nginxoldbak
cp /root/openresty-1.19.3.2/build/nginx-1.19.3/objs/nginx /usr/local/openresty/nginx/sbin/nginx
/usr/local/openresty/nginx/sbin/nginx
/usr/local/openresty/nginx/sbin/nginx -V

5、nginx check 配置
upstream hrois_haier_net_server {
server 10.163.19.22:8080;
server 10.25.13.4:8080;
ip_hash;
check interval=10000 rise=2 fall=5 default_down=false timeout=5000 type=http;
check_http_send “HEAD / HTTP/1.0\r\n\r\n”;
check_http_expect_alive http_2xx http_3xx;
}

如果后端服务访问有问题,会在nginx error日志中体现出来,日志举例如下:
2022/05/17 15:41:25 [error] 22088#0: send() failed (111: Connection refused)
2022/05/17 15:41:35 [error] 22088#0: send() failed (111: Connection refused)
2022/05/17 15:42:56 [error] 23128#0: check protocol http error with peer: 10.163.19.22:8080
2022/05/17 15:43:06 [error] 23128#0: check protocol http error with peer: 10.163.19.22:8080
2022/05/17 15:43:31 [error] 23358#0: enable check peer: 10.163.19.22:8080

经过测试,发现check功能是有效的。如果是用浏览器访问测试,因为浏览器有缓存,每次测试时需要清理一下浏览器缓存或使用无痕模式。

6、在nginx.conf中增加如下内容,便于接入zabbix监控
server {
listen 80;
server_name localhost;
location /ngx_status {
stub_status on;
access_log off;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值