您好,登录后才能下订单哦!
这期内容当中小编将会给大家带来有关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
将图示内容注释即可
然后再重启网卡
上述就是小编为大家分享的LVS-DR群集模式+keepalived怎么实现高可用了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。