V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
daimaosix
V2EX  ›  NGINX

Nginx 可以对 Redis 集群做负载均衡吗?

  •  
  •   daimaosix · 2021-04-03 19:09:42 +08:00 · 1367 次点击
    这是一个创建于 1090 天前的主题,其中的信息可能已经有所发展或是发生改变。

    买了一个 Redis 集群,但是没有公网 IP,所以通过有公网的服务器使用 Nginx 对 Redis 集群进行 TCP 反向代理,以下是 Nginx 配置:

    upstream redis{
            server 192.168.0.21:6379 weight=1;
            server 192.168.0.22:6379 weight=1;
            server 192.168.0.24:6379 weight=1;
    }
    
    server{
           	listen 6330;
            proxy_connect_timeout 2s;
            proxy_timeout 1h;
            proxy_pass redis;
    }
    

    这样做不知道会不会有什么问题,业务是 Java 写的,Java 在配置 Redis 的时候要把集群所有 IP 都写入配置中,如果使用 Nginx 做 TCP 转发是不是就只写一个 Nginx 所在的 IP 就可以了?

    5 条回复    2021-06-10 17:12:41 +08:00
    juzipeek
        1
    juzipeek  
       2021-04-08 21:24:07 +08:00
    不可以
    wxlg1117
        2
    wxlg1117  
       2021-04-27 18:52:30 +08:00
    HAProxy 我记得可以的
    coolloves
        3
    coolloves  
       2021-06-07 09:20:56 +08:00   ❤️ 1
    可以的,nginx 支持 4 层代理,stream
    Toadair
        4
    Toadair  
       2021-06-10 13:43:35 +08:00
    @coolloves 请问大佬,如果是四层代理,那么原始 IP 如何透传呢?
    coolloves
        5
    coolloves  
       2021-06-10 17:12:41 +08:00
    @Toadair 我也没用过,只是知道支持,刚了解了下,
    ginx 配置 proxy_protocol
    后端需要支持 proxy protocol v1
    如果你的后端不支持,那必须修改代码
    proxy protocol 的标准参见 HAProxy 官方文档:
    https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   930 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:54 · PVG 04:54 · LAX 13:54 · JFK 16:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.