####################################
#lvs_dr_configuration
#Author:楚霏
#Date: 2009-08-25
#Last Update:2009-09-10
####################################
一、准备工作
####################################
环境:Centos 5.3 x86_64
所需软件:
piranha
ipvsadm
####################################
二、环境介绍
####################################
#所有机器全是Centos 5.3 x86_64
#Primary_LVS_Server
eth0参数
IPADDR=10.0.0.52
NETMASK=255.255.255.0
eth0:0参数
IPADDR=10.0.0.252
NETMASK=255.255.255.0
#Backup_LVS_Server
eth0参数
IPADDR=10.0.0.53
NETMASK=255.255.255.0
eth0:0参数
IPADDR=10.0.0.252
NETMASK=255.255.255.0
#Real_Server_1
eth0参数
IPADDR=192.168.0.231
NETMASK=255.255.255.0
lo:0参数
DEVICE=lo:0
ONBOOT=yes
IPADDR=10.0.0.252
NETMASK=255.255.255.255
#Real_Server_2
eth0参数
IPADDR=192.168.0.232
NETMASK=255.255.255.0
lo:0参数
DEVICE=lo:0
ONBOOT=yes
IPADDR=10.0.0.252
NETMASK=255.255.255.255
####################################
三、Primary_LVS_Server上的安装配置
####################################
(1)安装ipvsadm,piranha
1 | yum install ipvsadm modcluster piranha system-confi-cluster |
####################################
####################################
(2)配置网络参数
#参考本文第二部分进行eth0的配置
#新建一个虚拟网卡配置文件eth0:0
01 | cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-eth0:0 |
11 | service network restart |
####################################
####################################
(3)开启路由转寄
04 | net.ipv4.ip_forward = 1 |
09 | net.ipv4.ip_forward = 1 |
10 | net.ipv4.conf.default.rp_filter = 1 |
11 | net.ipv4.conf.default.accept_source_route = 0 |
13 | kernel.core_uses_pid = 1 |
14 | net.ipv4.tcp_syncookies = 1 |
17 | kernel.shmmax = 68719476736 |
18 | kernel.shmall = 4294967296 |
####################################
####################################
(4)配置/etc/sysconfig/ha/lvs.cf
02 | cat << EOF >> /etc/sysconfig/ha/lvs.cf |
14 | nat_nmask = 255.255.255.0 |
18 | address = 10.0.0.252 eth0:1 |
19 | vip_nmask = 255.255.255.0 |
21 | send = "GET / HTTP/1.0\r\n\r\n" |
49 | service piranha-gui start |
#打开http://primary’s_ip:3636来进行配置
#—————————-配置-开始—————————-
选择Global Setting
Primary server public IP: 10.0.0.52 #这个是 Primary LVS Router eth0
Use network type: Direct Routing
然后accept
选择Virtual Servers
ADD,然后选中并点击EDIT
Name: HTTP
Application port: 80
Protocal: TCP
Virtual Server Address: 10.0.0.252
Virtual IP Network Mask: 255.255.255.0
Device: eth0:1
Re-entry Time: 15
Service Timeout: 6
Quiesce server: No
Load Monitor Tool: none
Scheduling: Weighted least-connections #加权最小连接法(默认)
Persistence Network Mask: Unused
选择accept,然后再点击Virtual Servers,点击(de)active,激活
选择real server
ADD,然后选中并点击EDIT
Name: real_1
Address: 10.0.0.231 #Real_Server_1 eth0
Weighted: 1
Name: real_2
Address: 10.0.0.232 #Real_Server_2 eth0
Weighted: 1
添加以后,分别激活
#—————————-配置-结束—————————-
#配置完成后,安全起见,关闭web服务和piranha-gui
2 | service piranha-gui stop |
#不管通过哪种方法,配置完成后启动pulse服务
####################################
四、后端的real server上的配置
####################################
(1)配置网络环境
03 | cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-lo:0 |
08 | NETMASK=255.255.255.255 |
####################################
####################################
(2)关闭arp,这一步很关键.
04 | net.ipv4.conf.default.rp_filter = 1 |
05 | net.ipv4.conf.lo.arp_ignore = 1 |
06 | net.ipv4.conf.lo.arp_announce = 2 |
07 | net.ipv4.conf.all.arp_ignore = 1 |
08 | net.ipv4.conf.all.arp_announce = 2 |
14 | net.ipv4.ip_forward = 0 |
15 | net.ipv4.conf.default.rp_filter = 1 |
16 | net.ipv4.conf.lo.arp_ignore = 1 |
17 | net.ipv4.conf.lo.arp_announce = 2 |
18 | net.ipv4.conf.all.arp_ignore = 1 |
19 | net.ipv4.conf.all.arp_announce = 2 |
20 | net.ipv4.conf.default.accept_source_route = 0 |
22 | kernel.core_uses_pid = 1 |
23 | net.ipv4.tcp_syncookies = 1 |
26 | kernel.shmmax = 68719476736 |
27 | kernel.shmall = 4294967296 |
31 | service network restart |
####################################
五、测试
####################################
(1)在Primary_LVS_Server上测试一下是否可以连上两台Real_Server
3 | IP Virtual Server version 1.2.1 (size=4096) |
4 | Prot LocalAddress:Port Scheduler Flags |
5 | -> RemoteAddress:Port Forward Weight ActiveConn InActConn |
7 | -> bogon:http Route 1 0 0 |
8 | -> bogon:http Route 1 0 0 |
####################################
####################################
(2)在Real_Server_1和Real_Server_2上分别建不同内容的index.html
#在Real_Server_1上
echo 11111111111 >> /web根目录/index.html
#在Real_Server_2上
echo 22222222222 >> /web根目录/index.html
#在这三台服务器的任一客户端用浏览器不断刷新
http://10.0.0.252
#如果配置成功了,则说明配置成功了
####################################
六、增加一台Backup_LVS_Server
####################################
#如果需要增加一台Backup_LVS_Server,请阅读接下来的七和八这两部分
####################################
七、Backup_LVS_Server上的安装配置
####################################
(1)安装ipvsadm,piranha
1 | yum install ipvsadm modcluster piranha system-confi-cluster |
####################################
####################################
(2)配置网络参数
#参考本文第二部分进行eth0的配置
02 | cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-eth0:0 |
12 | service network restart |
####################################
####################################
(3)开启路由转寄
04 | net.ipv4.ip_forward = 1 |
09 | net.ipv4.ip_forward = 1 |
10 | net.ipv4.conf.default.rp_filter = 1 |
11 | net.ipv4.conf.default.accept_source_route = 0 |
13 | kernel.core_uses_pid = 1 |
14 | net.ipv4.tcp_syncookies = 1 |
17 | kernel.shmmax = 68719476736 |
18 | kernel.shmall = 4294967296 |
####################################
####################################
(4)配置/etc/sysconfig/ha/lvs.cf
02 | vi /etc/sysconfig/ha/lvs.cf |
14 | nat_nmask = 255.255.255.0 |
18 | address = 10.0.0.252 eth0:1 |
19 | vip_nmask = 255.255.255.0 |
21 | send = "GET / HTTP/1.0\r\n\r\n" |
46 | scp root@10.0.0.52:/etc/sysconfig/ha/lvs.cf /etc/sysconfig/ha/lvs.cf |
####################################
八、测试Backup_LVS_Server是否能及时顶替Primary_LVS_Server
####################################
#将Primary_LVS_Server关机,用浏览器继续刷新
http://10.0.0.252
#如果正常打开,说明工作正常
####################################