pengjunling 发表于 2019-1-6 06:27:15

Linux下群集服务之lvs

O:\RHCA\群集_Cluster\Linux下群集服务之LB群集-lvs-DR模型.docx
Linux下群集服务之lvs-DR模型在企业网络中的应用案例
  案例应用拓扑图:
http://blog.运维网.com/attachment/201205/222016575.png
  案例应用实现详细步骤如下:
  一.Client-pc客户端配
http://blog.运维网.com/attachment/201205/222053115.png
  二. Director服务器配置
  2.1Director服务器ip地址配置
  # setup
http://blog.运维网.com/attachment/201205/222108346.png
http://blog.运维网.com/attachment/201205/222119764.png
  # service network restart
Shutting down interface eth0:                              
  Shutting down loopback interface:                        
  Bringing up loopback interface:                           
Bringing up interface eth0:                              

# ifconfig eth0
eth0      Link encap:EthernetHWaddr 00:0C:29:66:E1:DA
          inet addr:10.106.6.250Bcast:10.106.6.255Mask:255.255.255.0

# ifconfig eth0:0
eth0:0    Link encap:EthernetHWaddr 00:0C:29:66:E1:DA
          inet addr:10.106.6.254Bcast:10.106.6.254Mask:255.255.255.255
  # hostname director.junjie.com#注销重新登录
  2.2为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
  # route add -host 10.106.6.254 dev eth0:0
# 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服务器:
  # vim /etc/yum.repos.d/server.repo

  name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

  name=Red Hat Enterprise Linux cluster
baseurl=file:///mnt/cdrom/Cluster/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
#mkdir /mnt/cdrom
  # mount /dev/cdrom /mnt/cdrom/
  mount: block device /dev/cdrom is write-protected, mounting read-only
#yum list all
  2.4安装配置dircetor服务器:
  # yum install -y ipvsadm
# ipvsadm -ln
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port         Forward Weight ActiveConn InActConn
  # ipvsadm -A -t 10.106.6.254:80 -s rr
  # ipvsadm -a -t 10.106.6.254:80 -r 10.106.6.251 -g
  # ipvsadm -a -t 10.106.6.254:80 -r 10.106.6.252 -g
  # ipvsadm -ln                                    
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port         Forward Weight ActiveConn InActConn
TCP10.106.6.254:80 rr
  -> 10.106.6.252:80            Route   1      0          0         
  -> 10.106.6.251:80            Route   1      0          0
http://blog.运维网.com/attachment/201205/222140850.png
  # service ipvsadm save
Saving IPVS table to /etc/sysconfig/ipvsadm:               
# service ipvsadm restart
  Clearing the current IPVS table:                           
Applying IPVS configuration:                              
  三.配置real-server-1的web服务器:
  3.1 解决arp问题:
  # hostname r1.junjie.com
注销重新登录
  # echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf
  # echo "net.ipv4.conf.lo.arp_announce = 2" >> /etc/sysctl.conf
  # echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf
  # echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf
# 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地址和路由
# setup
http://blog.运维网.com/attachment/201205/222155342.png
http://blog.运维网.com/attachment/201205/222204818.png
  # service network restart
Shutting down interface eth0:                              
  Shutting down loopback interface:                        
  Bringing up loopback interface:                           
Bringing up interface eth0:                              
# ifconfig eth0
eth0      Link encap:EthernetHWaddr 00:0C:29:1B:F1:BA
          inet addr:10.106.6.251Bcast:10.106.6.255Mask:255.255.255.0

# ifconfig lo:0
lo:0      Link encap:Local Loopback
          inet addr:10.106.6.254Mask:255.255.255.255

# 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
  # route add -host 10.106.6.254 dev lo:0
# 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-1的Web服务器:
#mkdir /mnt/cdrom
# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
# 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...   ####################################
1:httpd      ###########################################
# echo "web1-- real-server-1" > /var/www/html/index.html
# 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
                                                           
3.4         客户端访问real-server-1的web服务:(桥接)
http://blog.运维网.com/attachment/201205/222226975.png
  四.配置real-server2的web服务器:
  4.1解决arp问题:
# hostname r2.junjie.com
注销重新登录
  # echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf
  # echo "net.ipv4.conf.lo.arp_announce = 2" >> /etc/sysctl.conf
  # echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf
  # echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf
# 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地址和路由
# setup
http://blog.运维网.com/attachment/201205/222418178.png
http://blog.运维网.com/attachment/201205/222428746.png
  # service network restart
Shutting down interface eth0:                              
  Shutting down loopback interface:                        
  Bringing up loopback interface:                           
Bringing up interface eth0:                              

# ifconfig eth0
eth0      Link encap:EthernetHWaddr 00:0C:29:AE:83:D1
          inet addr:10.106.6.252Bcast:10.106.6.255Mask:255.255.255.0

# ifconfig lo:0
lo:0      Link encap:Local Loopback
          inet addr:10.106.6.254Mask:255.255.255.255

# 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
  # route add -host 10.106.6.254 dev lo:0
# 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-2的Web服务器:
#mkdir /mnt/cdrom
# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
# 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...   ####################################
1:httpd      ###########################################
#echo "web2-- real-server-2" > /var/www/html/index.html l
# 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
                                                         
4.4 客户端访问real-server-2的web服务:(桥接)
http://blog.运维网.com/attachment/201205/222454842.png
五.客户端测试:
  5.1客户端访问director的群集服务服务:(网卡使用桥接模式)http://10.106.6.254
http://blog.运维网.com/attachment/201205/222506919.png
  5.2 客户端不断刷新,发现web2和web1交替出现,比率为1:1,说明依次轮询模式为RR
http://blog.运维网.com/attachment/201205/222524377.png
  5.3在director上查看信息如下:轮询调度比几乎为1:1;
  说明lvs调度方法是用的是RR模式
# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port         Forward Weight ActiveConn InActConn
TCP10.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.运维网.com/3582724/850650
  关于Linux下群集服务之LB集群-lvs-nat模式请参看我的博客:
  http://xjzhujunjie.blog.运维网.com/3582724/850866
--xjzhujunjie
--2012/05/03



页: [1]
查看完整版本: Linux下群集服务之lvs