单主模型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的高可用性的更多相关文章

  1. Linux中keepalived+LVS负载均衡的搭建测试

    1.1 LVS简介       LVS(Linux Virtual Server),也就是Linux虚拟服务器, 是一个自由软件项目.使用LVS技术要达到的目标是:通过LVS提供的负载均衡技术和Lin ...

  2. 基于VMware的虚拟Linux集群搭建-lvs+keepalived

    基于VMware的虚拟Linux集群搭建-lvs+keepalived 本文通过keepalived实现lvsserver的的双机热备和真实server之间的负载均衡.这方面的blog挺多,可是每一个 ...

  3. Linux学习系列之lvs+keepalived

    LVS简介 LVS介绍 LVS是Linux Virtual Server的缩写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统,属于4层负载均衡 ipvs和ipvsadm的关系 我们使用配置LV ...

  4. Linux集群服务 LVS

    linux虚拟服务器(LVS)项目在linux操作系统上提供了最常见的负载均衡软件. 集群定义: 集群(cluster)技术是一种较新的技术,通过集群技术,可以在付出较低成本的情况下获得在性能.可靠性 ...

  5. keepalived给LVS带来了什么

    LVS+Keepalived 1>Keepalived简介  Keepalived是Linux下一个轻量级别的高可用解决方案,高可用(High Avalilability,HA),其实两种不同的 ...

  6. Linux负载均衡软件LVS简介

    Linux负载均衡软件LVS LVS集群的体系结构以及特点 1. LVS简介        LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起 ...

  7. MySQL HA方案之MySQL半复制+MHA+Keepalived+Atlas+LVS[转]

    MySQL HA方案之MySQL半复制+MHA+Keepalived+Atlas+LVS 简介 目前Mysql高可用的方案有好多,比如MMM,heartbeat+drbd,Cluster等,还有per ...

  8. Linux下Keepalived安装与配置

    一.简介 负载平衡是一种在真实服务器集群中分配IP流量的方法,可提供一个或多个高度可用的虚拟服务.在设计负载均衡拓扑时,重要的是要考虑负载均衡器本身的可用性以及它背后的真实服务器.用C编写的类似于la ...

  9. linux高级技巧:heartbeat+lvs

    linux高级技巧:heartbeat+lvs   Heartbeat 项目是 Linux-HA 工程的一个组成部分,它实现了一个高可用集群系统.心跳服务和集群通信是高可用集群的两个关键组件,在 He ...

随机推荐

  1. bzoj3427:[POI2013]BAJ-Bytecomputer

    传送门 很显然有一个结论:最大不过1,最小不过-1 然后dp,设\(f[i][j]\)为满足前\(i\)个不下降,当前放的是\(j-2\),转移就比较好想了 具体方程看代码吧,终于有一个自己会写的题了 ...

  2. 多线程:『GCD』详尽总结

    本文用来介绍 iOS 多线程中 GCD 的相关知识以及使用方法.这大概是史上最详细.清晰的关于 GCD 的详细讲解+总结的文章了.通过本文,您将了解到:1. GCD 简介2. GCD 任务和队列3. ...

  3. springMVC-接收数据-参数绑定

    接收数据-参数绑定 #Method Arguments概观 Same in Spring WebFlux The table below shows supported controller meth ...

  4. selenium登录 京东滑动验证码

    京东的滑动验证码在页面上是没有原图的,所有我是用ps把他们拼成一个的. from selenium import webdriver from selenium.webdriver import Ac ...

  5. TDH-hbase shell 常用命令

    一.HBASE shell 命令操作;1.建表: create ‘tableName’,'f1','f2'; 注:列簇,裂限定符都要尽量短: 2.插入数据: put 'tableName','RowK ...

  6. Semi-prime H-numbers

    题目描述形如4n+1的数被称为“H数”,乘法在“H数”集合内为封闭的.因数只有1和本身的数叫“H素数”(不包括1),其余叫“H合数”.一个“H合成数”能且只能分解为两个“H素数”.求0·h内的“H合成 ...

  7. I/O————缓存流

    为什么要使用缓存流? 当对磁盘访问次数多的时候,字节流和字符流就会感觉性能不佳,速度较慢. 缓存流,一次会读取很多的数据到缓存中,以后每一次读取都是从缓存中读取,直到缓存中数据读取完,这样就减少了io ...

  8. @RequestParam和@ResponseBody注解的区别(转)

    @RequestParam 用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容.(Http协议中,如果不指定Content-Type, ...

  9. AzureARM 使用 powershell 扩容系统磁盘大小

    azure中的虚拟机,windows磁盘大小为127G,linux磁盘大小为30G,在很多时候部署应用程序时直接部署到系统磁盘内导致磁盘后期容量不够需要扩容,在执行分区扩容前我们需要先通过Potal或 ...

  10. JBOSS默认连接池配置

    jboss5.0mysql连接配置 <?xml version="1.0" encoding="UTF-8"?> <!-- The Hyper ...