分类: 系统运维
2014-01-16 14:38:56
NAT的LVS负载均衡,今天来写下DR的
先来拓扑图
基本网络参数见上图
网络参数下载好以后,需要对real server进行配置,以使得real server在收到分发给自己的LVS请求之后能够以LVS router的身份对外部请求进行直接应答
配置方法有两种
非官方方案:
在real server上建立一个ifcfg-lo:1接口,参数为
#cat /etc/sysconfig/network-scripts/ifcfg:eth0:1
DEVICE=eth0:1
IPADDR=192.168.99.250
NETMASK=255.255.255.255
NETWORK=192.168.99.250
ARP=no #关键参数,它将关闭real server上正常的arp响应,所有响应由LVS Router来处理
TYPE=Ethernet
有些环境不同的,还需要修改内核一些参数,方法如下:
#vi /etc/sysctl.conf
net.ipv4.conf.eth0.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.ip_forward = 0
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
保存以后
#sysctl -p
官方方案:
real server1
安装arptables_jf
#rpm -ivh arptables_jf-0.0.8-8
#arptables -A IN -d 192.168.99.250 -j DROP
#arptables -A OUT -d 192.168.99.250 -j mangle --mangle-ip-s 192.168.99.100
real server2
安装arptables_jf
#rpm -ivh arptables_jf-0.0.8-8
#arptables -A IN -d 192.168.99.250 -j DROP
#arptables -A OUT -d 192.168.99.250 -j mangle --mangle-ip-s 192.168.99.200
然后
#service arptables_jf save
#service arptables_jf start
#chkconfig arptables_jf on
分别在两台real server加入以下内容到rc.local
/sbin/ifconfig lo:1 192.168.99.250 netmask 255.255.255.0 broadcast 192.168.99.250 up
然后重启
LVS router上的配置
选择Global Setting
Primary server public IP: 192.168.99.10 #这个是 Primary LVS Router eth0
Primary server private IP: #这个留空
Use network type: Direct Routing
然后accept
选择redundancy,enable
redundancy server public IP: 192.168.99.20 #这个是Backup LVS Router eth0
Heartbeat interval (seconds): 6 #心跳间隔
Assume dead after (seconds): 18 #如果主LVS Router 没有相应,备LVS Router会在几秒钟后启动
Heartbeat runs on port: 539 #心跳线监听端口
Monitor NIC links for failures: 不勾选
Syncdaemon: 不勾选
选择Virtual Servers
ADD,然后选中并点击EDIT
Name: HTTP
Application port: 80
Protocal: TCP
Virtual Server Address: 192.168.99.250
Virtual IP Network Mask: 255.255.255.0
Firewall Mark:
Device: eth0:1
Re-entry Time: 15
Service Timeout: 6
Quiesce server: No
Load Monitor Tool: none
Scheduling: Weighted least-connections #加权最小连接法(默认)
Persistence:
Persistence Network Mask: Unused
选择accept,然后再点击Virtual Servers,点击(de)active,激活
选择real server
ADD,然后选中并点击EDIT
Name: localhost.localdomain
Address: 192.168.99.100 #real server1 eth0
Weighted: 1
Name: localhost.localdomain
Address: 192.168.99.200 #real server2 eth0
Weighted: 1
添加以后,分别激活
最后启动服务
#service pulse start
备机也同样配置
重启pulse
#service pulse restart
然后测试是否可以访问,就ok了
下面怎么配置web和nfs共享存储,在
CentOS5.3上基于LVS的web负载均衡服务器(NAT方式)--新增使用NFS做共享存储
有详细介绍
(全文完)