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,为最小化安装。
- 主机A操作
#vim /etc/sysconfig/network-scripts/ifcfg-eth0
#service network restart
- 主机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
- 主机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
- 主机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
- 主机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 #为了便于下面的测试,所以用不同网页
#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操作:
- 测试
在浏览器输入curl 192.168.10.10
可以知道主机C和主机D交互出现。
- LVS+keeplived实现服务器的高可用
- keepalived概述
为LVS和HA设计的一款健康状态工具;
支持故障自动切换(Failover);
支持节点健康状态检查(Health Checking);
- keepalived的热备方式
VRRP(Virtual Router Redundancy Protocol,虚拟路由冗余协议)--主+多备,共用同一个IP地址,但优先级不同。
- lvs+keepalived
负载均衡+高可用集群,针对Lvs调度器实现双机热备,能够管理服务器池,自动隔离失效节点
4.实现LVS+keepalived实现高可用集群
试验在上面试验的基础上,在加上一台服务器作为从调度器,IP地址为192.168.10.7
- 配置从调度器安装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
- 主调度器安装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
- 从调度器安装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查看效果
网站仍然可以访问
- 把从调度器的eth0 down掉
#ifdown eth0
在访问网站
启动主调度器的eth0网卡
#ifup eth0
又可以访问了