码迷,mamicode.com
首页 > 其他好文 > 详细

LVS DR 负载均衡集群

时间:2015-11-15 22:55:53      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

LVS DR 负载均衡集群

试验准备:五台主机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

技术分享

#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

技术分享

#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

技术分享

又可以访问了

LVS DR 负载均衡集群

标签:

原文地址:http://www.cnblogs.com/fengyutech/p/4967489.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!