查看完整版本: [技巧]在openbsd上实现负载均衡

杀死白雪公主 2008-4-14 12:30

[技巧]在openbsd上实现负载均衡

  负载均衡需要有的特性如下:
  支持多[url=http://server.ctocio.com.cn/]服务器[/url]的服务池和轮询策略
  支持自身HA
  支持会话同步,在单机失效的情况下操持会话连接
  我使用了VirtualBox建议模拟环境。我只是说明它的配置,不会有OpenBSD自身的安装和系统配置。
  [url=http://networking.ctocio.com.cn/]网络[/url]规划如下:
  外网网段:192.168.1.xxx
  PFSYNC网段:10.10.9.xxx
  内网网段:10.10.10.xxx
  整体拓扑如下:
  [img=692,486]http://blog.opensource.[url=http://whatis.ctocio.com.cn/searchwhatis/20/6093020.shtml]org[/url].cn/hdcola/lbsample.[url=http://whatis.ctocio.com.cn/searchwhatis/159/6026159.shtml]PNG[/url].png[/img]
  这里我们可以看到以下关键字,请自行google之,或到OpenBSD [url=http://whatis.ctocio.com.cn/searchwhatis/343/5947843.shtml]FAQ[/url]中了解:
  CARP(Common Access Redundancy Protocol )
  pf([url=http://whatis.ctocio.com.cn/searchwhatis/385/6025885.shtml]packet[/url] fileter)
  Load Balance
  我们对LB1机器的三个网卡配置如下:
  /etc/hostname.pcn0
  inet 192.168.1.101 255.255.255.0 192.168.1.255
  /etc/hostname.pcn1
  inet 10.10.10.101 255.255.255.0 10.10.10.255
  /etc/hostname.pcn2
  inet 10.10.9.101 255.255.255.0 10.10.9.255
  相应的LB2也是对应的配置,只是ip不相同
  后端服务器网络配置的重点是将它们的网关配置成为LB的后端CARP虚似[url=http://whatis.ctocio.com.cn/searchwhatis/191/6025691.shtml]IP[/url]。
  /etc/mygate
  10.10.10.100
  在LB1和LB2上配置CARP。LB会有两个虚似IP,一个是对外提供服务的VIP,一个是内部用于后端服务器的网关IP。它们都使用CARP来虚似,好在一个机器出现问题后由第二台机器接管它的服务。
  先增加外网VIP的CARP接口:
  LB1上增加carp0接口:
  /etc/hostname.carp0
  inet 192.168.1.100 255.255.255.0 192.168.1.255 vhid 1 pass yourpasswd carpdev pcn2 advskew 10
  LB2上也增加carp0接口:
  /etc/hostname.carp0
  inet 192.168.1.100 255.255.255.0 192.168.1.255 vhid 1 pass yourpasswd carpdev pcn2 advskew 20
  再增加内网网关的CARP接口:
  LB1上增加carp1接口:
  /etc/hostname.carp1
  inet 10.10.10.100 255.255.255.0 10.10.10.255 vhid 1 pass yourpasswd carpdev pcn2 advskew 10
  LB2上也增加carp1接口:
  /etc/hostname.carp1
  inet 10.10.10.100 255.255.255.0 10.10.10.255 vhid 1 pass yourpasswd carpdev pcn2 advskew 20
  以上carp的配置中advskew设置出了优先级别。数字越小的,获得优先级别越高,也就是最先能成为Master。
  我们要使用pf来做轮询,以下配置在LB1和LB2上都相同:
  在/etc/pf.conf中加入论询:
  ext_if="pcn0"
  sync_if="pcn2"
  web_servers = "{ 10.10.10.11, 10.10.10.12, 10.10.10.13 }"
  rdr on $ext_if proto tcp from any to any [url=http://whatis.ctocio.com.cn/searchwhatis/199/6026199.shtml]port[/url] 80 -> $web_servers round-robin sticky-[url=http://whatis.ctocio.com.cn/searchwhatis/255/6025255.shtml]address[/url]
  pass on $sync_if proto pfsync
  为了在carp生效后,一台机器失效让另一台机器接手服务时把当前的网络连接接手过去,我们需要把pf的状态表进行同步,这是通过pfsync完成的:
  为LB1和LB2增加一个做sync的接口,在/etc/hostname.pfsync0中加入
  up syncif pcn2
页: [1]
查看完整版本: [技巧]在openbsd上实现负载均衡