服務器以及軟件規劃:html
linux服務器 :3臺linux
系統版本 : centos 6.5 x86_64(1臺是lvs 調度器,安裝lvs調度軟件,2臺是RS服務器,運行web服務)web
2.IP地址規劃:apache
LVS Server: eth0:0 VIP:192.168.1.222/24 eth0 DIP:192.168.1.134/24 RS1: RS2: eth0 192.168.1.135/24 eth0 192.168.1.136/24 lo:0 192.168.1.222/32 lo:0 192.168.1.222/32
下邊開始部署安裝LVS負載均衡的DR模式。後端
1、在LB上配置VIP,安裝ipvsadm管理軟件。centos
在調度器上,配置VIP和DIP,因爲DIP已經配置好,只需配置VIP。bash
[root@LVS-LB ~]# ifconfig eth0:0 192.168.1.222 netmask 255.255.255.0 up [root@LVS-LB ~]# ifconfig eth0:0 eth0:0 Link encap:Ethernet HWaddr 00:0C:29:78:6B:94 inet addr:192.168.1.222 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
2.yum安裝ipvsadm管理軟件。服務器
[root@LVS-LB ~]# yum install -y ipvsadm [root@LVS-LB ~]# ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn [root@LVS-LB ~]# lsmod | grep ip_vs ip_vs 125220 0 libcrc32c 1246 1 ip_vs ipv6 317340 142 ip_vs,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
2、分別在兩臺後端RS上安裝apache,抑制arp,配置VIP地址。負載均衡
看下是否安裝了apache,沒有安裝的話,yum安裝一下httpd。ide
[root@RS1 ~]# rpm -qa | grep httpd
[root@RS1 ~]#
[root@RS1 ~]# yum install -y httpd
安裝完成以後,檢查下是否安裝成功。
[root@RS1 ~]# rpm -qa | grep httpd
httpd-tools-2.2.15-47.el6.centos.x86_64
httpd-2.2.15-47.el6.centos.x86_64
啓動httpd服務。
[root@RS1 ~]# /etc/init.d/httpd start
成功啓動以後,寫一個頁面到相應目錄下。
[root@RS1 ~]# echo "<h1>RS1<h1>" >/var/www/html/index.html
訪問一下,看看頁面是否能夠正常,有時候打不開,頗有多是防火牆或者selinux影響的。
一樣上述步驟,配置下RS2,此處省略,訪問rs2看網頁,出現RS2便可,以下圖所示。
2.在rs1和rs2上,作arp抑制,而後再配置VIP。
RS1上,抑制ARP,在lo網卡上,添加VIP
[root@RS1 ]# echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore [root@RS1 ]# echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce [root@RS1 ]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore [root@RS1 ]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce [root@RS1 ~]# ifconfig lo:0 192.168.1.222 netmask 255.255.255.255 up [root@RS1 ~]# ifconfig lo:0 lo:0 Link encap:Local Loopback inet addr:192.168.1.222 Mask:255.255.255.255 UP LOOPBACK RUNNING MTU:16436 Metric:1
RS2上,抑制ARP,配置VIP,在lo網卡上,添加VIP
[root@RS2 ]# echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
[root@RS2 ]# echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
[root@RS2 ]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
[root@RS2 ]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
root@RS2 ~]# ifconfig lo:0 192.168.1.222 broadcast 192.168.1.222 255.255.255.255 up
[root@RS2 ~]# ifconfig lo:0
lo:0 Link encap:Local Loopback
inet addr:192.168.1.222 Mask:255.255.255.255
UP LOOPBACK RUNNING MTU:16436 Metric:1
3、在調度器上配置lvs。
[root@LVS-LB ~]# ipvsadm -C [root@LVS-LB ~]# ipvsadm --set 30 5 60 [root@LVS-LB ~]# ipvsadm -A -t 192.168.1.222:80 -s wrr [root@LVS-LB ~]# ipvsadm -a -t 192.168.1.222:80 -r 192.168.1.135:80 -g -w 1 [root@LVS-LB ~]# ipvsadm -a -t 192.168.1.222:80 -r 192.168.1.136:80 -g -w 1 [root@LVS-LB ~]# 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.1.222:80 wrr -> 192.168.1.135:80 Route 1 0 0 -> 192.168.1.136:80 Route 1 0 0
[root@LVS-LB ~]# 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.1.222:80 wrr -> 192.168.1.135:80 Route 1 0 1 -> 192.168.1.136:80 Route 1 0 1
安裝lvs負載均衡的DR模式實驗,到此結束,謝謝你們。