keepalived+lvs实现高可用

目录

环境

1.配置real-server服务器

2.配置keepalived和lvs

3.测试:

概述

keepalived+lvs实现高可用:

lvs可以监控后端服务器,当服务器宕机之后可以对其进行故障切换。

keepalived是对VIP进行检测,当某一个主机的vip错误,则会将vip漂移到另一个节点上。

环境

5台主机---(两台主机--keeplived,lvs 两台主机--real-server服务器 一台主机--客户端)

1.配置real-server服务器

复制代码
后端服务器---real-serer

1.yum install -y httpd

2.编写lvs脚本
vim  /etc/init.d/lvs_rs
(脚本过长)

3.给脚本权限
chmod +x /etc/init.d/lvs_rs

4.添加为系统服务
chkconfig --add lvs_rs

4.当前启动
/etc/init.d/lvs_rs start

5.查看本机IP是否产生vip
6.配置服务器页面
echo "xxxxx" > /var/www/html/index.html

2.配置keepalived和lvs

复制代码
主备节点都需要配置
1.keepalived中自带了lvs的模块,所以下载ipvsadm后配置在keepalived的配置文件里即可
yum install -y ipvsadm
2.对于keepalived的配置之前有,这里显示keepalived中lvs的配置
vim /etc/keepalived/keepalived.conf
[root@localhost ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL1
}
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.27.135
}
}
virtual_server 192.168.27.135 80 {       设置的vip
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
real_server 192.168.27.122 80 {          后端的real-server服务器的ip
    weight 1
TCP_CHECK {
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 3
    connect_port 80
}
}
real_server 192.168.27.123 80 {
    weight 1
TCP_CHECK {
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 3
    connect_port 80
}
}
}

重新启动keepalived,检查VIP是否存在。

3.测试:

客户端使用VIP进行访问:

复制代码
for ((i=1;i<=6;i++));do curl vip ;done

返回的页面是后端不同服务器提供的页面,当real-server中的一个宕机之后,会将请求发送给另一台服务器,防止长时间请求宕机的服务器。

当前端一台keepalived宕机之后,会进行vip漂移,由另一个keepalived接管主节点上的所有服务,客户端仍然可以访问。

相关推荐
orion572 小时前
Missing Semester Class1:course overview and introduction of shell
linux
用户120487221618 小时前
Linux驱动编译与加载
linux·嵌入式
程序员老赵10 小时前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
vivo互联网技术14 小时前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
用户8055336980314 小时前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户8055336980314 小时前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
七歌杜金房1 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia2 天前
linux curl命令详解_curl详解
linux
扛枪的书生2 天前
Linux 网络管理器用法速查
linux