分类: LINUX
2011-01-26 15:52:16
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
lvs-m# yum install ipvsadm lvs-m# yum install heartbeat-ldirectord lvs-m# yum install heartbeat
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 .
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
lvs-m# vi authkeys modfiy: #auth 1 #1 crc to: auth 1 1 crc
lvs-m# chomd 600 autkeys
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
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
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
lvs-m# vi /etc/hosts 192.168.1.221 lvs-m 192.168.1.222 lvs-s
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
Create healthcheck page in web server
web-n# echo "OKAY" > /var/www/html/.healthcheck.html
lvs-m# chkconfig heartbeat on lvs-m# service heartbeat start
lvs-s# chkconfig heartbeat on lvs-s# service heartbeat start
lvs-m# watch ipvsadm -L -n
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
lvs-m# yum install ipvsadm lvs-m# yum install heartbeat-ldirectord lvs-m# yum install heartbeat
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 .
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
lvs-m# vi authkeys modfiy: #auth 1 #1 crc to: auth 1 1 crc
lvs-m# chomd 600 autkeys
lvs-m# vi haresources Add: lvs-m IPaddr::192.168.1.220/32/eth0:0 ldirectord //lvs-m server
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"
lvs-m# vi /etc/hosts 192.168.1.221 lvs-m 192.168.1.222 lvs-s
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
Create healthcheck page in web server
web-n# echo "OKAY" > /var/www/html/.healthcheck.html
lvs-m# chkconfig heartbeat on lvs-m# service heartbeat start
lvs-s# chkconfig heartbeat on lvs-s# service heartbeat start
lvs-m# watch ipvsadm -L -n
gate -g Route LVS-DR
ipip -i Tunnel LVS-TUN
masq -m Masq LVS-NAT
web-n# lynx -dump 127.0.0.1/.healthcheck.html