Keepalived+LVS(DR)

该文介绍了如何使用keepalived解决lvs的单点故障,实现高可用集群。首先在六台虚拟机上进行环境搭建,关闭NetworkManager和firewalld,设置SELINUX为disabled。然后在调度器节点上安装keepalived和ipvsadm,配置vrrp_instance和virtual_server,确保高可用性。在web节点上调整ARP参数,配置虚拟IP地址并安装httpd服务。最后,通过NFS共享存储来同步数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概述:

使用keepalived解决lvs的单点故障,实现高可用集群

开始之前准备六台虚拟机,搭建环境

systemctl stop NetworkManager

systemctl disable NetworkManager

systemctl stop firewalld

systemctl disable firewalld

setenforce 0

vim /etc/selinux/config

SELINUX=disabled

客户端ip:192.168.115.199        
keepalived+lvs1ip:192.168.115.200       
keepalived+lvs2ip:192.168.115.201       
web1ip:192.168.115.202       
web2ip:192.168.115.203       
nfs共享存储ip:192.168.115.204       

目录

一、调度器配置

二、web节点配置


一、调度器配置

1、安装keepalived、安装ipvsadm

yum install -y keepalived        安装

yum install -y ipvsadm        安装

modprobe ip_vs        加载模块

lsmod | grep ip_vs        查看模块

2、配置keepalived

global_defs {
   router_id MASTER
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    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
    #persistence_timeout 50
    protocol TCP

    real_server 192.168.115.202 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.115.203 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

global_defs {
   router_id BACKUP
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 90
    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
   # persistence_timeout 50
    protocol TCP

    real_server 192.168.115.202 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.115.203 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
3、查看lvs节点状态

ipvsadm -ln

二、web节点配置

1、调整ARP参数

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

2、配置虚拟IP地址

cp ifcfg-lo ifcfg-lo:0

vim ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.115.200
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
wq

route add -host 192.168.115.100/32 dev lo:0

3、安装httpd

yum -y install httpd

systemctl start httpd

vim /var/www/html/index.html

web1

wq

 

nfs共享存储搭建好之后安装,创建共享目录挂载到两个web节点就好了

下次见

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值