使用Tengine 对负载均衡进行状态检查(day028)

本篇文章对于在服务器已经安装了nginx,但却希望使用Tengine 的状态检查或其他功能时使用,不需要卸载服务器上的nginx,思路是使用干净服务器(未安装过nginx)通过编译安装Tengine,通过对./configure的配置,保证安装Tengine的环境与nginx服务器相同,(同时,加入需要的Tengine模块),编译,最后将nginx代码传送至nginx服务器对应位置,覆盖原先nginx代码,完成nginx服务器上Tengine功能的更新。

1.前往Changelog - The Tengine Web Server,下载最新的tengine的tar包

2.解压tar包并进入目录中

3.编译安装前,安装依赖

yum install -y gcc make pcre pcre-devel openssl openssl-devel zlib zlib-devel geoip geoip-devel perl perl-devel gperftools gperftools-devel libxslt libxslt-devel

yum install -y gd-devel

yum -y install perl-ExtUtils-Embed

此处例举大部分依赖,若下面出现问题大概率是此处缺少其他依赖

4.在已经配置好nginx的机器上,使用nginx -V,查看nginx的configure argument

复制代码
--prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

5.配置环境,在目录中运行如下命令(./configure 上面复制的配置信息+需要添加的模块)

注意:此处需要在tengine目录下,因为下面使用的是相对地址

因为tengine服务把ngx常用的第3方模块放在了源代码中的modules目录下面。

--add-module=modules/ngx_http_upstream_check_module 编译安装的时候增加upstream_check模块

--add-module=modules/ngx_http_upstream_session_sticky_module/ 增加会话共享模块

复制代码
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=modules/ngx_http_upstream_check_module/ --add-module=modules/ngx_http_upstream_session_sticky_module/

6.进行编译

make -j 1 这里1为cpu核心,或者直接make也可以

正常这一步如果要安装Tengine,make install 即可,这里不需要安装。

7.将当前目录下的objs下的nginx代码传到负载均衡服务器

scp ./objs/nginx lb01:~

8.负载均衡服务器检查./nginx -V,检查scp过来的nginx信息

注意图片最后两行已经加了对应的模块

9.将nginx代码替换掉原来的,scp是传至家目录,所以下面两条命令执行也是在家目录下。

mv /sbin/nginx /sbin/nginx1

mv nginx /sbin/nginx

10.nginx -V,检查nginx信息,此时已经可以看到信息如第8步一致

注意:第八步看的是家目录下的nginx代码信息,此处看的是服务器nginx代码信息

nginx -t,检查语法

kill -USR2 pid (通过老的命令向当前运行的ngx发送信号,准备被新的ngx进程替代)

kill pid(之前的ngx服务)

systemctl restart nginx 重新启动nginx。

11.对需要状态检查的页面进行配置,可以参考Tengine官网(ngx_http_upstream_check_module - The Tengine Web Server

配置完成即可查看各个web服务器信息

12.各个参数

check interval=3000 rise=2 fall=5 timeout=1000 type=http;

检查间隔3000ms,成功两次即为活跃状态,失败五次即为挂掉状态,检查类型为http请求

check_http_send 代理向web服务器通过http方式发出请求报文,请求报文起始行,请求方法, 请求的URI,请求协议(默认使用的是ip方式 访问

check_http_expect_alive 收到指定的状态码,就认为是存活的

相关推荐
乘云数字DATABUFF1 天前
5分钟部署开源APM Databuff:OpenTelemetry全链路追踪入门实战
运维·后端
荣--3 天前
一键部署不是为了省时间 —— 它是把"买来的 PaaS"变成"自己的平台"的拐点
运维·zabbix·工程化·一键部署·平台化·边界设计
江华森3 天前
动手实战学 Docker — 从零到集群编排完全指南
运维
Avan_菜菜4 天前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
SelectDB5 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
XIAOHEZIcode6 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220707 天前
如何搭建本地yum源(上)
运维
ping某8 天前
为什么 Nginx 明明监听了 80,转发后端时却用了 4xxxx 端口?
后端·nginx
大树8810 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠10 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql