Linux下羣集服務之lvs-DR模型在企業網絡中的應用案例

 O:\RHCA\羣集_Cluster\Linux下羣集服務之LB羣集-lvs-DR模型.docx

Linux下羣集服務之lvs-DR模型在企業網絡中的應用案例

案例應用拓撲圖:

案例應用實現詳細步驟如下:

一.Client-pc客戶端配

二. Director服務器配置

2.1  Director服務器ip地址配置

[root@junjie ~]# setup

[root@junjie ~]# service network restart

Shutting down interface eth0:                              [  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:                                [  OK  ]
 
[root@junjie ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:66:E1:DA 
          inet addr:10.106.6.250  Bcast:10.106.6.255  Mask:255.255.255.0
 
[root@junjie ~]# ifconfig eth0:0
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:66:E1:DA 
          inet addr:10.106.6.254  Bcast:10.106.6.254  Mask:255.255.255.255

[root@junjie ~]# hostname director.junjie.com  #註銷重新登錄

2.2  director添加路由

[root@director ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.106.6.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0

0.0.0.0         10.106.6.254    0.0.0.0         UG    0      0        0 eth0

[root@director ~]# route add -host 10.106.6.254 dev eth0:0

[root@director ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.106.6.254    0.0.0.0         255.255.255.255 UH    0      0        0 eth0

10.106.6.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0

0.0.0.0         10.106.6.254    0.0.0.0         UG    0      0        0 eth0 2.3  配置本地yum服務器:

[root@director ~]# vim /etc/yum.repos.d/server.repo

[rhel-server]

name=Red Hat Enterprise Linux server

baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-cluster]

name=Red Hat Enterprise Linux cluster

baseurl=file:///mnt/cdrom/Cluster/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[root@director ~]#mkdir /mnt/cdrom

[root@director ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@director ~]#yum list all

2.4  安裝配置dircetor服務器:

[root@director ~]# yum install -y ipvsadm

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

[root@director ~]# ipvsadm -A -t 10.106.6.254:80 -s rr

[root@director ~]# ipvsadm -a -t 10.106.6.254:80 -r 10.106.6.251 -g

[root@director ~]# ipvsadm -a -t 10.106.6.254:80 -r 10.106.6.252 -g

[root@director ~]# ipvsadm -ln                                    

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  10.106.6.254:80 rr

  -> 10.106.6.252:80              Route   1      0          0        

  -> 10.106.6.251:80              Route   1      0          0

[root@director ~]# service ipvsadm save

Saving IPVS table to /etc/sysconfig/ipvsadm:               [  OK  ]
[root@director ~]# service ipvsadm restart

Clearing the current IPVS table:                           [  OK  ]

Applying IPVS configuration:                               [  OK  ]

三.配置real-server-1web服務器:

3.1 解決arp問題:

[root@junjie ~]# hostname r1.junjie.com

註銷重新登錄

[root@r1 ~]# echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf

[root@r1 ~]# echo "net.ipv4.conf.lo.arp_announce = 2" >> /etc/sysctl.conf

[root@r1 ~]# echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf

[root@r1 ~]# echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf

[root@r1 ~]# sysctl -p
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1

3.2  配置ip地址和路由

[root@r1 ~]# setup

[root@r1 ~]# service network restart

Shutting down interface eth0:                              [  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:                                [  OK  ]
[root@r1 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:1B:F1:BA 
          inet addr:10.106.6.251  Bcast:10.106.6.255  Mask:255.255.255.0
 
[root@r1 ~]# ifconfig lo:0
lo:0      Link encap:Local Loopback 
          inet addr:10.106.6.254  Mask:255.255.255.255
 
[root@r1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.106.6.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0

0.0.0.0         10.106.6.254    0.0.0.0         UG    0      0        0 lo

[root@r1 ~]# route add -host 10.106.6.254 dev lo:0

[root@r1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.106.6.254    0.0.0.0         255.255.255.255 UH    0      0        0 lo

10.106.6.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0

0.0.0.0         10.106.6.254    0.0.0.0         UG    0      0        0 lo

 

3.3         配置Real-server-1Web服務器:

[root@r1 ~]#mkdir /mnt/cdrom

[root@r1 ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@r1 ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm

warning: /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

Preparing...   #################################### [100%]

1:httpd      ########################################### [100%]

[root@r1 ~]# echo "web1  -- real-server-1" > /var/www/html/index.html

[root@r1 ~]# service httpd start

Starting httpd: httpd: apr_sockaddr_info_get() failed for r1.junjie.com

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

                                                           [  OK  ]

3.4         客戶端訪問real-server-1web服務:(橋接)

四.配置real-server2web服務器:

4.1  解決arp問題:

[root@junjie ~]# hostname r2.junjie.com
註銷重新登錄

[root@r2 ~]# echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf

[root@r2 ~]# echo "net.ipv4.conf.lo.arp_announce = 2" >> /etc/sysctl.conf

[root@r2 ~]# echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf

[root@r2 ~]# echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf

[root@r2 ~]# sysctl -p
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1

4.2  配置ip地址和路由

[root@r2 ~]# setup

[root@r2~]# service network restart

Shutting down interface eth0:                              [  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:                                [  OK  ]
 
[root@r2 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:AE:83:D1 
          inet addr:10.106.6.252  Bcast:10.106.6.255  Mask:255.255.255.0
 
[root@r2 ~]# ifconfig lo:0
lo:0      Link encap:Local Loopback 
          inet addr:10.106.6.254  Mask:255.255.255.255
 
[root@r2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.106.6.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0

0.0.0.0         10.106.6.254    0.0.0.0         UG    0      0        0 lo

[root@r2 ~]# route add -host 10.106.6.254 dev lo:0

[root@r2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.106.6.254    0.0.0.0         255.255.255.255 UH    0      0        0 lo

10.106.6.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0

0.0.0.0         10.106.6.254    0.0.0.0         UG    0      0        0 lo

 

4.3  配置Real-server-2Web服務器:

[root@r2 ~]#mkdir /mnt/cdrom

[root@r2 ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@r2 ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm

warning: /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

Preparing...   #################################### [100%]

1:httpd      ########################################### [100%]

[root@r2 ~]#echo "web2  -- real-server-2" > /var/www/html/index.html l

[root@r2 ~]# service httpd start

Starting httpd: httpd: apr_sockaddr_info_get() failed for r2.junjie.vom

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

                                                           [  OK  ]

4.4 客戶端訪問real-server-2web服務:(橋接)

五.客戶端測試:

5.1  客戶端訪問director的羣集服務服務:(網卡使用橋接模式)http//10.106.6.254

5.2 客戶端不斷刷新,發現web2和web1交替出現,比率爲1:1,說明依次輪詢模式爲RR

5.3在director上查看信息如下:輪詢調度比幾乎爲1:1;

說明lvs調度方法是用的是RR模式

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  10.106.6.254:80 rr

  -> 10.106.6.251:80              Route   1      0          14       

  -> 10.106.6.252:80              Route   1      0          14

 《完》

關於Linux下集羣服務簡介和lvs的詳解請參看我的博客:

http://xjzhujunjie.blog.51cto.com/3582724/850650

關於Linux下羣集服務之LB集羣-lvs-nat模式請參看我的博客:

http://xjzhujunjie.blog.51cto.com/3582724/850866

--xjzhujunjie

--2012/05/03

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章