nginx 负载均衡集群解决方案 healthcheck_nginx_upstreams模块测试 (二)

时间:2023-03-09 01:00:25
nginx 负载均衡集群解决方案 healthcheck_nginx_upstreams模块测试 (二)

在这里详细讲解healthcheck_nginx_upstreams模块中存在的bug,对于healthcheck_nginx_upstreams模块的安装和使用请阅读上一篇blog进行学习。

测试环境,通过nginx做反向代理,请求转发给2和3:

1.192.168.0.235(nginx)
2.192.168.30.150(apache)
3.192.168.30.200(apache)

遇到的问题,当我用上一篇blog的方法安装了healthcheck_nginx_upstreams,并且配置nginx如下:

worker_processes 5;
#daemon off; events {
worker_connections 1000;
} # Only if you want to see lots of spam
error_log logs/error.log debug_http; http { upstream test_upstreams {
server 192.168.30.150:80;
server 192.168.30.200:80; healthcheck_enabled;
healthcheck_delay 2000;
healthcheck_timeout 1000;
healthcheck_failcount 1;
healthcheck_send "GET /.health HTTP/1.0";
} server {
listen 12389; location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://test_upstreams;
proxy_connect_timeout 3;
}
location /stat {
healthcheck_status;
}
}
}

1.测试当一台机器挂掉时的处理:

nginx 负载均衡集群解决方案 healthcheck_nginx_upstreams模块测试 (二)

访问全部走向200机器

2.启动150时,是否会自动连接

nginx 负载均衡集群解决方案 healthcheck_nginx_upstreams模块测试 (二)

访问235时,会同时访问到两台机器

加healthcheck_nginx_upstreamsm模块有什么好处?

如果用原生的upstream模块,当web服务器宕机时,有用户可能是很多用户的请求都会被分配到宕机的服务器,直接影响用户操作。

用healthcheck_nginx_upstreams模块,可以自己二次开发,开发出更友好的监控界面。