You are on page 1of 6

node1.nhatnghe02.com [eth0:192.168.9.11] [eth1:172.16.1.1] node2.nhatnghe02.com [eth0:192.168.9.12] [eth1:172.16.1.2] node3.nhatnghe02.com [eth0:192.168.9.52] node4.nhatnghe02.com [eth0:192.168.9.

152] Trong file /etc/hosts ca node1, node2 , b sung thm tn hostname v a ch IP hai nt c th giao tip c vi nhau. 192.168.9.11 node1.nhatnghe02.com node1 192.168.9.12 node2.nhatnghe02.com node2 vip 192.168.9.27 phn 1: Ci t NLB b1: ci cc gi heartbeat package (master, slave) - Ci cc gi yum install libnet -y yum install heartbeat-* -y (chy 2 ln) yum install ipvsadm -y - Kim tra rpm qa | grep heartbeat heartbeat-2.1.3-3.el5.centos.i386.rpm heartbeat-devel-2.1.3-3.el5.centos.i386.rpm heartbeat-ldirectord-2.1.3-3.el5.centos.i386.rpm heartbeat-pils-2.1.3-3.el5.centos.i386.rpm heartbeat-stonith-2.1.3-3.el5.centos.i386.rpm chkconfig ldirectord off chkconfig heartbeat on b2:Cu hnh heartbeat (thc hin trn c 2 node) Chp cc file ha.cf, haresources, authkeys vo th mc /etc/ha.d cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/ cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/ cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/ + vi /etc/ha.d/authkeys Thm 2 dng sau: auth 1 1 sha1 123456 #chmod 600 /etc/ha.d/authkeys

;authentication ;

+ vi /etc/ha.d/ha.cf debugfile /var/log/ha-debug logfile /var/log/ha-log logfacility local0 keepalive 1 deadtime 10 warntime 5 initdead 120 udpport 694 mcast eth0 225.0.0.1 694 1 0 auto_failback off node node1.nhatnghe02.com node node2.nhatnghe02.com respawn hacluster /usr/lib/heartbeat/ipfail + vi /etc/ha.d/haresources Thm dng sau node1.nhatnghe02.com \ la active ldirectord::ldirectord.cf \ khoi dong LVSSyncDaemonSwap::master \ IPaddr2::192.168.9.27/24/eth0/192.168.9.255 B3.Cu hnh ldirectord (node1, node2) To file ldirectord.cf. c ni dung nh sau: #vi /etc/ha.d/ldirectord.cf logfile="/var/log/ldirectord.log" checktimeout=15 checkinterval=5 autoreload=no logfile="/var/log/ldirectord.log" quiescent=yes virtual=192.168.9.27:80 fallback=127.0.0.1:80 tab real=192.168.9.52:80 gate tab

;khai bao may nao ;moc ldirectord ;ip VIP.

;xoa them ;xoa them

real=192.168.9.152:80 gate them tab service=http tab request="alive.html" them tab kiem tra may con song ? receive="alive" tab scheduler=rr tab Thuat toan loadbancing roud robin persistent=600 tab protocol=tcp tab checktype=negotiate tab [root@node1 ~]# scp /etc/ha.d/* 192.168.9.27:/etc/ha.d/

;xoa ;xoa them ;xoa ;xoa them ;xoa them ;xoa them ;xoa them ;xoa them

b4: Packet Forwarding: chuyn hng cc yu cu ti real server #vi /etc/sysctl.conf net.ipv4.ip_forward = 1 #sysctl -p #service heartbeat restart #service ldirectord stop Kim tra ip [root@node1 ha.d]# ip addr sh eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:0c:29:39:29:f3 brd ff:ff:ff:ff:ff:ff inet 192.168.9.11/24 brd 192.168.9.255 scope global eth0 inet 192.168.9.27/24 brd 192.168.9.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe39:29f3/64 scope link valid_lft forever preferred_lft forever Dch v heartbeat s gi thc thi ldirectord, kim tra ldirectord:

#/usr/sbin/ldirectord ldirectord.cf status ldirectord for /etc/ha.d/ldirectord.cf is running with pid: 2954 Kim tra c ch load balancing #/sbin/ipvsadm -L n [root@node1 ~]# /sbin/ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.9.27:80 rr -> 192.168.9.52:80 Masq 0 0 0 -> 192.168.9.152:80 Masq 0 0 0 Weight : 0 0 do 2 real server cha ci t Phn 2: ci t web1, web2 - Ci httpd - Ci cc gi: arptables_jf-0.0.8-8.i386.rpm arptables-noarp-addr-0.99.2-1.rh.el.um.1.noarch.rpm My web1: #echo " <h1>web site on node3" > /var/www/html/index.html #echo "alive" >/var/www/html/alive.html ;test loadbancing My web2: #echo " <h1>web site on node4" > /var/www/html/index.html #echo "alive" >/var/www/html/alive.html ;test loadbancing #vi /etc/sysconfig/network-scripts/ifcfg-lo:0 DEVICE=lo:0 IPADDR=192.168.9.27 NETMASK=255.255.255.255 NETWORK=192.168.9.0 BROADCAST=192.168.9.255 ONBOOT=yes NAME=loopback

Chn ARP trn IP o ca cc Real1 v Real2 ( Restricting ARP Advertisments) /etc/init.d/arptables_jf stop /usr/sbin/arptables-noarp-addr 192.168.9.27 start /etc/init.d/arptables_jf save /etc/init.d/arptables_jf start /sbin/chkconfig --level 2345 arptables_jf on #service network restart #service httpd restart Phn 3: kim tra ( node1, node2) /sbin/chkconfig heartbeat on /sbin/chkconfig ldirectord off /sbin/service ldirectord stop /sbin/service heartbeat restart Trn node1 kim tra: Active [root@node1 ha.d]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.9.27:80 lblc persistent 100 -> 192.168.9.52:80 Route 1 0 0 -> 192.168.9.152:80 Route 1 0 0 [root@node1 ha.d]# Trn node2 kim tra: Passive [root@node2 ha.d]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn [root@node2 ha.d]#

Th truy cp web t my client

You might also like