nginx安装nginx_upstream_check_module模块
发表于:2022-09-20 |
背景
tengin的nginx_upstream_check_module模块具有心跳检测功能,当发现某个节点不能访问的时候自动切换到另外一个节点,可惜这不是nginx官方自带的模块,需要自己编译

下载nginx
 http://nginx.org/en/download.html

下载模块
 https://github.com/yaoweibin/nginx_upstream_check_module

进行安装Nginx和编译
tar zxvf nginx-1.20.1
unzip master ### github下载下来就叫master,解压后的文件夹是nginx_upstream_check_module-master
cd nginx-1.20.1
patch -p1 < /usr/local/src/nginx_upstream_check_module-master/check_1.20.1+.patch #这步很重要,打补丁
./configure --prefix=/usr/local/nginx --add-module=../nginx_upstream_check_module-master
make
make install 

编辑配置文件
vi /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 10.10.10.100:80;
        server 10.10.10.110: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 / {
            root   html;
            index  index.html index.htm;
        proxy_pass http://cluster;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location /status {
                check_status;
                access_log off;
        }
    }
}

启动并验证
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
浏览器访问
上一篇:
Ubuntu 20.04 修改时区 24小时
下一篇:
mysql开启远程访问权限