Chinaunix首页 | 论坛 | 博客
  • 博客访问: 266064
  • 博文数量: 53
  • 博客积分: 2580
  • 博客等级: 少校
  • 技术积分: 509
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-29 10:02
文章分类

全部博文(53)

文章存档

2014年(1)

2013年(1)

2011年(14)

2010年(37)

我的朋友

分类: LINUX

2011-01-26 15:52:16

LVS with DR mode

1、Servers environment

System: CentOS 5.2
lvs-m : 192.168.1.221

lvs-s : 192.168.1.222

web-1 : 192.168.1.2

web-2 : 192.168.1.3

VIP : 192.168.1.220

2、Install related softwares

lvs-m# yum install ipvsadm
lvs-m# yum install heartbeat-ldirectord
lvs-m# yum install heartbeat
  • The above operations also need implement on lvs-s.

3、Configure LVS

lvs-m# cd /etc/ha.d
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/ha.cf .
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/authkeys .
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/haresources .
lvs-m# cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf .
  • The above operations also need implement on lvs-s.

4、Configure HA

lvs-m# vi ha.cf

modfiy:

#logfile        /var/log/ha-log
#keepalive 2
#deadtime 30
#warntime 10
#initdead 120
#udpport        694
#bcast   eth0            # Linux
ucast eth0 192.168.1.2
#node    ken3
#node    kathy
#ping 10.10.10.254

to:

logfile        /var/log/ha-log
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport        694
bcast   eth0            # Linux
ucast eth0 192.168.1.222    //lvs-s's IP
node    lvs-m           # the node name must same as the output of "uname -n"
node    lvs-s           # the node name must same as the output of "uname -n"
ping 192.168.1.222    //lvs-s's IP
  • The above operations also need implement on lvs-s.
  • Attention the ip address.

5、Configure auth mode

lvs-m# vi authkeys
modfiy:

#auth 1
#1 crc

to:

auth 1
1 crc
lvs-m# chomd 600 autkeys
  • The above operations also need implement on lvs-s.

6、Configure virtual Service

lvs-m# vi haresources

Removin all then add following line:
lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord     //here, node lvs-m works as master
  • the lvs-s server as follows:
lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord     //here, node lvs-m works as master
If we configure them work as master/master mode, and the vip on lvs-s is 192.168.1.230, the configuration in both haresources files as follows:
lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord
lvs-s IPaddr::192.168.1.230/32/eth0:0   ldirectord

Add following lines to /etc/sysctl.conf

net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
net.ipv4.conf.eth0.arp_ignore = 0
net.ipv4.conf.eth0.arp_announce = 0
and change "net.ipv4.ip_forward = 0" to "net.ipv4.ip_forward = 1"
lvs-m# sysctl -p
  • The above operations also need implement on lvs-s.
  • On Web server
web-n# vi /root/vip.sh
Add:
################################################################################
# Virtual IP Setup
################################################################################

ifconfig lo:0 192.168.1.220 broadcast 192.168.1.220 netmask 255.255.255.255 up
route add -host 192.168.1.220 dev lo:0

################################################################################
# The end
################################################################################
web-n# chmod a+x /root/vip.sh
web-n# echo "/root/vip.sh" >> /etc/rc.local

And add the following lines to /etc/sysctl.conf on web server

net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
web-n# sysctl -p

7、Configure hosts

lvs-m# vi /etc/hosts
192.168.1.221   lvs-m
192.168.1.222   lvs-s
  • The above operations also need implement on lvs-s.

8、Configure ldirectord

lvs-m# vi ldirectord.cf

Add:

checktimeout=3
checkinterval=1
autoreload=yes
quiescent=no

virtual=192.168.1.220:80
   real=192.168.1.2:80 gate 1 ".healthcheck.html", "OKAY"
   real=192.168.1.3:80 gate 1 ".healthcheck.html", "OKAY"
   fallback=127.0.0.1:80 gate 1 ".healthcheck.html", "OKAY"
   service=http
   request=".healthcheck.html"
   receive="Test Page"
   scheduler=rr
   protocol=tcp
   persistent = 600
  • The above operations also need implement on lvs-s.

Create healthcheck page in web server

web-n# echo "OKAY" > /var/www/html/.healthcheck.html

9、Start heartbeat

lvs-m# chkconfig heartbeat on
lvs-m# service heartbeat start
lvs-s# chkconfig heartbeat on
lvs-s# service heartbeat start

10、Check ipvsadm status

lvs-m# watch ipvsadm -L -n

LVS with NAT mode

1、Servers environment

lvs-m : eth0:192.168.1.221
        eth1:172.16.1.1

lvs-s : eth0:192.168.1.222
        eht1:172.16.1.254

web-1 : eth0:172.16.1.2   //gw:172.16.1.1

web-2 : eth0:172.16.1.3   //gw:172.16.1.1

VIP : 192.168.1.220

2、Install related softwares

lvs-m# yum install ipvsadm
lvs-m# yum install heartbeat-ldirectord
lvs-m# yum install heartbeat
  • The above operations also need implement on lvs-s.

3、Configure LVS

lvs-m# cd /etc/ha.d
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/ha.cf .
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/authkeys .
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/haresources .
lvs-m# cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf .
  • The above operations also need implement on lvs-s.

4、Configure HA

lvs-m# vi ha.cf

modfiy:

#logfile        /var/log/ha-log
#keepalive 2
#deadtime 30
#warntime 10
#initdead 120
#udpport        694
#bcast   eth0            # Linux
ucast eth0 192.168.1.2
#node    ken3
#node    kathy
#ping 10.10.10.254

to:

logfile        /var/log/ha-log
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport        694
bcast   eth0            # Linux
ucast eth0 192.168.1.222    //lvs-s's IP
node    lvs-m           # uname -n
node    lvs-s           # uname -n
ping 192.168.1.222    //lvs-s's IP
  • The above operations also need implement on lvs-s.
  • Attention the ip address.

5、Configure auth mode

lvs-m# vi authkeys
modfiy:

#auth 1
#1 crc

to:

auth 1
1 crc
lvs-m# chomd 600 autkeys
  • The above operations also need implement on lvs-s.

6、Configure virtual Service

lvs-m# vi haresources

Add:

lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord     //lvs-m server
  • the lvs-s server as follows:
lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord

Add following lines to /etc/sysctl.conf

net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
net.ipv4.conf.eth0.arp_ignore = 0
net.ipv4.conf.eth0.arp_announce = 0
and change "net.ipv4.ip_forward = 0" to "net.ipv4.ip_forward = 1"
  • The above operations also need implement on lvs-s.

7、Configure hosts

lvs-m# vi /etc/hosts
192.168.1.221   lvs-m
192.168.1.222   lvs-s
  • The above operations also need implement on lvs-s.

8、Configure ldirectord

lvs-m# vi ldirectord.cf

Add:

checktimeout=3
checkinterval=1
autoreload=yes
quiescent=no

virtual=192.168.1.220:80
   real=172.16.1.2:80 gate 1 ".healthcheck.html", "OKAY"
   real=172.16.1.3:80 gate 1 ".healthcheck.html", "OKAY"
   fallback=127.0.0.1:80 gate 1 ".healthcheck.html", "OKAY"
   service=http
   request=".healthcheck.html"
   receive="Test Page"
   scheduler=rr
   protocol=tcp
   persistent = 600
  • The above operations also need implement on lvs-s.

Create healthcheck page in web server

web-n# echo "OKAY" > /var/www/html/.healthcheck.html

9、Start heartbeat

lvs-m# chkconfig heartbeat on
lvs-m# service heartbeat start
lvs-s# chkconfig heartbeat on
lvs-s# service heartbeat start

10、Check ipvsadm status

lvs-m# watch ipvsadm -L -n

Some useful notes

  • LVS forwarding:

gate -g Route LVS-DR

ipip -i Tunnel LVS-TUN

masq -m Masq LVS-NAT

  • Check the healthcheck page
web-n# lynx -dump 127.0.0.1/.healthcheck.html
阅读(2018) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~