nginx 配置间接监控 udp 负载均衡健康检查

1 篇文章 0 订阅
0 篇文章 0 订阅

1.nginx 搭建

2.nginx.conf 文件的配置

user  root;
worker_processes  1;
error_log  logs/error.log  info;
#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    server {
        listen 80;
        # status interface
        location /status {
            healthcheck_status html;
        }
        # http front
        location / { 
          proxy_pass http://http-cluster;
        }   
    }
    # as a backend server.
    server {
        listen 8080;
        location / {
          root html;
        }
    }
    
    upstream http-cluster {
        # simple round-robin
        server 127.0.0.1:8080;
        server 127.0.0.2:81;

        check interval=3000 rise=2 fall=5 timeout=5000 type=http;
        check_http_send "GET / HTTP/1.0\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
    }
}
stream {
    upstream tcp-cluster {
        #simple round-robin
        server 127.0.0.1:22;
        server 192.168.0.2:22;
		server 192.168.221.141:12346;
        check interval=3000 rise=2 fall=5 timeout=5000 default_down=true type=tcp;
    }
    server {
        listen 5141;
        proxy_pass tcp-cluster;
    }
    
    upstream udp-cluster {
        # simple round-robin
        #server 127.0.0.1:53;
        #server 8.8.8.8:53;
		#server 192.168.221.141:5555;
		server 192.168.221.141:12345 weight=1;
		server 192.168.221.141:12346 weight=1;
		server 192.168.221.141:12347 weight=1;
		server 192.168.221.141:12348 weight=1;
		server 192.168.221.141:12349 weight=1;
        check interval=3000 rise=2 fall=5 timeout=5000 default_down=true type=udp;
    }
    server {
        listen 5140 udp;
        proxy_pass udp-cluster;
    }
}

这里包含了 udp 和 tcp 的负载均衡,虽然实现了udp的负载均衡,但是在直接查看 udp 的健康情况时,udp 永远是健康的。这里采用方法是:被监控的 udp 服务同时监听 udp 和 tcp,在 nginx 这边查看健康情况时,若与 udp 同一 url 的 tcp 是健康的,则视其 udp 是健康的。
所以在配置 udp-cluster 的同时也要 配置到 tcp-cluster 中。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值