CentOS下lvs_dr方式配置

 

####################################
#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
02 #----------------------------引用文字-开始----------------------------
03 DEVICE=eth0:0
04 ONBOOT=yes
05 BOOTPROTO=static
06 IPADDR=10.0.0.252
07 NETMASK=255.255.255.0
08 EOF
09 #----------------------------引用文字-结束----------------------------
10  
11 service network restart

####################################

####################################
(3)开启路由转寄

01 vi /etc/sysctl.conf
02 #使下边这项值等于1
03 #----------------------------引用文字-结束----------------------------
04 net.ipv4.ip_forward = 1
05 #----------------------------引用文字-结束----------------------------
06  
07 sysctl -p
08 #----------------------------引用文字-开始----------------------------
09 net.ipv4.ip_forward = 1
10 net.ipv4.conf.default.rp_filter = 1
11 net.ipv4.conf.default.accept_source_route = 0
12 kernel.sysrq = 0
13 kernel.core_uses_pid = 1
14 net.ipv4.tcp_syncookies = 1
15 kernel.msgmnb = 65536
16 kernel.msgmax = 65536
17 kernel.shmmax = 68719476736
18 kernel.shmall = 4294967296
19 #----------------------------引用文字-结束----------------------------

####################################

####################################
(4)配置/etc/sysconfig/ha/lvs.cf

01 #方法一
02 cat << EOF >> /etc/sysconfig/ha/lvs.cf
03 #----------------------------引用文字-开始----------------------------
04 serial_no = 28
05 primary = 10.0.0.52
06 service = lvs
07 backup_active = 0
08 backup = 0.0.0.0
09 heartbeat = 1
10 heartbeat_port = 539
11 keepalive = 6
12 deadtime = 18
13 network = direct
14 nat_nmask = 255.255.255.0
15 debug_level = NONE
16 virtual HTTP {
17      active = 1
18      address = 10.0.0.252 eth0:1
19      vip_nmask = 255.255.255.0
20      port = 80
21      send = "GET / HTTP/1.0\r\n\r\n"
22      expect = "HTTP"
23      use_regex = 0
24      load_monitor = none
25      scheduler = wlc
26      protocol = tcp
27      timeout = 6
28      reentry = 15
29      quiesce_server = 0
30      server real_1 {
31          address = 10.0.0.231
32          active = 1
33          weight = 1
34      }
35      server real_2 {
36          address = 10.0.0.232
37          active = 1
38          weight = 1
39      }
40 }
41 EOF
42 #----------------------------引用文字-结束----------------------------
43  
44 #方法二
45 #piranha还提供了一个通过web配置lvs.cf的方式
46 #也可用浏览器打开http://primary's_ip:3636来进行配置,这需要primary安装并开启web服务
47 service httpd start
48 #打开piranha-gui
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

1 service httpd stop
2 service piranha-gui stop

#不管通过哪种方法,配置完成后启动pulse服务

1 service pulse start

####################################

四、后端的real server上的配置
####################################
(1)配置网络环境

01 #参考本文第二部分进行eth0的配置
02 #新建一个虚拟网卡配置文件ifcfg-lo:0
03 cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-lo:0
04 #----------------------------引用文字-开始----------------------------
05 DEVICE=lo:0
06 ONBOOT=yes
07 IPADDR=10.0.0.252
08 NETMASK=255.255.255.255
09 EOF
10 #----------------------------引用文字-结束----------------------------

####################################

####################################
(2)关闭arp,这一步很关键.

01 vi /etc/sysctl.conf
02 #更改以下参数
03 #----------------------------引用文字-开始----------------------------
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
09 #----------------------------引用文字-结束----------------------------
10  
11 #验证一下
12 sysctl -p
13 #----------------------------输出文字-开始----------------------------
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
21 kernel.sysrq = 0
22 kernel.core_uses_pid = 1
23 net.ipv4.tcp_syncookies = 1
24 kernel.msgmnb = 65536
25 kernel.msgmax = 65536
26 kernel.shmmax = 68719476736
27 kernel.shmall = 4294967296
28 #----------------------------输出文字-结束----------------------------
29  
30 #重启网络服务
31 service network restart

####################################

五、测试
####################################
(1)在Primary_LVS_Server上测试一下是否可以连上两台Real_Server

1 ipvsadm -l
2 #----------------------------输出文字-开始----------------------------
3 IP Virtual Server version 1.2.1 (size=4096)
4 Prot LocalAddress:Port Scheduler Flags
5   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
6 TCP  bogon:http wlc
7   -> bogon:http                   Route   1      0          0
8   -> bogon:http                   Route   1      0          0
9 #----------------------------输出文字-结束----------------------------

####################################

####################################
(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的配置

01 #新建一个虚拟网卡配置文件eth0:0
02 cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-eth0:0
03 #----------------------------引用文字-开始----------------------------
04 DEVICE=eth0:0
05 ONBOOT=yes
06 BOOTPROTO=static
07 IPADDR=10.0.0.252
08 NETMASK=255.255.255.0
09 EOF
10 #----------------------------引用文字-结束----------------------------
11  
12 service network restart

####################################

####################################
(3)开启路由转寄

01 vi /etc/sysctl.conf
02 使下边这项值等于1
03 #----------------------------引用文字-结束----------------------------
04 net.ipv4.ip_forward = 1
05 #----------------------------引用文字-结束----------------------------
06  
07 sysctl -p
08 #----------------------------引用文字-开始----------------------------
09 net.ipv4.ip_forward = 1
10 net.ipv4.conf.default.rp_filter = 1
11 net.ipv4.conf.default.accept_source_route = 0
12 kernel.sysrq = 0
13 kernel.core_uses_pid = 1
14 net.ipv4.tcp_syncookies = 1
15 kernel.msgmnb = 65536
16 kernel.msgmax = 65536
17 kernel.shmmax = 68719476736
18 kernel.shmall = 4294967296
19 #----------------------------引用文字-结束----------------------------

####################################

####################################
(4)配置/etc/sysconfig/ha/lvs.cf

01 #编辑Primary_LVS_Server上的lvs.cf
02 vi /etc/sysconfig/ha/lvs.cf
03 #----------------------------引用文字-开始----------------------------
04 serial_no = 29
05 primary = 10.0.0.52
06 service = lvs
07 backup_active = 1           #打开Backup_LVS_Server
08 backup =10.0.0.53               #设置Backup_LVS_Server的ip
09 heartbeat = 1
10 heartbeat_port = 539
11 keepalive = 6
12 deadtime = 18
13 network = direct
14 nat_nmask = 255.255.255.0
15 debug_level = NONE
16 virtual HTTP {
17      active = 1
18      address = 10.0.0.252 eth0:1
19      vip_nmask = 255.255.255.0
20      port = 80
21      send = "GET / HTTP/1.0\r\n\r\n"
22      expect = "HTTP"
23      use_regex = 0
24      load_monitor = none
25      scheduler = wlc
26      protocol = tcp
27      timeout = 6
28      reentry = 15
29      quiesce_server = 0
30      server real_1 {
31          address = 10.0.0.231
32          active = 1
33          weight = 1
34      }
35      server real_2 {
36          address = 10.0.0.232
37          active = 1
38          weight = 1
39      }
40 }
41 EOF
42 #----------------------------引用文字-开始----------------------------
43  
44 #Backup_LVS_Server把Primary_LVS_Server上的lvs.cf拷贝过来即可
45 #在Backup_LVS_Server上执行
46 scp root@10.0.0.52:/etc/sysconfig/ha/lvs.cf /etc/sysconfig/ha/lvs.cf
47  
48 #在Backup_LVS_Server启动pulse服务
49 service pulse start

####################################

八、测试Backup_LVS_Server是否能及时顶替Primary_LVS_Server
####################################
#将Primary_LVS_Server关机,用浏览器继续刷新

http://10.0.0.252

#如果正常打开,说明工作正常
####################################

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值