米狗

  • kubernets
  • docker
  • AWS
  • linux
  • nginx
Kratos
  1. 首页
  2. 中间件
  3. nginx
  4. 正文

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

2022年8月28日 623点热度 0人点赞 0条评论

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

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 中。

标签: 暂无
最后更新:2022年8月28日

duhongjun

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

归档

  • 2024 年 10 月
  • 2024 年 4 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 11 月
  • 2023 年 4 月
  • 2023 年 2 月
  • 2023 年 1 月
  • 2022 年 11 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 8 月
  • 2021 年 12 月
  • 2021 年 11 月
  • 2021 年 8 月
  • 2021 年 7 月
  • 2021 年 6 月
  • 2021 年 2 月
  • 2020 年 1 月
  • 2019 年 12 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 8 月

分类目录

  • AWS
  • docker
  • elasticsearch
  • Jenkins
  • kubernets
  • linux
  • mysql
  • nginx
  • Oracle
  • php
  • redis
  • zabbix
  • 个人
  • 中间件
  • 公有云
  • 大数据
  • 安全工具
  • 微软
  • 操作系统
  • 数据库
  • 未分类
  • 监控
  • 科技
  • 网络技术
  • 资讯
  • 阿里云

COPYRIGHT © 2024 米狗. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

沪ICP备2021019346号-1