网站建设资讯

NEWS

网站建设资讯

LVS-DR群集模式+keepalived怎么实现高可用

这期内容当中小编将会给大家带来有关LVS-DR群集模式+keepalived怎么实现高可用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

按需策划可以根据自己的需求进行定制,做网站、网站设计构思过程中功能建设理应排到主要部位公司做网站、网站设计的运用实际效果公司网站制作网站建立与制做的实际意义

条件:五台虚拟机:

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

(主)负载调度器:

创建映射端口(VIP)

LVS-DR群集模式+keepalived怎么实现高可用

优化环境:(/etc/sysctl.conf)

LVS-DR群集模式+keepalived怎么实现高可用

net.ipv4.conf.all.send_redirects = 0

net.ipv4.conf.default.send_redirects = 0

net.ipv4.conf.eth0.send_redirects = 0

sysctl -p

加载ip_vs模块

modprobe ip_vs

查看ipvs

cat /proc/net/ip_vs

安装IPVS

yum install -y ipvsadm

查看版本:

ipvsadm -v

设置负载调度器设置模式

ipvsadm -A -t 192.168.115.100:80 -s rr

ipvsadm -a -t 192.168.115.100:80 -r 192.168.115.173:80 -g(173和176分别指向两个RS)

ipvsadm -a -t 192.168.115.100:80 -r 192.168.115.176:80 -g

查看:

ipvsadm -Ln

安装keepalived

yum install -y gcc*  kernel-devel openssl-devel popt-devel ipvsadm

tar -xvf keepalived-1.2.7.tar.gz

./configure --prefix=/  --with-kernel-dir=/usr/src/kernels/2.6.32-131.0.15.el6.i686

make && make install

chkconfig --add keepalived

chkconfig keepalived on

LVS-DR群集模式+keepalived怎么实现高可用

配置keepalived文件:

LVS-DR群集模式+keepalived怎么实现高可用

启动服务:

service keepalived start

chkconfig keepalived on

共享资源服务器

搭建NFS给RS挂在使用

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

RS1:

安装Apache服务

配置本地回环端口映射:

LVS-DR群集模式+keepalived怎么实现高可用

设置一条路由:

route add -host 192.168.115.100 dev lo:0

优化环境:

LVS-DR群集模式+keepalived怎么实现高可用

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

RS2:

安装Apache服务,将内容从NFS服务器上面挂在过来:

mount -t nfs 192.168.115.177:/share /var/www/html

设置映射网卡:

LVS-DR群集模式+keepalived怎么实现高可用

优化环境:

LVS-DR群集模式+keepalived怎么实现高可用

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

net.ipv4.conf.default.arp_announce = 2

net.ipv4.conf.default.arp_ignore = 1

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

设置路由:

设置一条路由:

route add -host 192.168.115.100 dev lo:0

测试机访问:

每刷新一次,内容一次轮询:

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

下面搭建基于keepalived的LVS-DR

增加一个虚拟机作为从负载调度器:

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

加载ip_vs模块

modprobe ip_vs

查看ipvs

cat /proc/net/ip_vs

安装IPVS

yum install -y ipvsadm

查看版本:

ipvsadm -v

设置负载调度器设置模式

ipvsadm -A -t 192.168.115.100:80 -s rr

ipvsadm -a -t 192.168.115.100:80 -r 192.168.115.173:80 -g(173和176分别指向两个RS)

ipvsadm -a -t 192.168.115.100:80 -r 192.168.115.176:80 -g

查看:

ipvsadm -Ln

LVS-DR群集模式+keepalived怎么实现高可用

优化环境:

LVS-DR群集模式+keepalived怎么实现高可用

net.ipv4.conf.all.send_redirects = 0

net.ipv4.conf.default.send_redirects = 0

net.ipv4.conf.eth0.send_redirects = 0

安装keepalived

yum install -y gcc*  kernel-devel openssl-devel popt-devel ipvsadm

tar -xvf keepalived-1.2.7.tar.gz

./configure --prefix=/  --with-kernel-dir=/usr/src/kernels/2.6.32-131.0.15.el6.i686

make && make install

chkconfig --add keepalived

chkconfig keepalived on

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

service keepalived start

chkconfig keepalived on

测试机测试:

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

LVS-DR群集模式+keepalived怎么实现高可用

从服务器成功接替工作:实验成功:

配置文件模板:

! Configuration File for keepalived

global_defs {

  router_id LVS_R1

}

vrrp_instance VI_1 {

   state MASTER

   interface eth0

   virtual_router_id 51

   priority 100

   advert_int 1

   authentication {

       auth_type PASS

       auth_pass 1111

   }

   virtual_ipaddress {

       192.168.115.100

   }

}

virtual_server 192.168.115.100 80 {

   delay_loop 6

   lb_algo rr

   lb_kind DR

   protocol TCP

   real_server 192.168.115.173 80 {

       weight 1

               TCP_CHECK {

                       connect_port 80

                       connect_timeout 3

                       nb_get_retry 3

                       delay_before_retry 3

       }

       }

  real_server 192.168.115.176 80 {

       weight 1

               TCP_CHECK {

                       connect_port 80

                       connect_timeout 3

                       nb_get_retry 3

                       delay_before_retry 3

       }

       }

   }

在做从负载调度器的时候,因为有两个网卡公用一个地址,这样启动网卡的时候会报错

解决办法:

vim /etc/sysconfig/network-scripts/ifup-eth

LVS-DR群集模式+keepalived怎么实现高可用

将图示内容注释即可

然后再重启网卡

上述就是小编为大家分享的LVS-DR群集模式+keepalived怎么实现高可用了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。


当前名称:LVS-DR群集模式+keepalived怎么实现高可用
链接地址:http://njwzjz.com/article/joiicg.html