Linux LVS+Heartbeat

來源:互聯網
上載者:User
Linux叢集-LVS(DR)+Heartbeat

LVS+Heartbeat

 

 

LVS1和LVS2所完成一樣的工作,那麼配置指令碼也相同。唯一不同的是heartbeat設定檔ha.cf心跳地址不同。

真實的web,mysql,ftp……配置一樣

LVS配置

 #!/bin/bash

 ######lvs######

 ifconfig eth0:0 222.90.88.88 broadcast 222.90.88.88 netmask 255.255.255.255 up

 route add -host 222.90.88.88 dev eth0:0

 ipvsadm -C

 ipvsadm -A -t 222.90.88.88:80 -s rr

 ipvsadm -a -t 222.90.90.88.88:80 -r 222.90.88.10 -g

 ipvsadm -a -t 222.90.90.88.88:80 -r 222.90.88.20 -g

 ipvsadm

Web配置

 #!/bin/bash

 ######real server######

 ifconfig lo:0 222.90.88.88 broadcast 222.90.88.88 netmask 255.255.255.255 up

 route add -host 222.90.88.88 dev lo:0

 ######ipvsadm######

 echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore

 echo “2” > /proc/sys/net/ipv4/conf/lo/arp_announce

 echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore

 echo “2” > /proc/sys/net/ipv4/conf/all/arp_announce

 sysctl -p

 

操作:

 四台LINUX主機(LVS1,LVS2和SEV1,SEV2)

 LVS1安裝heartbeat

  #rpm -ivh heartbeat-pils-2.1.3-3.el5.centos.i386.rpm

  #rpm -ivh heartbeat-stonith-2.1.3-3.el5.centos.i386.rpm

  #rpm -ivh heartbeat-2.1.3-3.el5.centos.i386.rpm

 #rpm -q heartbeat -d(解壓檔案)

 #cd /usr/share/docheartbeat-2.1.3/

 #cp authkeys ha.cf haresources /etc/ha.d

 #cd /etc/ha.d

 #vim authkeys 

  ……

auth 1

  1 crc

  ……

 #vim /haresources

  ……

  vip-server1 222.90.88.88 vip.sh(LVS1,vip.sh存放在/etc/init.d[開機時自啟])

  ……

 #vim /ha.cf

  …….

  bcast eth0 #Linux (心跳檢測網卡)

  …….

  ucast eth0 222.90.88.40 (ping  LVS2)

  …….

  node vip-server1  (LVS1機器名)

  node vip-server2  (LVS2機器名)

  …….

 #chmod 600 authkeys

 #vim /etc/init.d/vip.sh

  #!/bin/sh

  ifconfig eth0:0 222.90.88.88 broadcast 222.90.88.88 netmask 255.255.255.255 up

  route add -host 222.90.88.88 dev eth0:0

  ######setup ipvs######

  ipvsadm -C

  ipvsadm -A -t 222.90.88.88:80 -s rr

  ipvsadm -a -t 222.90.88.88:80 -r 222.90.88.10 -g

  ipvsadm -a -t 222.90.88.88:80 -r 222.90.88.20 -g

  ipvsadm

 #chmod 777 vip.sh

 #/etc/init.d/vip.sh

 

  LVS2安裝heartbeat

  #rpm -ivh heartbeat-pils-2.1.3-3.el5.centos.i386.rpm

  #rpm -ivh heartbeat-stonith-2.1.3-3.el5.centos.i386.rpm

  #rpm -ivh heartbeat-2.1.3-3.el5.centos.i386.rpm

 #rpm -q heartbeat -d(解壓檔案)

 #cd /usr/share/docheartbeat-2.1.3/

 #cp authkeys ha.cf haresources /etc/ha.d

 #cd /etc/ha.d

 #vim authkeys 

  ……

auth 1

  1 crc

  ……

 #vim /haresources

  ……

  vip-server1 222.90.88.88 vip.sh(LVS1,vip.sh存放在/etc/init.d[開機時自啟])

  ……

 #vim /ha.cf

  …….

  bcast eth0 #Linux (心跳檢測網卡)

  …….

  ucast eth0 222.90.88.30 (ping  LVS1)

  …….

  node vip-server1  (LVS1機器名)

  node vip-server2  (LVS2機器名)

  …….

 #chmod 600 authkeys

 #vim /etc/init.d/vip.sh

  #!/bin/sh

  ifconfig eth0:0 222.90.88.88 broadcast 222.90.88.88 netmask 255.255.255.255 up

  route add -host 222.90.88.88 dev eth0:0

  ######setup ipvs######

  ipvsadm -C

  ipvsadm -A -t 222.90.88.88:80 -s rr

  ipvsadm -a -t 222.90.88.88:80 -r 222.90.88.10 -g

  ipvsadm -a -t 222.90.88.88:80 -r 222.90.88.20 -g

  ipvsadm

 #chmod 777 vip.sh

 #/etc/init.d/vip.sh

 

 SER1操作

 #vim /etc/init.d/lvs.sh

  #!/bin/sh

  ######realserver######

  ifconfig lo:0 222.90.88.88 broadcast 222.90.88.88 netmask 255.255.255.255 up

  route add -host 222.90.88.88 dev lo:0

  echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore

  echo “2” > /proc/sys/net/ipv4/conf/lo/arp_announce

  echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore

  echo “2” > /proc/sys/net/ipv4/conf/all/arp_announce

  sysctl -p

 #vim /var/www/html/index.html

  this is SER1

 #service httpd start

 

SER2操作

 #vim /etc/init.d/lvs.sh

  #!/bin/sh

  ######realserver######

  ifconfig lo:0 222.90.88.88 broadcast 222.90.88.88 netmask 255.255.255.255 up

  route add -host 222.90.88.88 dev lo:0

  echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore

  echo “2” > /proc/sys/net/ipv4/conf/lo/arp_announce

  echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore

  echo “2” > /proc/sys/net/ipv4/conf/all/arp_announce

  sysctl -p

 #vim /var/www/html/index.html

  this is SER2

 #service httpd start

 

測試故障狀態

 LVS2heartbeat停止,LVS1正常;SER1,SER2正常

 LVS1 heartbeat停止,LVS2正常;SER1,SER2正常

 LVS1正常,LVS2正常;SER1不正常,SER2正常

 LVS1正常,LVS2正常;SER1正常,SER2不正常

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.