基于LVS-DR群集模式+keepalived实现高可用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于LVS-DR群集模式+keepalived实现高可用相关的知识,希望对你有一定的参考价值。
条件:五台虚拟机:
(主)负载调度器:
创建映射端口(VIP)
优化环境:(/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
加载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
配置keepalived文件:
启动服务:
service keepalived start
chkconfig keepalived on
共享资源服务器:
搭建NFS给RS挂在使用
RS1:
安装Apache服务
配置本地回环端口映射:
设置一条路由:
route add -host 192.168.115.100 dev lo:0
优化环境:
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
设置映射网卡:
优化环境:
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
测试机访问:
每刷新一次,内容一次轮询:
下面搭建基于keepalived的LVS-DR
增加一个虚拟机作为从负载调度器:
加载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
优化环境:
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
service keepalived start
chkconfig keepalived on
测试机测试:
从服务器成功接替工作:实验成功:
配置文件模板:
! 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
将图示内容注释即可
然后再重启网卡
本文出自 “Change life Start fresh.” 博客,请务必保留此出处http://ahcwy.blog.51cto.com/9853317/1940298
以上是关于基于LVS-DR群集模式+keepalived实现高可用的主要内容,如果未能解决你的问题,请参考以下文章