配色: 字号:
lvs-ha
2012-08-24 | 阅:  转:  |  分享 
  
lvs负载均衡及ha高可用集群

2010-3-31wdlinux.cn制作

目录

一应用背景

二应用环境

三安装配置

四FAQ



一应用背景

随着互联网应用的普及以及人们对互联网的要求也越来越高,在流量增加的同时,要求速度快,在线时间长或出故障的时间短或故障后能及时恢复等等。为了解决这些问题,各种负载均衡及集群技术应运而生

其中,LVS便是一个解决大流量分流很好的解决方案

详细请参考http://www.linuxvirtualserver.org/zh/lvs1.html

HA(HighAvailability),则是高可用的意思,也可以说是双机热备双机等的应用。如在一些在线时间有特别的要求或是在故障后要在很短的时间内恢复,就有必要应用到这个ha了

本文的应用,由两台机组成的一个LVS及HA,主要是解决分流及单点故障。

如A,B机,正常情况下,A机为LVS转分机,同时又是提供web的服务机,当A机有问题时,B机接管A机的服务,同时自己也是一个web服务机。由于本文的应用中,机器数量有限,所以,将ha,lvs,realserver都放在一起了。在机器允许的情况下,最好分开,如:

LVS转发为独立一台机,再在这转发机上配置HA避免转发机故障,再用一台机来做转发及HA的备机,当主转发机故障时就可接管服务





二应用环境

机器两台

系统为由本人基于CentOS5.4x86_64的定制版

可以看http://www.wdlinux.cn/centos5.4_x86_64

heartbeat+ldirectord+lvs



结构如下:

VIP:192.168.1.90

Wd1192.168.1.91

Wd2192.168.1.92



三安装

1可以用源码安装,也可以用yum安装,用源码安装,定制性强一点,但用yum安装,很方便,如:

yuminstall-yheartbeat

yuminstall-yheartbeat-ldirectord

即可完成



2配置(本例的配置文件沿用1.X的风格,2.X以上的功能很强大,也较复杂)

主要的配置文件有以下几个:

Authkeys

ha.cf

ldirectord.cf

haresources



文件内容

#catauthkeys

auth1

1crc



#catha.cf

#wdlinux.cnconf

debugfile/var/log/ha-debug

logfile/var/log/ha-log

logfacilitylocal0

keepalive8

deadtime60

warntime60

initdead120

udpport694

ucasteth0192.168.1.92

auto_failbackon

nodewd1

nodewd2

respawnhacluster/usr/lib/heartbeat/ipfail

apiauthipfailgid=haclientuid=hacluster





#catldirectord.cf

#wdlinux.cnconf

checktimeout=10

checkinterval=8

fallback=127.0.0.1:80

autoreload=yes

logfile="/var/log/ldirectord.log"

logfile="local0"

quiescent=no



virtual=192.168.1.90:80

real=192.168.1.91:80gate

real=192.168.1.92:80gate

fallback=127.0.0.1:80gate

service=http

request="lt.html"

receive="TestPage"

scheduler=wrr

persistent=30

protocol=tcp

checktype=negotiate

checkport=80





#catharesources

Wd1lvsIPaddr::192.168.1.90/24/eth0:0ldirectord



wd2上的lvs脚本文件

#cat/etc/rc.d/init.d/lvs

#!/bin/bash

/sbin/ipvsadm--set101010



Wd2上的lvs脚本文件

#cat/etc/rc.d/init.d/lvs

#!/bin/bash

#wdlinux.cn

VIP=192.168.1.90

/etc/rc.d/init.d/functions

/sbin/ipvsadm--set101010

case"$1"in

start)

/sbin/ifconfiglo:0down

/sbin/ifconfigeth0:0$VIPbroadcast$VIPnetmask255.255.255.255up

/sbin/routeadd-host$VIPdeveth0:0

;;

stop)

/sbin/ifconfigeth0:0down

/sbin/ifconfiglo:0$VIPbroadcast$VIPnetmask255.255.255.255up

/sbin/routeadd-host$VIPdevlo:0

;;

)

echo"Usage:$0{start|stop}"

exit1

esac



#cat/etc/hosts

wd1

wd2

cat/etc/sysctl.conf

net.ipv4.ip_forward=1

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



在iptables增加一个对方IP的访问,否则在切换时会有问题



此文的连接:http://www.wdlinux.cn/ha-lvs-loadbalance

[我的Linux,让Linux更易用:http://www.wdlinux.cn:QQ12571192]

原创内容,转载请保留此信息

本文的pdf下载http://www.wdlinux.cn/doc/lvs负载均衡及ha高可用集群.pdf

Word版下载http://www.wdlinux.cn/doc/lvs负载均衡及ha高可用集群.doc



























我的Linux,让Linux更易用http://www.wdlinux.cn



WdLinux.cn致力于Linux服务器架构,配置,性能优化,自动化,解决方案等应用的研究2/4







献花(0)
+1
(本文系忧郁_小刚首藏)