澳门金沙国际 1

lvs+keepalived是什么?

LVS/DR + Keepalived搭建负载均衡集群

前方的LVS即便曾经布署成功也落实了负荷均衡(见
),不过我们测试的时候发现,当某台real
server把nginx进程停掉,那么director照样会把请求转载过去,那样就造成了几许请求不正常。所以必要有一种体制用来检测real
server的气象,那就是keepalived。它的职能除了可以检测rs状态外,还足以检测备用director的图景,也就是说keepalived可以达成ha集群的功用,当然了也急需一台备用director。
备用director也需求设置一下keepalived软件、ipvsadm;
keepalived调用lvs来完毕团结的规则;
yum install -y keepalived ipvsadm

条件搭建工作:
主director    192.168.11.30    eth1网卡
从director    192.168.11.40    eth1网卡
real server1:    192.168.11.100    eth0网卡
real server2:    192.168.11.101    eth0网卡

用来curl测试的linux主机 192.168.11.0 网段即可;
主dr和备用dr都要求安装keepalived,ipvsadm;
两台rs安装nginx;

安装好后,主director的配置文件
vim /etc/keepalived/keepalived.conf  //参与如下:
vrrp_instance VI_1 {
    state MASTER  #备用服务器上为 BACKUP
    interface eth1
    virtual_router_id 51
    priority 100  #优先级,数值越大优先级越高;备用服务器上为90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.11.110
    }
}
virtual_server 192.168.11.110 80 {
    delay_loop 6                 
#(每隔6秒查询realserver状态,是还是不是存活)
    lb_algo wlc                  #(轮询算法)
    lb_kind DR                  #(Direct Route)
    persistence_timeout 0   
#(同一IP的连接多少秒内被分配到同一台realserver,0象征不延续)
    protocol TCP                #(用TCP协议检查realserver状态)
    real_server 192.168.11.100 80 {
        weight 100              #(权重)
        TCP_CHECK {
        connect_timeout 10      #(10秒无响应超时)
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
real_server 192.168.11.101 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}

从director的配备文件只须要修改上边两项:
state MASTER  -> state BACKUP
priority 100 -> priority 90
安排完keepalived后,要求敞先导口转载(主从dr都要做):
echo 1 > /proc/sys/net/ipv4/ip_forward
然后,两个rs上执行 /usr/local/sbin/lvs_dr_rs.sh 脚本,启动nginx服务
# /etc/init.d/nginx start

末段,八个director上启动keepalived服务(先主后从):
# /etc/init.d/keepalived start

别的,须要专注的是,启动keepalived服务会自动生成vip和ipvsadm规则.

行义务令#ip addr   
查看dr的杜撰ip地址;直接动用ifconfig不呈现虚拟ip;
[[email protected]
keepalived]# ip addr
eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:97:c3:f6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.30/24 brd 192.168.11.255 scope global eth1
   
    inet 192.168.11.110/32 scope global eth1
    inet6 fe80::20c:29ff:fe97:c3f6/64 scope link 
    valid_lft forever preferred_lft forever

在任何机器curl测试,请求rs1和rs2次数很是;
[[email protected]
~]# curl 192.168.11.110
rs1rs1
[[email protected]
~]# curl 192.168.11.110
rs2rs2
[[email protected]
~]# curl 192.168.11.110
rs1rs1
[[email protected]
~]# curl 192.168.11.110
rs2rs2

rs2下边stop nginx,然后curl测试,发现具有的乞求都到rs1上边了;
日记里面也会记录remove rs2;日志文件:/var/log/messages
[[email protected]
~]# /etc/init.d/nginx stop

[[email protected]
~]# curl 192.168.11.110
rs1rs1
[[email protected]
~]# curl 192.168.11.110
rs1rs1
[[email protected]
~]# curl 192.168.11.110
rs1rs1
[[email protected]
~]# curl 192.168.11.110
rs1rs1

[[email protected]
~]# tail -2 /var/log/messages
Jun  9 23:27:19 localhost Keepalived_healthcheckers[1572]: TCP
connection to [192.168.11.101]:80 failed !!!
Jun  9 23:27:19 localhost Keepalived_healthcheckers[1572]: Removing
service [运用keepalived完毕lvs的高可用性,Keepalived搭建负载均衡集群。192.168.11.101]:80 from VS [192.168.11.110]:80

rs2起动nginx,日志文件记录adding
rs2;curl测试,发现呼吁平均分配到rs1和rs2上边了;

[[email protected]
~]# /etc/init.d/nginx start

[[email protected]
~]# tail -2 /var/log/messages
Jun  9 23:31:38 localhost Keepalived_healthcheckers[1572]: TCP
connection to [192.168.11.101]:80 success.
Jun  9 23:31:38 localhost Keepalived_healthcheckers[1572]: Adding
service [192.168.11.101]:80 to VS [192.168.11.110]:80

[[email protected]
~]# curl 192.168.11.110
rs1rs1
[[email protected]
~]# curl 192.168.11.110
rs2rs2
[[email protected]
~]# curl 192.168.11.110
rs1rs1
[[email protected]
~]# curl 192.168.11.110
rs2rs2

加入dr2 备用dircetor机器;
主上停止keepalive服务;stop之后,在从上ip
addr查看绑定虚拟ip,表达从接管了服务;切换速度很快;
主上启动keepalived服务后,主绑定虚拟ip,接管服务;
[[email protected]
keepalived]# ip addr
eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:af:73:3f brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.40/24 brd 192.168.11.255 scope global eth1
    inet 192.168.11.110/32 scope global eth1

nc命令可以扫描端口是或不是打开:

在其余机器上扫描,11.100 和11.101,11.110的80端口是不是打开;

#nc -z -w2 192.168.11.110 80
[[email protected]
~]# nc -z -w2 192.168.11.100 80
Connection to 192.168.11.100 80 port [tcp/http] succeeded!
[[email protected]
~]# nc -z -w2 192.168.11.101 80
Connection to 192.168.11.101 80 port [tcp/http] succeeded!
[[email protected]
~]# nc -z -w2 192.168.11.110 80
Connection to 192.168.11.110 80 port [tcp/http] succeeded!

LVS+Keepalived落成四层负载及高可用 

LVS+Keepalived高可用负载均衡集群架构实验 

Heartbeat+LVS创设高可用负载均衡集群 

搭建LVS负载均衡测试环境 

一个针对性LVS的压力测试报告

CentOS 6.3下Haproxy+Keepalived+Apache配置笔记

Haproxy + KeepAlived 实现WEB群集 on CentOS 6

Keepalived+Haproxy配置高可用负载均衡

Haproxy+Keepalived营造高可用负载均衡

CentOS 7 上配置LVS + Keepalived + ipvsadm

Keepalived高可用集群搭建

Keepalived 的详细介绍:请点那里
Keepalived 的下载地址:请点这里

本文永久更新链接地址:

+ Keepalived搭建负载均衡集群
前边的LVS即便已经安顿成功也完结了负荷均衡(见
),可是大家测试的时候发现,当某台real server把ngin…

类型实战3—Keepalived 已毕高可用,实战keepalived

澳门金沙国际 2

完毕基于Keepalived高可用集群网站架构

  环境:随着业务的进化,网站的访问量越来越大,网站访问量已经从原来的1000QPS,变为3000QPS,如今作业曾经经过集群LVS架构可做到时时举办,后端节点已经因而集群技术有限辅助了可用性,但对在此以前端负载均衡器来说,是个比较大的安全隐患,因为眼下端负载均衡器出现故障时,整个集群就高居瘫痪状态,因此,负载均衡器的可用性也突显至关主要,那么怎么来化解负载均衡器的可用性难点吧?

 总项目流程图,详见

尝试前准备

① 两台服务器都使用yum 格局安装keepalived 服务

yum -y install keepalived

② iptables -F && setenforing 清空防火墙策略,关闭selinux

 

单主模型IPVS示例

keepalived工作规律

试验一:完毕keepalived主从章程高可用基于LVS-DR方式的应用实战:

试行原理:

主从:一主一从,主的在做事,从的在用逸待劳;主的宕机了,VIP漂移到从上,由从提供服务

配置keepalive

高可用的ipvs集群示例:修改keepalived配置文件

keepalived是集群管理中确保集群高可用的一个劳务软件,其功用相近于heartbeat,用来防备单点故障。
keepalived是以VRRP协议为贯彻基础的,VRRP全称Virtual Router Redundancy
Protocol,即虚拟路由冗余协议。
虚拟路由冗余协议,可以认为是促成路由器高可用的说道,即将N台提供平等效果的路由器组成一个路由器组,那个组里面有一个master和四个backup,master上边有一个对外提供服务的vip(该路由器所在局域网内其余机器的默许路由为该vip),master会发组播,当backup收不到vrrp包时就以为master宕掉了,那时就必要依照VRRP的预先级来推举一个backup当master。那样的话就足以确保路由器的高可用了。

1、环境准备:

两台centos系统做DR、一主一从,两台落成过基于LNMP的电子商务网站

机器名称

lvs-server-master

lvs-server-backup

rs01

rs02

  

修改主机: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 }

 LVS简介

2、在lvs-server-master 主上

修改keepalived主(lvs-server-master)配置文件落到实处 virtual_instance 实例

(1)vim /etc/keepalived/keepalived.conf 修改三段

① 全局段,故障通知邮件配置
global_defs {
   notification_email {
        [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id keepalived_lvs
}

② 配置虚拟路由器的实例段,VI_1是自定义的实例名称,可以有多个实例段
vrrp_instance VI_1 {     #VI_1是自定义的实例名称
    state MASTER        #初始状态,MASTER|BACKUP
    interface eth1      #通告选举所用端口
    virtual_router_id 51  #虚拟路由的ID号(一般不可大于255)
    priority 100       #优先级信息 #备节点必须更低
    advert_int 1       #VRRP通告间隔,秒
    authentication {
        auth_type PASS    #认证机制
        auth_pass along   #密码(尽量使用随机)
    } 
    virtual_ipaddress {
        172.17.100.100    #vip
    }
}

③ 设置一个virtual server段
virtual_server 172.17.100.100 80 {   #设置一个virtual server:
    delay_loop 6   # service polling的delay时间,即服务轮询的时间间隔
    lb_algo wrr    #LVS调度算法:rr|wrr|lc|wlc|lblc|sh|dh
    lb_kind DR    #LVS集群模式:NAT|DR|TUN
    nat_mask 255.255.255.255  
    persistence_timeout 600  #会话保持时间(持久连接,秒),即以用户在600秒内被分配到同一个后端realserver
    protocol TCP    #健康检查用的是TCP还是UDP

④ real server设置段
    real_server 172.17.1.7 80 { #后端真实节点主机的权重等设置
        weight 1  #给每台的权重,rr无效
        HTTP_GET {  #http服务
            url {
              path /
            }
            connect_timeout 3    #连接超时时间
            nb_get_retry 3      #重连次数
            delay_before_retry 3 #重连间隔
        }
    }
    real_server 172.17.22.22 80 {
        weight 2
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

 

(2)开启keepalived 服务

service keepalived start

能来看网卡别名 和 负载均衡策略已经安装好了

ipvsadm -Ln

澳门金沙国际 3

 

(3)因为是主导方式,所以从上的布局和主唯有好几差别;所以可以把那几个布局文件拷过去

scp /etc/keepalived/keepalived.conf @172.17.11.11:

  

修改主机: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
        }
    }
}

LVS是Linux Virtual
Server的简写,意即Linux虚拟服务器,是一个虚构的服务器集群系统。本项目在1998年5月由章文嵩大学生成立,是礼仪之邦国内最早出现的自由软件项目之一。目前有三种IP负载均衡技术(VS/NAT、VS/TUN和VS/DR),十种调度算法。

3、在lvs-server-backup 从上

(1)只需改②实例段,其余都不要变,有限支撑一模一样

vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass along
    }

 

(2)开启keepalived 服务

service keepalived start

负载均衡策略已经安装好了,注意:主director没有宕机,从上就不会有VIP

ipvsadm -Ln 可能过一会才会显示

澳门金沙国际 4

 

查看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

正文重点给大家介绍Linux利用keepalived完毕lvs的高可用性的操作方法,感兴趣的爱侣参考下啊。

4、在real server 上

(1) 开启事前准备好的web服务

systemctl start nginx

systemctl start mariadb

systemctl start php-fpm

 

(2)因为是DR模式,需在rs上设置

① 配置VIP到地头回环网卡lo上,并只播放自己

ifconfig lo:0 172.17.100.100 broadcast 172.17.100.100 netmask
255.255.255.255 up

计划本地回环网卡路由

route add -host 172.17.100.100 lo:0

 

② 使RS “闭嘴”

echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo “2” > /proc/sys/net/ipv4/conf/lo/arp_announce

忽略ARP广播

echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore

echo “2” > /proc/sys/net/ipv4/conf/all/arp_announce

注意:关闭arp应答

1:仅在央浼的对象IP配置在该地主机的收取到请求报文的接口上时,才予以响应

2:必须避免将接口新闻向非本互连网展开通报

 

③ 想永远生效,可以写到配置文件中

vim /etc/sysctl.conf

net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

  

启航服务

[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已配置好

澳门金沙国际 5

5、测试

(1)lvs负载均衡功用是或不是打开

客户端访问

澳门金沙国际 6

也得以详细测试

① 在rs1 上设置一个测试一面

vim /data/web/test.html

real server 1

 

② 在rs2 上设置一个测试一面

vim /data/web/test.html

real server 2

 

③ 网页访问 发现有real server 1也有real
server 2

澳门金沙国际 7

 

(2)测试keepalived的基本方式

① 使keepalive 的主宕机

service keepalived stop

 

会发觉服务能照常访问,可是VIP 漂移到了从上

从多了网卡别名,且地址是VIP

澳门金沙国际 8

 

③ 使keepalive
的主重新开启服务,因为主的事先级高,所以VIP又再一次漂移到了主上

澳门金沙国际 9

 

后端real_server准备

单主模型IPVS示例

试行二:已毕keepalived双主情势高可用基于LVS-DR格局的使用实战:

尝试原理:

互为骨干:主从都在办事;其中一个宕机了,VIP漂移到另一个上,提供劳动

扩张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_announce

route add default gw 192.168.234.17

设置httpd服务 写好网页文件

配置keepalive

1、实验环境,基本同上

机器名称

lvs-server-1

lvs-server2

rs01

rs02

 

启动服务

澳门金沙国际 10

高可用的ipvs集群示例:修改keepalived配置文件

2、在lvs-server1 上,基本同上,就是加了一个实例段

修改keepalived主(lvs-server-master)配置文件贯彻 virtual_instance 实例

(1)vim /etc/keepalived/keepalived.conf

① 主的设置 VI_1

vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass along
    }
    virtual_ipaddress {
        172.17.100.100
    }
}

virtual_server 172.17.100.100 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.255
    persistence_timeout 600
    protocol TCP

    real_server 172.17.1.7 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 172.17.22.22 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

 

② 从的装置 VI_2

vrrp_instance VI_2 {
    state BACKUP
    interface eth1
    virtual_router_id 52
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass along
    }
    virtual_ipaddress {
        172.17.100.101
    }
}

virtual_server 172.17.100.101 443 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.255
    persistence_timeout 600
    protocol TCP

    real_server 172.17.1.7 443 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 172.17.22.22 443 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

 

(2)开启keepalived 服务

service keepalived start

能来看网卡别名 和 负载均衡策略已经安装好了

澳门金沙国际 11

ipvsadm -Ln

澳门金沙国际 12

 

(3)因为是宗旨格局,所以从上的布局和主唯有几许异样;所以可以把这些布局文件拷过去

scp /etc/keepalived/keepalived.conf @172.17.11.11:

 

多主模型IPVS示例

澳门金沙国际 13

修改主机:192.168.234.27的keepalived配置文件

3、在lvs-server2 上,基本同1,就是把实例的基本调换一下

(1)vim /etc/keepalived/keepalived.conf

① vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    virtual_router_id 51
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass along
    }
    virtual_ipaddress {
        172.17.100.100
    }
}
② vrrp_instance VI_2 {
    state MASTER
    interface eth1
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass along
    }
    virtual_ipaddress {
        172.17.100.101
    }
}

 

(2)开启keepalived 服务

service keepalived start

能观察网卡别名 和 负载均衡策略已经设置好了,突显结果会等段时光再突显

澳门金沙国际 14

ipvsadm -Ln,突显结果会等段日子再突显

澳门金沙国际 15

 

配置keepalive

高可用的ipvs集群示例:修改keepalived配置文件

[root@234c27 ~]# 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 //发送邮件服务器IP
smtp_connect_timeout 30 //邮件连接超时时长
router_id kptwo //路由id
vrrp _mcast_group4 234.10.10.10 //指定vrrp协议的多播地址
}
vrrp_instance VI_1 { //vrrp协议的
state MASTER //lvs的MASTER服务器
interface ens37 //
virtual_router_id 50 //虚拟路由
priority 100 //权重为100.越大越先
advert_int 1 //发送组博包的间隔
authentication { //验证
auth_type PASS //方式为pass( 明文)
auth_pass 1111 //密码
}
virtual_ipaddress { //keepalived虚拟ip
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 //服务协议,仅支持TCP
 real_server 192.168.234.47 80 { //后端real_server服务器地址
  weight 1 //权重
  HTTP_GET { //应用层检测
   url {
    path / //定义要监控的URL
    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
  }
 }
}

4、在real server 上

(1) 开启事前准备好的web服务

systemctl start nginx

systemctl start mariadb

systemctl start php-fpm

 

(2)因为是DR模式,需在rs上设置

① 配置VIP到当地回环网卡lo上,并只播放自己

ifconfig lo:0 172.17.100.100 broadcast 172.17.100.100 netmask
255.255.255.255 up

ifconfig lo:1 172.17.100.101 broadcast 172.17.100.101 netmask
255.255.255.255 up

布局本地回环网卡路由

route add -host 172.17.100.100 lo:0

route add -host 172.17.100.101 lo:1

 

② 使RS “闭嘴”

echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo “2” > /proc/sys/net/ipv4/conf/lo/arp_澳门金沙国际 ,announce

忽略ARP广播

echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore

echo “2” > /proc/sys/net/ipv4/conf/all/arp_announce

注意:关闭arp应答

1:仅在呼吁的目的IP配置在当地主机的收到到请求报文的接口上时,才给予响应

2:必须幸免将接口音讯向非本互联网进行通报

 

③ 想永远生效,可以写到配置文件中

vim /etc/sysctl.conf

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

 

修改主机: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配置文件

5、测试

(1)lvs负载均衡功用是或不是打开

客户端访问 公网172.17.100.100只能访问80

澳门金沙国际 16

公网172.17.100.101只好访问443

澳门金沙国际 17

也可以详细测试

① 在rs1 上安装一个测试一面

vim /data/web/test.html

real server 1

 

② 在rs2 上安装一个测试一面

vim /data/web/test.html

real server 2

 


网页访问
发现有real server 1也有real server 2

澳门金沙国际 18

 

(2)测试keepalived的双主形式

① 使keepalive 的轻易一个宕机

service keepalived stop

 

会发觉服务能照常访问,另一个机械80、443都能访问,且宕机的VIP漂移到了另一个服务器上

澳门金沙国际 19

  

修改主机: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备用

[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主从点子高可用基于LVS-NAT情势的行使实战:

试验原理:

主从:一主一从,主的在工作,从的在恢复;主的宕机了,VIP和DIP都漂移到从上,由从提供劳动,因为DIP需被rs作为网关,所以也需上浮

后端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

澳门金沙国际 20

今昔宕掉一个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 

澳门金沙国际 21

如故提供劳动

  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

后一个完毕基于前一个的基本功上修改来的

查看keepalived

1、环境准备

机器名称

vs-server-master

lvs-server-backup

rs01

rs02

注意:要保管rs和DIP在一个网段,且不和VIP在一个网段

 

比方要兑现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 }
[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

2、在lvs-server-master 主上

(1)vim keepalived.conf

global_defs {
   notification_email {
        [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id keepalived_lvs
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass along
    }
    virtual_ipaddress {
       172.17.100.100
192.168.30.100
    }
}

virtual_server 172.17.100.100 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind NAT
    nat_mask 255.255.255.255
    persistence_timeout 100
    protocol TCP

    real_server 192.168.30.107 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.30.7 80 {
        weight 2
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

 

(2)因为是NAT情势,所以需开启路由转发作用

vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

 

sysctl -p 读一些,使参数生效

 

(3)开启keepalived 服务

service keepalived start

能见到网卡别名 和 负载均衡策略已经安装好了

澳门金沙国际 22

ipvsadm -Ln

澳门金沙国际 23

 

(4)因为是着力方式,所以从上的安排和主只有一些差异;所以可以把这几个布局文件拷过去

scp /etc/keepalived/keepalived.conf @172.17.11.11:

 

3、在lvs-server-backup 从上

(1)只需改②实例段,其余都不要变,保障一模一样

vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass along
    }

 

 

(2)因为是NAT格局,所以需开启路由转载作用

① vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

② sysctl -p 读一些,使参数生效

 

(3)开启keepalived 服务

service keepalived start

负载均衡策略已经安装好了,注意:主director没有宕机,从上就不会有VIP

ipvsadm -Ln 可能过一会才会来得

澳门金沙国际 24

 

启动服务

4、在real server 上

(1) 开启事前准备好的web服务

systemctl start nginx

systemctl start mariadb

systemctl start php-fpm

 

(2)因为是NAT模式,需在rs上设置

只需把网关指向DIP

route add default gw 192.168.30.100

 

澳门金沙国际 25

5、测试

(1)lvs负载均衡成效是或不是开启

客户端访问

澳门金沙国际 26

也足以详细测试

① 在rs1 上安装一个测试一面

vim /data/web/test.html

real server 1

 

② 在rs2 上安装一个测试一面

vim /data/web/test.html

real server 2

 

③ 网页访问 发现有real server 1也有real
server 2

澳门金沙国际 27

 

 

(2)测试keepalived的要旨形式

① 使keepalive 的主宕机

service keepalived stop

 

会发现服务能照常访问,可是VIP 和DIP 都浮动到了从上

从多了网卡别名,且地址是VIP

澳门金沙国际 28

 

③ 使keepalive
的主重新开启服务,因为主的预先级高,所以VIP和DIP又再一次漂移到了主上

澳门金沙国际 29

 

[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已配置好

实验四:完结keeaplived 故障通知机制

后端real_server准备

1、编写好剧本

剧本主要内容:检测到基本爆发变化,或不当,给何人发邮件;邮件内容是:在什么时间,何人爆发了如何变动

vim /etc/keepalived/notify.sh

#!/bin/bash
# Author: www.magedu.com
contact='[email protected]'
notify() {
        mailsubject="$(hostname) to be $1: vip floating"
        mailbody="$(date +'%F %H:%M:%S'): vrrp transition, $(hostname) changed to be $1"
        echo $mailbody | mail -s "$mailsubject" $contact
}
case $1 in
master) 
        notify master
        exit 0
;;
backup)
        notify backup
        exit 0
;;
fault)
        notify fault
        exit 0
;;
*)
        echo "Usage: $(basename $0) {master|backup|fault}"
        exit 1
;;
esac

剧本加权限 chmod +x /etc/keepalived/notify.sh

 

充实ip在网卡上 修改限制arp通知及应答级别
rs1 rs2都做,网关并指向路由

2、在keepalived 的布置文件调用脚本

在instance 实例段添加,注意脚本的门路

notify_backup "/etc/keepalived/notify.sh backup"
notify_master "/etc/keepalived/notify.sh master"
notify_fault "/etc/keepalived/notify.sh fault"

例:

澳门金沙国际 30

  

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_announce
route add default gw 192.168.234.17

实验五:完结keepaplived自定义脚本检测成效

规律:在keepalived的安排文件中能直接定义脚本,且能在instance
实例段直接调用生效

 

安装httpd服务 写好网页文件

方案一:检测是或不是留存down文件,来落到实处基本的调整

1、在实例段上面定义一个剧本

vim keepalived.conf

vrrp_script chk_down {    #定义一个脚本,脚本名称为chk_down
   script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"   #检查这个down文件,若存在返回值为1,keepalived会停止;不存在返回值为0,服务正常运行;这里的exit和bash脚本里的return很相似
 interval 2   #每2秒检查一次
}

2、在instance 实例段可以一贯调用这几个剧本

track_script {
    chk_down
}

 

3、检测

在主上,创造一个/etc/keepalived/down
文件,主的keepalived服务及时终止,VIP漂到从上,从接上服务;

down文件一旦删除,主的keepalived服务会马上启动,若优先级高或预先级低但设置的侵吞,VIP会重漂回来,接上服务。

 

开行服务

方案二:检测nginx服务是还是不是打开,来贯彻调整为主

1、在实例段下面定义一个本子

vrrp_script chk_nginx {
     script "killall -0 nginx" #killall -0 检测这个进程是否还活着,不存在就减权重
     interval 2 #每2秒检查一次
     fall 2 #失败2次就打上ko的标记
     rise 2 #成功2次就打上ok的标记
     weight -4 #权重,优先级-4,若为ko
}

 

2、在instance 实例段可以一向调用那几个本子

track_script {
    chk_nginx
}

 

3、检测

若主的nginx服务没有开启,则每2秒-4的权重,当优先级小于从,VIP漂到从上,从接上服务;

若主的nginx服务开启,重读配置文件,优先级回复,VIP回到主上,主复苏服务;

  

完结高可用,实战keepalived
达成基于Keepalived高可用集群网站架构
环境:随着事情的进化,网站的访问量越来越大,网站…

image

多主模型IPVS示例

澳门金沙国际 31

配置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

  [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
  TCP 10.0.0.200:80 wrr
  -> 192.168.234.57:80      Route  1   0     0

今昔宕掉一个lvs

澳门金沙国际 32

  [root@234c27 keepalived]# systemctl stop keepalived.service
  [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

如故提供劳动

澳门金沙国际 33

 [root@234c37 ~]# 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     21
  TCP 10.0.0.200:80 wrr
   -> 192.168.234.57:80      Route  1   0     39

后一个兑现基于前一个的底子上修改来的

假定要完毕sorry_server

1.把rs服务都停掉。然后在lvs上安装apache或者nginx服务

2.将keepalived配置文件中的

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
    }
  }
}

你或许感兴趣的文章:

  • LVS+Keepalived营造高可用负载均衡(测试篇)
  • LVS+Keepalived营造高可用负载均衡配置格局(配置篇)
  • Linux下的高可用性方案商讨

相关文章