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

相关推荐
va学弟1 小时前
Agent入门开发
java·运维·服务器·ai
014-code1 小时前
Chronicle Queue:把 Disruptor 的数据落盘
java·服务器
keyipatience1 小时前
7.Linux1权限-开发工具
linux
念何架构之路2 小时前
图解常见网络I/O复用模型
服务器·网络·php
j_xxx404_2 小时前
万字长文爆肝:彻底弄懂Linux文件系统(Ext2),从Inode、Block到Dentry核心机制全解析
linux·运维·服务器
2401_841495643 小时前
Linux C++ TCP 服务端经典的监听骨架
linux·网络·c++·网络编程·ip·tcp·服务端
Zn_lunar3 小时前
autodl tizi+codex cli
运维·服务器·网络
@insist1233 小时前
网络工程师-实战配置篇(一):深入 BGP 与 VRRP,构建高可靠网络
服务器·网络·php·网络工程师·软件水平考试
楼田莉子3 小时前
同步/异步日志系统:日志器管理器模块\全局接口\性能测试
linux·服务器·开发语言·c++·后端·设计模式
奇妙之二进制3 小时前
zmq源码分析之io_thread_t
linux·服务器