重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍“LINUX中Keepalive+lvs主从dr负载均衡怎么实现”,在日常操作中,相信很多人在LINUX中Keepalive+lvs主从dr负载均衡怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”LINUX中Keepalive+lvs主从dr负载均衡怎么实现”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创新互联公司专注于郑州企业网站建设,响应式网站设计,成都商城网站开发。郑州网站建设公司,为郑州等地区提供建站服务。全流程按需开发网站,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务
1.1.1配置本地yum源
#mkdir /media/cdrom //创建cdrom目录
#mkdir /etc/yum.repo.d/a //在yum源目录中创建a目录
#mv /etc/yum.repo.d/Cent* /etc/yum.repo.d/a //将以Cent开头的所有文件拷贝到a目录
#mount /dev/cdrom /media/cdrom //将光盘挂载到/media/cdrom/目录下
#vim /etc/yum.repo.d/local.repo //编辑本地yum源文件
[base]
name=cets
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
#yum –y install openssl-devel //使用yum源安装openssl-devel软件
#yum –y install popt-devel //使用yum源安装popt-devel软件
#tar zxf keepalived-1.2.13.tar.gz //解压keepalived软件包
#cd keepalived-1.2.13 //进入解压的文件夹中
#./configure -prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64 //编译指定安装路径
#make && make install //编译和安装keepalived
本机ip 192.168.1.1
#cd /etc/keepalived/ //进入keepalived软件主目录
#cp keepalived.conf keepalived.conf.bak //备份keepalived主配置文件
#vim keepalived.conf //编辑keepalived主配置文件
router_id r1 //给该keepalived主机取名
state MASTER //该keepalived主机类型为主
priority 100 //优先级100
virtual_ipaddress {
192.168.1.254} //虚拟ip地址
#service keepalived restart //重启服务
#service iptables stop //关闭防火墙
#service network restart //重启网卡
本机ip 192.168.1.5
router_id r2
state SL**E 备注:也可以使用BACKUP
priority 99
virtual_ipaddress {
192.168.1.254}
Ip地址192.168.1.110
Service iptables stop
测试登陆192.168.1.25
关闭防火墙
开启httpd
重启keepalive
编辑测试网页#vim /var/www/html/index.html
down掉主服务在测试机在访问 192.168.1.254
关闭防火墙
开启httpd
重启keepalive
#ip addr show dev eth0 查看虚拟接口
编辑测试网页#vim /var/www/html/index.html
router_id r1
state MASTER
priority 100
virtual_ipaddress {
192.168.1.254}
virtual_server 192.168.1.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.11 80 {
weight 1
TCP_CHECK {
connect-port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}}
}
virtual_server 192.168.1.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.22 80 {
weight 1
TCP_CHECK {
connect-port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}}
}
1.本地yum
2.安装支持keepalive软件包
3.编译安装keepalive
4.修改配置文件并启用keepalive
复制备份 cp keepalive.conf keepalive.conf.bak
本机ip 192.168.1.5
router_id r2
state SL**E
priority 99
virtual_ipaddress {
192.168.1.254}
virtual_server 192.168.1.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.11 80 {
weight 1
TCP_CHECK {
connect-port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}}
}
5.安装ipvsadm
yum –y install ipvsadm
ipvsadm –Lnc /Ln
192.168.1.11
#cd /etc/sysconfig/network-scripts
#cp ifcfg-lo ifcfg-lo:0
#vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.254
NETMASK=255.255.255.255
ONBOOT=yes
重启服务service network restart
酌情添加
vi /etc/rc.local //添加VIP本地访问路由
/sbin/route add -host 192.168.1.254 dev lo:0
# route add -host 192.168.1.254 dev 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
sysctl -p
vi /var/www/html/index.html
# service httpd start
# chkconfig httpd on
192.168.1.22
#cd /etc/sysconfig/network-scripts
#cp ifcfg-lo ifcfg-lo:0
#vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.254
NETMASK=255.255.255.255
ONBOOT=yes
重启服务service network restart
酌情添加
vi /etc/rc.local //添加VIP本地访问路由
/sbin/route add -host 192.168.1.254 dev lo:0
# route add -host 192.168.1.254 dev 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
sysctl -p
vi /var/www/html/index.html
# service httpd start
# chkconfig httpd on
配置ip 192.168.1.110
关闭防火墙能与其他主机通信
登陆192.168.1.254
主 ipvsadm -Ln
Down掉主keepalive
在登陆
登陆成功节点1 down点 在测试节点2
到此,关于“LINUX中Keepalive+lvs主从dr负载均衡怎么实现”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!