PART 1
ICP在提供网络服务的时候,访客往往来自各种各样的大小ISP,比如电信、联通、移动、长宽、广电、xx通,甚至还有小区或者写字楼物业垄断下自己搞的宽带。面对这么多复杂的访问来源,如何保证服务的网络质量是内容提供商不得不面对的挑战。解决方案不外乎以下几个:
- 1. 在多个地区为用户就近部署服务器;
- 2. 选择多个网络运营商的线路接入机房,让用户选择和自己相同运营商的服务器地址;
- 3. 选择提供BGP网络的机房(包括线下机房和云服务提供商)进行托管;
- 4. 买CDN节点(广泛应用于各类下载站、VOD、直播或类似单向服务场景)。
生产环境实际部署的过程中,并不会局限于一种方案,而是将多种方案进行组合建设,即在某个/些地区架设服务器,同时接入多家运营商网络,比如广州+电信,青岛+阿里云,北京+移动+联通。
自建机房由于需要自行架设网络,所以只能采用多家运营商网络同时接入的方案;托管方案(包括云)则取决于托管机房的网络资源,条件允许的情况下,一般直接使用机房的BGP网络,条件不具备的时候才会进行多线接入。

PART 2
下面将演示如何为服务器接入多个网络并提供服务。
1. 拓扑图

- 真实服务器借助负载均衡设备为每个ISP发布一个具备独立IP的虚拟服务(本例中发布到10.1.1.2作为电信服务,发布到10.1.1.3作为联通服务);
- 由防火墙设置源地址策略,不同虚拟服务的地址出站时选择各自对应的ISP出口,这样就将一个服务发布到了多个线路上(每条线路都有一个地址);
- 客户端提供服务器地址时,有两种方式可选:
- 所有客户使用相同域名,根据客户所处的运营商网络,由DNS智能解析返回该网络下相应的发布地址;
- 所有发布地址都在客户端列出来,供客户自己选择,或测速后自动选择。
2. 配置
2.1 真实服务器
服务器IP地址为192.168.2.254,安装nginx充当真实服务器,网站首页显示访客IP。
server {
listen 80;
server_name localhost;
default_type text/html;
return 200 'USER IP: $remote_addr';
}


2.2 负载均衡器
2.2.1 配置接口IP和网关等基本网络设置
负载均衡器(pfSense)的内侧IP为192.168.2.20,外侧IP为10.1.1.4,网关为10.1.1.1。


2.2.2 配置负载均衡服务
- 添加VIP:

- 创建服务资源池(真实服务):

- 创建负载服务器(需要为电信和联通各创建一个服务,对应VIP为10.1.1.2和10.1.1.3):

2.2.3 在两个接口上配置防火墙策略,放行负载均衡器发布的服务


2.3 防火墙
2.3.1 IP设置
- WAN电信:1.1.2.10
- WAN联通:1.1.3.10
- LAN:10.1.1.1

2.3.2 添加映射(电信联通各一条)与防火墙允许策略
- 电信WAN口,映射80到10.1.1.2的80;
- 联通WAN口,映射80到10.1.1.3的80;
- 为两个接口添加映射以后,还需要建立防火墙策略放行对应两个端口。

2.3.3 策略路由
- 源地址10.1.1.3使用出接口WanUnicom;
- 源地址10.1.1.2使用出接口WanTelecom。


3 客户端测试
3.1 电信客户端(1.1.2.9)访问电信WAN口

3.2 联通客户端(1.1.3.9)访问联通WAN口
