大网数据广告活动
服务器运维问答

HAProxy load balancing based on source ip (IP subnet)

· 52CE 我爱测

I have x cluster. This cluster look like Cluster 1 192.168.1. (Server type 1) 192.168.2. (Server type 2) 192.168.3.1 (Server type 3) <Redis server> Cluster 2 192.167.1. (Server type 1) 192.167.2. (Server type 2) 192.167.3.1 (Serv…

问题原文

原帖链接 · Vivek Goel · CC BY-SA 3.0

I have x cluster. This cluster look like

Cluster 1
192.168.1. (Server type 1)
192.168.2. (Server type 2)
192.168.3.1 (Server type 3) <Redis server> 

Cluster 2
192.167.1. (Server type 1)
192.167.2. (Server type 2)
192.167.3.1 (Server type 3) <Redis server> 

Currently I am managing cluster group configuration in code. Is it possible to have a domain called as using haproxy And which redirect require based on source ip? For example

192.167.* request gets redirect to 192.167.3.1

and

192.168.* request gets redirect to 192.168.3.1

已采纳解答

原帖链接 · Philip Cristiano · CC BY-SA 4.0

This is possible with HAProxy ACLs. You need to setup 2 backends, one for each block, then in the frontend create 2 acls, one for each backend.

Your frontend block would look something like this

   acl block_7 src 192.167.0.0/16
   acl block_8 src 192.168.0.0/16

   use_backend block_7_hosts if block_7 
   use_backend block_8_hosts if block_8

Then define a backends block_7_hosts and block_8_hosts with the correct redis server in them.

If you don't plan on adding more Redis servers though you may just want to use a configuration management tool since you aren't really load balancing.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-04-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。