设为首页 收藏本站
查看: 1699|回复: 0

[经验分享] Linux下群集服务之lvs

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2019-1-6 06:27:15 | 显示全部楼层 |阅读模式
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.运维网.com/3582724/850650
  关于Linux下群集服务之LB集群-lvs-nat模式请参看我的博客:
  http://xjzhujunjie.blog.运维网.com/3582724/850866
--xjzhujunjie

--2012/05/03





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-659771-1-1.html 上篇帖子: LVS:三种负载均衡方式(VS/NAT、VS/TUN、VS/DR)比较 下篇帖子: 服务器群集及web服务器负载均衡Lvs
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表