LVS DR 負載均衡集羣

LVS DR 負載均衡集羣 html

試驗準備:五臺主機ABCDE,主機ABCDE均爲單網卡,IP地址分別爲192.168.10.2,192.168.10.3,192.168.10.4,192.168.10.5,192.168.10.6。主機A做爲內網客戶端,主機B負載均衡調度器,主機C和主機D做爲網站服務器,主機E做爲共享存儲,均清除防火牆和SELINUX。操做系統均爲RHELx86_64,爲最小化安裝。 面試

  1. 主機A操做

#vim /etc/sysconfig/network-scripts/ifcfg-eth0 vim

#service network restart 瀏覽器

  1. 主機B操做

#vim /etc/sysconfig/network-scripts/ifcfg-eth0 服務器

#cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0 負載均衡

#service network restart curl

#vim /etc/sysctl.conf 工具

net.ipv4.conf.all.send_redirects=0 測試

net.ipv4.conf.default.send_redirects=0 網站

net.ipv4.conf.eth0.send_redirects=0

#sysctl –p

#modprobe ip_vs

#cat /proc/net/ip_vs

#cd /mnt/cdrom/Packets

#rpm –ivh ipvsadm-1.25-10.el6.x86_64.rpm

#service ipvsadm stop #這個命令會清除原來設定的規則

#ipvsadm –A –t 192.168.10.10:80 –s rr

#ipvsadm –a –t 192.168.10.10:80 –r 192.168.10.4:80 –g

#ipvsadm –a –t 192.168.10.10:80 –r 192.168.10.5:80 –g

#service ipvsadm save

  1. 主機E操做

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

#service network restart

#rpm –qa | grep nfs

#vim /etc/exports

#mkdir /share

#cd /share

#vim index.html

www.taobao.com

#service rpcbind start

注:RHEL6以後,portmap的啓動方式改了,必須啓動,不然nfs會報錯

#servie nfs start

#chkconfig rpcbind on

#chkcofig nfs on

#yum -y install showmount #安裝showmount命令

#showmount –e 192.168.10.6

#exportfs –rv

  1. 主機C操做

#yum –y install httpd

#service httpd start

#chkconfig httpd on

#yum –y install showmount

#showmount –e 192.168.10.6

#mount 192.168.10.6:/share /var/www/html

#curl 192.168.10.4

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

#cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0

#vim /etc/sysconfig/network-scripts/ifcfg-lo:0

#vim /etc/sysctl.conf

net.ipv4.conf.all.arp_ignore=1

net.ipv4.conf.all.arp_announce=2

net.ipv4.conf.default.arp_ignore=1

net.ipv4.conf.default.arp_announce=2

net.ipv4.conf.lo.arp_ignore=1

net.ipv4.conf.lo.arp_announce=2

#route add –host 192.168.10.10 dev lo:0

#vim /etc/rc.d/rc.local

/sbin/route add –host 192.168.10.10 dev lo:0

  1. 主機D操做

#yum –y install httpd

#service httpd start

#chkconfig httpd on

#yum –y install showmount

#showmount –e 192.168.10.6

#vim /var/www/html/index.html #爲了便於下面的測試,因此用不一樣網頁

www.baidu.com

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

#cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0

#vim /etc/sysconfig/network-scripts/ifcfg-lo:0

#vim /etc/sysctl.conf

net.ipv4.conf.all.arp_ignore=1

net.ipv4.conf.all.arp_announce=2

net.ipv4.conf.default.arp_ignore=1

net.ipv4.conf.default.arp_announce=2

net.ipv4.conf.lo.arp_ignore=1

net.ipv4.conf.lo.arp_announce=2

#route add –host 192.168.10.10 dev lo:0

#vim /etc/rc.d/rc.local

/sbin/route add –host 192.168.10.10 dev lo:0

#ipvsadm –Ln

主機B操做:

  1. 測試

在瀏覽器輸入curl 192.168.10.10

能夠知道主機C和主機D交互出現。

  1. LVS+keeplived實現服務器的高可用
  1. keepalived概述

    爲LVS和HA設計的一款健康狀態工具;

    支持故障自動切換(Failover);

    支持節點健康狀態檢查(Health Checking);

  2. keepalived的熱備方式

    VRRP(Virtual Router Redundancy Protocol,虛擬路由冗餘協議)--主+多備,共用同一個IP地址,但優先級不一樣。

  3. lvs+keepalived

    負載均衡+高可用集羣,針對Lvs調度器實現雙機熱備,可以管理服務器池,自動隔離失效節點

4.實現LVS+keepalived實現高可用集羣

試驗在上面試驗的基礎上,在加上一臺服務器做爲從調度器,IP地址爲192.168.10.7

  1. 配置從調度器安裝ipvs

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

#cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0

#/etc/sysconfig/network-scripts/ifcfg-eth0:0

若是這個時候啓動會出現以下問題

解決方法:

#vim /etc/sysconfig/network-scripts/ifup-eth

243-246這幾行註釋掉

主調度器也要作上面的操做,而後啓動eth0:0

#ifup eth0

#ifup eth0:0

#vim /etc/sysctl.conf

net.ipv4.conf.all.send_redirects=0

net.ipv4.conf.default.send_redirects=0

net.ipv4.conf.eth0.send_redirects=0

#sysctl –p

#modprobe ip_vs

#cat /proc/net/ip_vs

#cd /mnt/cdrom/Packets

#rpm –ivh ipvsadm-1.25-10.el6.x86_64.rpm

#service ipvsadm stop #這個命令會清楚原來設定的規則

#ipvsadm –A –t 192.168.10.10:80 –s rr

#ipvsadm –a –t 192.168.10.10:80 –r 192.168.10.4:80 –g

#ipvsadm –a –t 192.168.10.10:80 –r 192.168.10.5:80 –g

#service ipvsadm save

  1. 主調度器安裝keepalived

#yum –y intall kernel-devel openssl-devel popt-devel

#tar xf keepalived-1.2.2.tar.gz

#cd keepalived-1.2.2

#./configure –prefix=/ –with-kernel-dir=/usr/sr/kernels/2.6.32-358.el6.x86_64/

#make && make install

#vim /etc/keepalived/keepalived.conf

#service keepalived start

#chkconfig –add keepalived

#chkconfig keepalived on

#vim /etc/sysconfig/network-scripts/ifup-eth

243-246這幾行註釋掉

#ifup eth0

#ifup eth0:0

  1. 從調度器安裝keepalived

#yum –y intall kernel-devel openssl-devel popt-devel

#tar xf keepalived-1.2.2.tar.gz

#cd keepalived-1.2.2

#./configure –prefix=/ –with-kernel-dir=/usr/sr/kernels/2.6.32-358.el6.x86_64/

#make && make install

#vim /etc/keepalived/keepalived.conf

#service keepalived start

#chkconfig –add keepalived

#chkconfig keepalived on

5.測試是否能夠高可用

①從主機A看一下負載的效果

②把主調度器的eth0 down

#ifdown eth0

從主機A查看效果

網站仍然能夠訪問

  1. 把從調度器的eth0 down掉

#ifdown eth0

在訪問網站

啓動主調度器的eth0網卡

#ifup eth0

又能夠訪問了

相關文章
相關標籤/搜索