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接管主节点上的所有服务,客户端仍然可以访问。

相关推荐
布莱克60517 小时前
Swift 类详解:从定义、继承到内存管理的完整指南
服务器·开发语言·ios·ssh·swift·类
布莱克60520 小时前
Swift 方法详解:实例方法、类型方法与 mutating 机制
服务器·开发语言·ios·ssh·swift·方法
时间的拾荒人20 小时前
Linux 系统命令与网络、磁盘、日志监控(下篇):性能原理与优化
linux·运维·网络
金色熊族20 小时前
qt5.15.9编译qt-creator7.0.2源码
linux·qt
Rabitebla21 小时前
【Linux】文件篇(五):手撕简易 FILE——模拟实现 C 标准 I/O 缓冲机制
linux·服务器·c语言·笔记·学习·ubuntu
蜗牛一步步往上爬21 小时前
第十章 使用编辑器
linux
无足鸟ICT1 天前
【RHCA+】swap和物理内存
linux
zly35001 天前
esxi安装 windows2000 鼠标不动
运维·服务器
LabVIEW开发1 天前
Ethernet/IP 会话无效 -251723770
服务器·网络协议·tcp/ip
Huangjin007_1 天前
【Linux 系统篇(四十一)】线程(二):线程的优缺点、资源共享与上下文切换
linux·运维·服务器