Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1441562
  • 博文数量: 77
  • 博客积分: 2104
  • 博客等级: 大尉
  • 技术积分: 2322
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-19 13:21
个人简介

关注于系统高可用、网站架构

文章分类

全部博文(77)

文章存档

2018年(1)

2017年(1)

2015年(4)

2014年(8)

2013年(4)

2012年(12)

2011年(17)

2010年(30)

分类:

2010-09-05 19:17:09

LVS部署两台,为Active/standby模式
安装步骤:
yum install ipvsadm -y
yum install piranha -y

1.       Lvs.cf modification

[root@LVS-S src]# vi /etc/sysconfig/ha/lvs.cf

service = lvs

primary = 192.168.1.190

primary_private = 172.16.0.190                               //lvs 主服务器心跳地址

backup_active = 1

backup = 192.168.1.1.191                                    //lvs 备服务器心跳地址

backup_private = 172.16.0.191

heartbeat = 1

heartbeat_port = 539

keepalive = 4

deadtime = 12

debug_level = NONE

rsh_command = ssh

network = direct

#Tcp port 80 for portal

virtual portal1v1 {

        active = 1

        address = 192.168.1.100 eth0:1

        vip_nmask = 255.255.255.0

        port = 80

        persistent = 1800

        pmask = 255.255.255.255

        send = "GET /iwl/.lvs.html\n"

        expect = "OK"

        load_monitor = none

        scheduler = wlc

        protocol = tcp

        timeout = 5

        reentry = 10

        quiesce_server = 0

        server potral1 {

                address = 192.168.1.10

                active = 1

                weight = 100

        }

        server potral2 {

                address = 192.168.1.11

                active = 1

                weight = 100

        }

        server potral3 {

                address = 192.168.1.12

                active = 1

                weight = 100

        }

}

virtual portal1v2 {

        active = 1

        address = 192.168.2.100 eth1:1

        vip_nmask = 255.255.255.0

        port = 80

        persistent = 1800

        pmask = 255.255.255.255

        send = "GET /iwl/.lvs.html\n"

        expect = "OK"

        load_monitor = none

        scheduler = wlc

        protocol = tcp

        timeout = 5

        reentry = 10

        quiesce_server = 0

        server potral1 {

                address = 192.168.2.10

                active = 1

                weight = 100

        }

        server potral2 {

                address = 192.168.2.11

                active = 1

                weight = 100

        }

        server potral3 {

                address = 192.168.2.12

                active = 1

                weight = 100

        }

}

virtual portal1v3 {

        active = 1

        address = 192.168.3.100 eth2:1

        vip_nmask = 255.255.255.0

        port = 80

        persistent = 1800

        pmask = 255.255.255.255

        send = "GET /iwl/.lvs.html\n"

        expect = "OK"

        load_monitor = none

        scheduler = wlc

        protocol = tcp

        timeout = 5

        reentry = 10

        quiesce_server = 0

        server potral1 {

                address = 192.168.3.10

                active = 1

                weight = 100

        }

        server potral2 {

                address = 192.168.3.11

                active = 1

                weight = 100

        }

        server potral3 {

                address = 192.168.3.12

                active = 1

                weight = 100

        }

}

:wq!                                                      //”Esc”键输入”:wq!”保存退出

 

2客户端配置
所有客户端添加
 vi /etc/sysctl.conf

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

最后保存sysctl  –p  

root@portal1 ~]# vi /etc/rc.local

#!/bin/sh

……

………..

ifconfig lo:0 192.168.1.100 broadcast 192.168.1.100 netmask 255.255.255.255 up   //增加此行

ifconfig lo:1 192.168.2.100 broadcast 192.168.2.100 netmask 255.255.255.255 up   //增加此行

ifconfig lo:2 192.168.3.100 broadcast 192.168.3.100 netmask 255.255.255.255 up   //增加此行

:wq!                                                      //”Esc”键输入”:wq!”保存退出

[root@portal1 ~]# sh ./etc/rc.d/rc.local                         //执行rc.local脚本,使回环地址生效,注意如果重启网络回环地址会消失,因此需要重新执行此脚本,切记.

root@portal1 iwl.war]# vi /infowarelab/apache2/conf/uriworkermap.properties

# uriworkermap.properties

….

……..

/iwl/.lvs.html=jboss                                        //添加此行

 

cp -r /infowarelab/jboss/server/default/deploy/jboss-web.deployer/ROOT.war /infowarelab/jboss/server/default/deploy/iwl.war

[root@portal1 ~]#cd /infowarelab/jboss/server/default/deploy/iwl.war/

[root@portal1 iwl.war]#cat > .lvs.html <

OK

EOF                                                      //回车,重启apachejboss进程

[root@portal1 ~]# GET

OK                                                       //返回”OK”值说明配置成功

 

LVS常用命令

pulse命令:

/etc/init.d/pulse start

                  /restart

                  /stop

                  /status 查看lvs状态

                  {pulse (pid 27089) is running..}

查看当前的lvs转发状态列表:

ipvsadm -Ln

-L      list以列表的方式输出

-n        numeric显示地址和端口

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  192.168.1.100:80 wlc persistent 1800

  -> 192.168.1.10:80                 Route   100    1          66       

  -> 192.168.1.11:80                 Route   100    1          97       

  -> 192.168.1.12:80                 Route   100    1          97  

watch ipvsadm Ln      查看实时状态

 

经验分享

1、机房无法实时刷新MAC,LVS+Heartbeat方案无法正常随机切换IP

假如两台VS之间使用的互备关系,那么当一台VS接管LVS服务时,可能会网络不通,这时因为路由器的MAC缓存表里无法及时刷新MAC.关于vip这个地址的MAC地址还是替换的VS的MAC,有两种解决方法,一种是修改新VS的MAC地址,另一种是使用send_arp /arping命令.

【注】最好让机房调整路由MAC缓存表的刷新频率;

以arping命令为例.
/sbin/arping -I eth0 -c 3 -s ${vip}${gateway_ip} > /dev/null 2>&1
Eg:
/sbin/arping -I eth0 -c 3 -s 192.168.1.6192.168.1.1

阅读(2725) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~