赞
踩
https://www.iamle.com/archives/1865.html
haproxy配置文件重要参数,有端口数目限制:
global maxconn 65535 #最大连接数,HAProxy是数据转发,每条数据链路占用两个连接。
当我们使用haproxy 做负载均衡器的时候,负载均衡多个后端服务器,但是有一个问题,负载均衡后端的服务器的是需要占用haproxy机端口的.
tcp的端口一共65535个除去保留端口,基本也就64k可用的样子.
那么f5之类套着硬件皮的负载均衡器是怎么做到的可以负载几十万的连接数的?
其实f5机本身自己使用了多个内网ip地址,一个f5上的内网ip地址拥有连接后端64k连接的能力.
那么haproxy支持这样的功能么,从而负载更高的连接数么?
经过灿哥的分享,我们知道是可以的,只要给haproxy机配置多个lan内网ip,haproxy机可以通过多个lan内网ip去负载均衡后端服务器.Linux支持单个网卡,绑定多个IP地址。
一个内网ip去负载一台后端服务,这样一个haproxy内网ip就有了长64k连接的负载能力了.
配置例子
haproxy负载均衡机
外网ip: 8.8.8.8
haproxy内网ip1: 10.8.8.2
haproxy内网ip2: 10.8.8.3
haproxy内网ip3: 10.8.8.4
后端web1内网ip: 10.8.8.10
后端web2内网ip: 10.8.8.11
后端web3内网ip: 10.8.8.12
server web1 10.8.8.10 : 80 check source 10.8.8.2 : 1025 – 65000
server web2 10.8.8.11 : 80 check source 10.8.8.3 : 1025 – 65000
server web3 10.8.8.12 : 80 check source 10.8.8.4 : 1025 – 65000
如果haproxy机只有一个内网ip 10.8.8.2 去反向代理所有后端,总连接数就只有64k,如果这样配置利用了多个ip去链接后端那么一个haproxy就可以64k连接
从而让haproxy机支持甚至几十w的连接数了.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
source <addr>[:<pl>[-<ph>]] [usesrc { <addr2>[:<port2>] | client | clientip } ]
source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | hdr_ip(<hdr>[,<occ>]) } ]
source <addr>[:<pl>[-<ph>]] [interface <name>] ...
The "source" parameter sets the source address which will be used when
connecting to the server. It follows the exact same parameters and principle
as the backend "source" keyword, except that it only applies to the server
referencing it. Please consult the "source" keyword for details.
Additionally, the "source" statement on a server line allows one to specify a
source port range by indicating the lower and higher bounds delimited by a
dash ('-'). Some operating systems might require a valid IP address when a
source port range is specified. It is permitted to have the same IP/range for
several servers. Doing so makes it possible to bypass the maximum of 64k
total concurrent connections. The limit will then reach 64k connections per
server.
Supported in default-server: No
|
Doing so makes it possible to bypass the maximum of 64k total concurrent connections. The limit will then reach 64k connections per server.
这样做可以绕过64 k的最大并发连接。限制将达到64 k每台后端服务器的连接。也就是说我3台web后端每台64k,haproxy机上就是 64k * 3 = 192k
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。