CONFIG_IP_ROUTE_MULTIPATH内核选项将把所有这些路径(缺省路由)等同看待,然后再根据/usr/src/linux/Documentation/Configure.help来选择其特定的方式。Ip route命令的equalize选项,会让Linux内核基于IP地址平衡外部连接。对于一个特定的IP地址,内核会选择一个接口用于传输流出的数据包,然后内核会为该IP地址在路由缓冲中建一个记录。这样,其它到达的有相同IP地址的数据包就会使用同一个接口,直到该记录从路由缓冲中删除。我们可以使用ip route list cache命令来查看路由缓冲。
配置服务
各种不同的服务(DNS、SMTP、HTTP、LDAP、SSH等) 可以通过DNS循环来实现。减少每一个DNS记录里的TTL(存活时间),让远程系统只能缓冲IP信息30分钟。这样流入的信息就会分散在两个IP地址上。对于流入的SMTP连接,在DNS中添加了两个MX记录,这样如果一个接口关闭了,电子邮件将从另外一个接口传送。
你可以使用如下所示的dig命令来检查你的DNS配置:
> dig alphapager.org any
; <<>> DiG 8.2 <<>> alphapager.org any
;; res options: init recurs defnam dnsrch
;; got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4
;; flags: qr rd ra; QUERY: 1, ANSWER: 9, AUTHORITY: 0, ADDITIONAL: 5
;; QUERY SECTION:
;; alphapager.org, type = ANY, class = IN
;; ANSWER SECTION:
alphapager.org. 30M IN A 63.89.102.157
alphapager.org. 30M IN A 65.3.17.133
alphapager.org. 30M IN NS ns.alphapager.org.
alphapager.org. 30M IN NS ns.herdejurgen.com.
alphapager.org. 30M IN SOA proxy.alphapager.org.
root.proxy.alphapager.org. (
2001031000 ; serial
3H ; refresh
1H ; retry
1W ; expiry
30M ) ; minimum
alphapager.org. 30M IN MX 10 ns.herdejurgen.com.
alphapager.org. 30M IN MX 10 ns.alphapager.org.
;; ADDITIONAL SECTION:
ns.alphapager.org. 30M IN A 63.89.102.157
ns.herdejurgen.com. 30M IN A 65.3.17.133
;; Total query time: 98 msec
;; FROM: pandora to SERVER: default -- 192.168.100.1
;; WHEN: Sat Mar 10 22:15:22 2001
;; MSG SIZE sent: 32 rcvd: 326 |
所有的DNS记录(除了ns.alphapager.org和ns.herdejurgen.com)现在都被解析成了两个IP地址。比如:
> nslookup seann.herdejurgen.com
Server: proxy-in.alphapager.org
Address: 10.0.0.1
Name: seann.herdejurgen.com
Addresses: 65.3.17.133, 63.89.102.157 |
对于Apache,可以更改httpd.conf中的以下行来实现多个名字的虚拟主机:
NameVirtualHost 63.89.102.157:80
NameVirtualHost 65.3.17.133:80
Inbound LDAP and SSH traffic are distributed using
round-robin DNS and require no special configuration. |
启动脚本
为了支持我们的网络配置,必须对启动脚本进行一些更改。这里更改的脚本是指Red Hat的,不过我们很容易将其推广到其它的Linux发行套件。系统启动以后,ip rule命令只能被执行一次。我们可以把以下的行添加到/etc/rc.d/init.d/network脚本中来实现这一目的:
# Add non interface-specific static-rules
if [ -f /etc/sysconfig/static-rules ]; then
sh /etc/sysconfig/static-rules
fi
/etc/sysconfig/static-rules文件内容:
# Setup source IP routing rules
ip rule add from 63.89.102.157 lookup 1
ip rule add from 65.3.17.133 lookup 2
# Setup load balancing
ip route add default equalize
nexthop via 63.89.102.1 dev eth1
nexthop via 65.3.17.1 dev eth2 |
每一次对某个接口执行ifup后,都必须要执行ip route命令。我们可以在/etc/sysconfig/network-scripts/ifup-routes中添加以下行来实现该目的:
# Add any advanced routes
grep "^advanced " /etc/sysconfig/static-routes |
while read ignore dev args; do
if [ "$dev" = "$1" ]; then
/sbin/ip route add $args
fi
done
/etc/sysconfig/static-routes文件内容:
advanced eth0 10.0.0.0/24 via 10.0.0.1 table 1
advanced eth0 10.0.0.0/24 via 10.0.0.1 table 2
advanced eth1 0/0 via 63.89.102.1 table 1
advanced eth2 0/0 via 65.3.17.1 table 2 |