Linux-利用keepalived实现lvs的高可用性
单主模型IPVS示例
配置keepalive
高可用的ipvs集群示例:修改keepalived配置文件
修改主机:192.168.234.27的keepalived配置文件
1 [root@234c27 ~]# vim /etc/keepalived/keepalived.conf
2 ! Configuration File for keepalived
3
4 global_defs {
5 notification_email {
6 root@localhost //接受邮件地址
7 }
8 notification_email_from keepalived@localhost //发送邮件地址
9 smtp_server 127.0.0.1 //发送邮件服务器IP
10 smtp_connect_timeout 30 //邮件连接超时时长
11 router_id kptwo //路由id
12 vrrp _mcast_group4 234.10.10.10 //指定vrrp协议的多播地址
13 }
14
15 vrrp_instance VI_1 { //vrrp协议的
16 state MASTER //lvs的MASTER服务器
17 interface ens37 //
18 virtual_router_id 50 //虚拟路由
19 priority 100 //权重为100.越大越先
20 advert_int 1 //发送组博包的间隔
21 authentication { //验证
22 auth_type PASS //方式为pass( 明文)
23 auth_pass 1111 //密码
24 }
25 virtual_ipaddress { //keepalived虚拟ip
26 10.0.0.100/24
27 }
28 }
29 virtual_server 10.0.0.100 80 {
30 delay_loop 6 //检查后端服务器的时间间隔
31 lb_algo wrr //定义调度方法
32 lb_kind DR //集群的类型
33 #persistence_timeout 50 //持久连接时长
34 protocol TCP //服务协议,仅支持TCP
35 real_server 192.168.234.47 80 { //后端real_server服务器地址
36 weight 1 //权重
37 HTTP_GET { //应用层检测
38 url {
39 path / //定义要监控的URL
40 status_code 200 //判断上述检测机制为健康状态的响应码
41 }
42 connect_timeout 3 //连接请求的超时时长
43 nb_get_retry 3 //重试次数
44 delay_before_retry 3 //重试之前的延迟时长
45 }
46 }
47 real_server 192.168.234.57 80 {
48 weight 2
49 HTTP_GET {
50 url {
51 path /
52 status_code 200
53 }
54 connect_timeout 3
55 nb_get_retry 3
56 delay_before_retry 3
57 }
58 }
59 }
修改主机:192.168.234.37的keepalived配置文件
[root@234c37 ~]# vim /etc/keepalived/keepalived.conf! Configuration File for keepalived global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id kptwo
vrrp _mcast_group4 234.10.10.10
} vrrp_instance VI_1 {
state BACKUP
interface ens37
virtual_router_id 50
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100/24
}
}
virtual_server 10.0.0.100 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
#persistence_timeout 50
protocol TCP
sorry_server 127.0.0.1:80
real_server 192.168.234.47 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.234.57 80 {
weight 2
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
查看keepalived
[root@234c37 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: inactive (dead)
…………
[root@234c37 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
//暂无ipvsadm
启动服务
[root@234c27 keepalived]# systemctl start keepalived.service
[root@234c27 keepalived]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2018-08-31 20:30:02 CST; 12s ago
Process: 9657 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 9658 (keepalived)
………………
[root@234c27 keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.0.0.100:80 wrr
-> 192.168.234.47:80 Route 1 0 0
-> 192.168.234.57:80 Route 2 0 0
//启动服务lvs vs已配置好
后端real_server准备
增加ip在网卡上 修改限制arp通告及应答级别 rs1 rs2都做,网关并指向路由
ip a a 10.0.0.100/32 dev ens37 echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announceroute add default gw 192.168.234.17
安装httpd服务 写好网页文件
启动服务
多主模型IPVS示例
配置keepalive
高可用的ipvs集群示例:修改keepalived配置文件
修改主机:192.168.234.27的keepalived配置文件
[root@234c27 keepalived]# vim /etc/keepalived/keepalived.conf
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id kpone
vrrp _mcast_group4 234.10.10.10
} vrrp_instance VI_1 {
state MASTER
interface ens37
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100/24
}
}
vrrp_instance VI_2 {
state BACKUP
interface ens37
virtual_router_id 51
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
10.0.0.200/24
}
}
virtual_server 10.0.0.100 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
#persistence_timeout 50
protocol TCP
#sorry_server 127.0.0.1:80
real_server 192.168.234.47 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 10.0.0.200 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
#persistence_timeout 50
protocol TCP
#sorry_server 127.0.0.1:80
real_server 192.168.234.57 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
修改主机:192.168.234.37的keepalived配置文件
[root@234c37 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id kptwo
vrrp _mcast_group4 234.10.10.10
} vrrp_instance VI_1 {
state BACKUP
interface ens37
virtual_router_id 50
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100/24
}
}
vrrp_instance VI_2 {
state MASTER
interface ens37
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
10.0.0.200/24
}
}
virtual_server 10.0.0.100 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
#persistence_timeout 50
protocol TCP
#sorry_server 127.0.0.1:80
real_server 192.168.234.47 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 10.0.0.200 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
#persistence_timeout 50
protocol TCP
#sorry_server 127.0.0.1:80
real_server 192.168.234.57 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
让10.0.0.100的ip优先分配至192.168.234.47 192.168.234.57备用
让10.0.0.200的ip优先分配至192.168.234.57 192.168.234.47备用
后端real_server准备
修改192.168.234.57的vip为10.0.0.200/32
1 [root@234c27 keepalived]# ipvsadm -Ln
2 IP Virtual Server version 1.2.1 (size=4096)
3 Prot LocalAddress:Port Scheduler Flags
4 -> RemoteAddress:Port Forward Weight ActiveConn InActConn
5 TCP 10.0.0.100:80 wrr
6 -> 192.168.234.47:80 Route 1 0 0
7 TCP 10.0.0.200:80 wrr
8 -> 192.168.234.57:80 Route 1 0 0
现在宕掉一个lvs
1 [root@234c27 keepalived]# systemctl stop keepalived.service
2 [root@234c27 keepalived]# ipvsadm -Ln
3 IP Virtual Server version 1.2.1 (size=4096)
4 Prot LocalAddress:Port Scheduler Flags
5 -> RemoteAddress:Port Forward Weight ActiveConn InActConn
6
依然提供服务
1 [root@234c37 ~]# ipvsadm -Ln
2 IP Virtual Server version 1.2.1 (size=4096)
3 Prot LocalAddress:Port Scheduler Flags
4 -> RemoteAddress:Port Forward Weight ActiveConn InActConn
5 TCP 10.0.0.100:80 wrr
6 -> 192.168.234.47:80 Route 1 0 21
7 TCP 10.0.0.200:80 wrr
8 -> 192.168.234.57:80 Route 1 0 39
后一个实现基于前一个的基础上修改来的
假设要实现sorry_server
1.把rs服务都停掉。然后在lvs上安装apache或者nginx服务
2.将keepalived配置文件中的
1 virtual_server 10.0.0.200 80 {
2 delay_loop 6
3 lb_algo wrr
4 lb_kind DR
5 #persistence_timeout 50
6 protocol TCP
7 #sorry_server 127.0.0.1:80 //这一行来修改 写出服务出错之后的页面
8 real_server 192.168.234.57 80 {
9 weight 1
10 HTTP_GET {
11 url {
12 path /
13 status_code 200
14 }
15 connect_timeout 3
16 nb_get_retry 3
17 delay_before_retry 3
18 }
19 }
20 }
Linux-利用keepalived实现lvs的高可用性的更多相关文章
- Linux中keepalived+LVS负载均衡的搭建测试
1.1 LVS简介 LVS(Linux Virtual Server),也就是Linux虚拟服务器, 是一个自由软件项目.使用LVS技术要达到的目标是:通过LVS提供的负载均衡技术和Lin ...
- 基于VMware的虚拟Linux集群搭建-lvs+keepalived
基于VMware的虚拟Linux集群搭建-lvs+keepalived 本文通过keepalived实现lvsserver的的双机热备和真实server之间的负载均衡.这方面的blog挺多,可是每一个 ...
- Linux学习系列之lvs+keepalived
LVS简介 LVS介绍 LVS是Linux Virtual Server的缩写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统,属于4层负载均衡 ipvs和ipvsadm的关系 我们使用配置LV ...
- Linux集群服务 LVS
linux虚拟服务器(LVS)项目在linux操作系统上提供了最常见的负载均衡软件. 集群定义: 集群(cluster)技术是一种较新的技术,通过集群技术,可以在付出较低成本的情况下获得在性能.可靠性 ...
- keepalived给LVS带来了什么
LVS+Keepalived 1>Keepalived简介 Keepalived是Linux下一个轻量级别的高可用解决方案,高可用(High Avalilability,HA),其实两种不同的 ...
- Linux负载均衡软件LVS简介
Linux负载均衡软件LVS LVS集群的体系结构以及特点 1. LVS简介 LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起 ...
- MySQL HA方案之MySQL半复制+MHA+Keepalived+Atlas+LVS[转]
MySQL HA方案之MySQL半复制+MHA+Keepalived+Atlas+LVS 简介 目前Mysql高可用的方案有好多,比如MMM,heartbeat+drbd,Cluster等,还有per ...
- Linux下Keepalived安装与配置
一.简介 负载平衡是一种在真实服务器集群中分配IP流量的方法,可提供一个或多个高度可用的虚拟服务.在设计负载均衡拓扑时,重要的是要考虑负载均衡器本身的可用性以及它背后的真实服务器.用C编写的类似于la ...
- linux高级技巧:heartbeat+lvs
linux高级技巧:heartbeat+lvs Heartbeat 项目是 Linux-HA 工程的一个组成部分,它实现了一个高可用集群系统.心跳服务和集群通信是高可用集群的两个关键组件,在 He ...
随机推荐
- javascript的学习笔记---复习及学习
1.javascript包含三大部分(BOM,DOM,ECMAscript) ECMAscript:规定js的语法规范 BOM:Document Object Model 给我们提供了一套完整的操作页 ...
- Jquery | 基础 | .hover()
https://api.jquery.com/hover/#hover-handlerIn-handlerOut http://jquery.cuishifeng.cn/hover.html
- java利用myeclipse自带三大框架搭建三大框架(Hibernate+Struts2+Spring)过程详解
搭建过程因人而异,我的搭建过程大致是这样的: 1.创建一个javaweb项目: 2.导入Spring框架,上图: 2.1: 2.2: 2.3: 3.导入struts2框架,上图: 3.1: 3.2: ...
- Codeforces 1139E(二分图最大匹配)
pi只有0-5000且只找最小的没出现的,又要找不同club的,考虑二分匹配,左边pi,右边ci,一个匹配一个.离线倒着加边即可. const int maxn = 5e3 + 5; int m, n ...
- vue 中的router 配置问题 导致的内存溢出~~~
最近的项目用到 vue, 各种踩坑中. 其中一个就是router映射表写的稍有不慎,就会出现内存溢出的问题, 而且也不会具体告诉你哪里出错,所以很是头疼~~~ 出错多了,发现了一些router的一些规 ...
- [已读]精通AngularJS
觉得可以看第二遍,内容其实还不错啦,就是翻译会有点生硬.
- 牛客网Java刷题知识点之什么是JSP、JSP有哪些优点、JSP的9大内置对象、JSP的四大域对象、JSP的四种范围
不多说,直接上干货! https://www.nowcoder.com/ta/review-java/review?tpId=31&tqId=21175&query=&asc= ...
- xml和TreeView
1.TreeView代码代码: private void Form1_Load(object sender, EventArgs e) {<br> //代码为TreeView添加子项 tr ...
- mybatis内置二级缓存。
一.查询缓存的使用,主要是为了提供查询访问速度.将用户对同一数据的重复查询过程简化, 不再每次均从数据库查询获取结果数据,从而提高访问速度. 二.内置二级缓存... 由于MyBatista从缓存中读取 ...
- Java——HashSet和TreeSet的区别
HashSetHashSet有以下特点 不能保证元素的排列顺序,顺序有可能发生变化 不是同步的 集合元素可以是null,但只能放入一个null当向HashSet集合中存入一个元素时,HashSe ...