nginx安装nginx_upstream_check_module模块
转载自:https://blog.51cto.com/riverxyz/3928890
背景
tengin的nginx_upstream_check_module模块具有心跳检测功能,当发现某个节点不能访问的时候自动切换到另外一个节点,可惜这不是nginx官方自带的模块,需要自己编译
下载nginx
http://nginx.org/en/download.html
下载的地址是:https://nginx.org/download/nginx-1.22.1.tar.gz
下载模块
https://github.com/yaoweibin/nginx_upstream_check_module
https://github.com/yaoweibin/nginx_upstream_check_module/tags
https://github.com/yaoweibin/nginx_upstream_check_module/releases/tag/v0.4.0
从tag中下载:https://github.com/yaoweibin/nginx_upstream_check_module/archive/refs/tags/v0.4.0.zip
注意下载模块适用的nginx版本
进行安装Nginx和编译
tar -zxv -f nginx-1.22.1.tar.gz
unzip nginx_upstream_check_module-0.4.0.zip (从模块tag中下载后的文件名)
cd /usr/local/src/nginx-1.22.1
yum -y install patch
patch -p1 < /usr/local/src/nginx_upstream_check_module-0.4.0/check_1.20.1+.patch #这步很重要,打补丁
./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/nginx_upstream_check_module-0.4.0 #加载模块使用绝对路径
make
make install
编辑配置文件
# vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream cluster {
server 127.0.0.1:80;
server 127.0.0.1:5040;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://cluster;
}
location /status {
check_status;
access_log off;
}
}
}
启动并验证
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
浏览器访问