我有一个在 1 台服务器上运行的网页。我们正在迁移到一个有 3 台服务器的新平台。
在迁移计划的第一步中,我们需要将一定比例(例如 10%)传输到新集群,将 90% 传输到旧服务器。新平台不需要有粘性会话(与 memcached 共享会话)。
有没有办法用 haproxy 来做到这一点?
答案1
这可以通过让 haproxy 连接自身来实现,为您提供两层负载平衡。
第一层listen
使用balance source
选项和服务器权重来分割现有服务器和集群之间的流量。第二层使用balance roundrobin
无持久性在集群成员之间轮换传入连接。
Listen 10.0.1.1:80
Balance source
Server oldserver 10.0.1.10 weight 90
Server newcluster 10.0.1.20 weight 10
Listen 10.0.1.20:80
Balance roundrobin
Server cluster1 10.0.1.31
Server cluster2 10.0.1.32
Server cluster3 10.0.1.33
答案2
您可以根据需要在 haproxy 中定义权重来分散负载。
来自官方 haproxy 1.4 文档:
weight <weight>
The "weight" parameter is used to adjust the server's weight relative to
other servers. All servers will receive a load proportional to their weight
relative to the sum of all weights, so the higher the weight, the higher the
load. The default weight is 1, and the maximal value is 256. A value of 0
means the server will not participate in load-balancing but will still accept
persistent connections. If this parameter is used to distribute the load
according to server's capacity, it is recommended to start with values which
can both grow and shrink, for instance between 10 and 100 to leave enough
room above and below for later adjustments.
答案3
在 haproxy 服务器部分使用权重。“权重 1 代表频率最低,256 代表频率最高”
server newserver1 192.168.1.1:80 weight 3
server newserver2 192.168.1.2:80 weight 3
server newserver3 192.168.1.3:80 weight 3
server oldserver1 192.168.2.1:80 weight 90