【亚洲必赢app官方下载】主主布局实例,达成基于Keepalived

实例拓扑图:


LVS(Linux Virtual
Server卡塔尔国:Linux虚构服务器,这里透过keepalived作为负载均衡器
兰德酷路泽S(Real Server卡塔尔国:真实服务器
VEvoqueRP(Virtual Router Redundancy Protocol卡塔尔国: 设想路由冗余磋商,
消逝局域网中配置静态网关现身单点失效现象的路由协议
亚洲必赢app官方下载 1

亚洲必赢app官方下载 2

亚洲必赢app官方下载 3

 

贯彻基于Keepalived高可用集群网址结构

DEscort1和DHighlander2布置keepalived和lvs作主从结构或主主布局,路虎极光S1和途睿欧S2陈设nginx搭建web站点。

1 Keepalived是何许,有怎么着意义?
1.1 Keepalived的定义
Keepalived 是三个基于VRubiconRP协议来兑现的LVS高可用方案
1.2 Keepalived的作用
1.2.1 通过IP漂移完成高可用
主副LVS分享三个虚构IP,同时唯有二个LVS占领VIP并对外提供劳务,若该LVS不可用,则VIP漂移至另生机勃勃台LVS并对外提供服务;
1.2.2 对EscortS集群举行状态监察和控制
若KoleosS不可用,则keepalived将其从集群中摘除,若WranglerS复苏,则keepalived将其重新参预集群中。
2 Keepalived有二种格局,各样形式的相仿点和分裂点是怎么?
2.1 Keepalived的情势种类
Keepalived有3种情势:NAT(地址调换);DCR-V(间接路由);TUN(隧道)
2.2 Keepalived的大器晚成一形式的牵线
2.2.1 NAT
优点:集群中的奥迪Q3S能够接收其余协助TCP/IP操作系统,OdysseyS能够分配Internet的保留私有地址,独有LVS需求一个官方的IP地址。
劣势:扩展性有限。当RAV4S节点增进到十七个或越多时,LVS将造成整个种类的瓶颈,因为具有的呼吁包和应对包都亟待经过LVS再生。
2.2.2 TUN
我们发掘,好些个Internet服务(举个例子WEB服务器)的伏乞包相当的短小,而应答包常常极大。
可取:LVS只负担将倡议包分发给SportageS,而本田CR-VS将回应包直接发给客商。所以,LVS能管理很伟大的央求量,这种办法,意气风发台载荷均衡能为超过100台的本田CR-VS服务,LVS不再是系统的瓶颈。
症结:不过,这种艺术必要具有的服务器帮衬”IP Tunneling”(IP
Encapsulation卡塔尔合同,小编仅在Linux系统上落到实处了那些。
2.2.3 DR
可取:和TUN同样,LVS也只是散发乞请,应答包通过独立的路由方法重返给客商端。与TUN相比较,D帕杰罗这种完毕格局不要求隧道构造,因而得以行使大好多操作系统做为马自达MX-5S。
不足:要求LVS的网卡必得与MuranoS的网卡在三个网段上
3 分歧方式的配置情势,验证办法分别是何许?
3.1 基本的情形供给
【亚洲必赢app官方下载】主主布局实例,达成基于Keepalived。需要2台LVS和n(n>=2)台RS
3.1.1 LVS
安装ipvsadm(LVS处理工科具)和keepalived;
开启路由转载效率:
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
验证:
sysctl -p
net.ipv4.ip_forward = 1
3.1.2 RS
安装httpd(用于最后测量检验)
3.2 NAT方式配置
3.2.1 景况概述
操作系统 负载均衡格局 VIP NVIP
RHEL7.4 NAT 193.168.140.80 192.168.102.165

  蒙受:随着事情的前进,网站的访谈量越来越大,网址访谈量已经从原来的1000QPS,变为3000QPS,如今事务已经经过集群LVS布局可产生任何时候开展,后端节点已经通过集群本事保障了可用性,但对在此以前端负载均衡器来讲,是个相当的大的安全隐患,因为近期端负载均衡器现身故障时,整个集群就高居瘫痪状态,因而,负载均衡器的可用性也出示至关首要,那么怎么来缓和负载均衡器的可用性难题呢?

小心:各节点的年华必要协作(ntpdate
ntp1.aliyun.com);关闭firewalld(systemctl stop
firewalld.service,systemctl disable
firewalld.service),设置selinux为permissive(setenforce
0);同期确认保证各网卡帮衬MULTICAST(多播)通讯。

LVS1 LVS2 RS1 RS2
ens3:192.168.102.161 ens3:192.168.102.162 ens3:192.168.102.163
ens3:192.168.102.164
ens4:193.168.140.79 ens4:193.168.140.83 网关:192.168.102.165
网关:192.168.102.165

 总项目流程图,详见 

经过命令ifconfig能够查看见是还是不是张开了MULTICAST:

3.2.2 LVS
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
qingean@163.com #故障接纳联系人
}
notification_email_from admin@test.com #故障发赠与他人
smtp_server 127.0.0.1 #本机发送邮件
smtp_connect_timeout 30
router_id LVS_亚洲必赢app官方下载,MASTER #BACKUP上改良为LVS_BACKUP
}
vrrp_instance VI_1 {
state MASTER #BACKUP上退换为BACKUP
interface ens4
virtual_router_id 51 #设想路由标记,主从雷同
priority 100 #BACKUP上修改良改为90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 #主题认证密码必需意气风发致
}
virtual_ipaddress {
193.168.140.80 #虚拟IP(VIP)
}
}
vrrp_instance LAN_GATEWAY { #概念网关
state MASTER #BACKUP上改换为BACKUP
interface ens3
virtual_router_id 62 #设想路由ID,主从相仿
priority 100 #BACKUP上修改正改为90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #ens3网关设想IP
192.168.102.165
}
}
virtual_server 192.168.102.165 80 { #概念内网网关虚构IP和端口
delay_loop 6 #检查RS时间,单位秒
lb_algo rr
#安装负载调解算法,轮叫(rr卡塔尔国、加权轮叫(wrr卡塔尔、最小连接(lc卡塔尔(英语:State of Qatar)、加权最小连接(wlc卡塔尔国、基于局地性最小连接(lblc卡塔尔国、带复制的借助局地性最少链接(lblcr卡塔尔、目的地点散列(dh卡塔尔国和源地址散列(sh卡塔尔国
lb_kind NAT #安装LVS负载均衡NAT情势
persistence_timeout 50
#同风度翩翩IP的三翻五次60秒内被分配到均等台真正服务器(测量检验时提出改为0卡塔尔(قطر‎
protocol TCP #运用TCP合同检查HighlanderS状态
real_server 192.168.102.161 80 { #首先个网关节点
weight 3 #节点权重值
TCP_CHECK { #健检形式
connect_timeout 3 #总是超时
nb_get_retry 3 #重试次数
delay_before_retry 3 #重试间距/S
}
}
real_server 192.168.102.162 80 { #其次个网关节点
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 193.168.140.80 80{ #概念虚构IP
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 192.168.102.163 80 { #第一个RS
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.102.164 80 { #第二个RS
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
3.2.3 RS
为具备揽胜极光S加多网关为192.168.102.165:
vim /etc/sysconfig/network-scripts/ifcfg-ens3
GATEWAY=192.168.102.165
重启; 使用route –n查看是还是不是成功
IPVS connection entries
pro expire state source virtual destination
TCP 01:54 FIN_WAIT 10.167.225.60:53882 193.168.140.80:80
192.168.102.163:80
TCP 00:37 NONE 10.167.225.60:0 193.168.140.80:80 192.168.102.163:80

实验前筹算

     
 亚洲必赢app官方下载 4

3.3 DPAJERO形式配置
3.3.1 情况概述
操作系统 负载均衡情势 VIP
RHEL7.4 DR 193.168.140.80

① 两台服务器都使用yum 情势安装keepalived 服务

keepalived的中坚布局

LVS1 LVS2 RS1 RS2
ens4:193.168.140.79 ens4:193.168.140.83 ens4:193.168.140.152
ens4:193.168.140.224

yum -y install keepalived

搭建RS1:

[root@RS1 ~]# yum -y install nginx   #安装nginx
[root@RS1 ~]# vim /usr/share/nginx/html/index.html   #修改主页
    <h1> 192.168.4.118 RS1 server </h1>
[root@RS1 ~]# systemctl start nginx.service   #启动nginx服务
[root@RS1 ~]# vim RS.sh   #配置lvs-dr的脚本文件
    #!/bin/bash
    #
    vip=192.168.4.120
    mask=255.255.255.255
    case $1 in
    start)
        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
        ifconfig lo:0 $vip netmask $mask broadcast $vip up
        route add -host $vip dev lo:0
        ;;
    stop)
        ifconfig lo:0 down
        echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
        echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
        echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
        echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
        ;;
    *) 
        echo "Usage $(basename $0) start|stop"
        exit 1
        ;;
    esac
[root@RS1 ~]# bash RS.sh start

3.3.2 LVS
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
qingean@163.com
}
notification_email_from admin@test.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_MASTER
}
vrrp_instance VI_1 {
state MASTER #BACKUP上改动为BACKUP
interface ens4
virtual_router_id 51
priority 100 #BACKUP上修改进改为90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
193.168.140.80
}
}
virtual_server 193.168.140.80 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.255
protocol TCP
real_server 193.168.140.152 80 {
weight 10
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 193.168.140.224 80 {
weight 10
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}

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

参谋EnclaveS1的铺排搭建KoleosS2。

3.3.3 RS
为所有RS修改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
net.ipv4.ip_forward= 1
执行/sbin/ifconfig lo:0 193.168.140.80 broadcast 193.168.140.80 netmask
255.255.255.255
可用route –n查看是不是成功
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 193.168.1.1 0.0.0.0 UG 100 0 0 ens4
193.168.0.0 0.0.0.0 255.255.0.0 U 100 0 0 ens4
193.168.140.80 0.0.0.0 255.255.255.255 UH 0 0 0 lo
若不成功施行/sbin/route add -host 193.168.140.80 dev lo:0
3.4 验证办法
3.4.1 全部机器关闭防火墙:
systemctl stop firewalld
3.4.2 全体CRUISERS写入测验页和开启httpd服务
RS1:echo “RS1″ > /var/www/html/index.html
RS2:echo “RS2″ > /var/www/html/index.html
systemctl start httpd
3.4.3 主副LVS开启keepalived服务
systemctl start keepalived
3.4.4 访问
浏览器访谈
刷新会更换体现揽胜S1或GL450S2
3.4.5 查看当前测验机的访问必要被转接到哪些服务器
ipvsadm –lcn
IPVS connection entries
pro expire state source virtual destination
TCP 01:54 FIN_WAIT 10.167.225.60:53882 193.168.140.80:80
192.168.102.163:80
TCP 00:37 NONE 10.167.225.60:0 193.168.140.80:80 192.168.102.163:80
3.4.6 测试
仿照宕掉主LVS,服务器照常专门的学业,再宕掉Web1,这个时候只会显得Web2,那样就贯彻IP负载均衡,高可用集群。当主LVS复苏后,会切换到主动服务器,纵然Keepalived监察和控制模块检查实验web故障恢复生机后,苏醒的主机又将此节点参预集群系统中。

 

搭建DR1:

[root@DR1 ~]# yum -y install ipvsadm keepalived   #安装ipvsadm和keepalived
[root@DR1 ~]# vim /etc/keepalived/keepalived.conf   #修改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 192.168.4.116
       vrrp_skip_check_adv_addr
       vrrp_mcast_group4 224.0.0.10
    }

    vrrp_instance VIP_1 {
        state MASTER
        interface eno16777736
        virtual_router_id 1
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass %&hhjj99
        }
        virtual_ipaddress {
          192.168.4.120/24 dev eno16777736 label eno16777736:0
        }
    }

    virtual_server 192.168.4.120 80 {
        delay_loop 6
        lb_algo rr
        lb_kind DR
        protocol TCP

        real_server 192.168.4.118 80 {
            weight 1
            HTTP_GET {
                url {
                  path /index.html
                  status_code 200
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
        real_server 192.168.4.119 80 {
            weight 1
            HTTP_GET {
                url {
                  path /index.html
                  status_code 200
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
         }
    }
[root@DR1 ~]# systemctl start keepalived
[root@DR1 ~]# ifconfig
    eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.4.116  netmask 255.255.255.0  broadcast 192.168.4.255
            inet6 fe80::20c:29ff:fe93:270f  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:93:27:0f  txqueuelen 1000  (Ethernet)
            RX packets 14604  bytes 1376647 (1.3 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 6722  bytes 653961 (638.6 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    eno16777736:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.4.120  netmask 255.255.255.0  broadcast 0.0.0.0
            ether 00:0c:29:93:27:0f  txqueuelen 1000  (Ethernet)
[root@DR1 ~]# ipvsadm -ln
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
      -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP  192.168.4.120:80 rr
      -> 192.168.4.118:80             Route   1      0          0         
      -> 192.168.4.119:80             Route   1      0          0

尝试意气风发:达成keepalived主从章程高可用基于LVS-D宝马X5情势的使用实战:

实验原理:

主从:风流倜傥主蓬蓬勃勃从,主的在干活,从的在休养;主的宕机了,VIP漂移到从上,由从提供劳务

D奥迪Q32的搭建基本同DCRUISER1,主要改进一下配置文件中/etc/keepalived/keepalived.conf的state和priority:state BACKUP、priority 90. 同期我们发掘作为backup的D卡宴2未有启用eno16777736:0的网口:

亚洲必赢app官方下载 5

1、遭逢准备:

两台centos系统做DGL450、蓬蓬勃勃主生龙活虎从,两台完结过基于LNMP的电商网站

机器名称

IP配置

服务角色

备注

lvs-server-master

VIP:172.17.100.100

DIP:172.17.1.6

负载均衡器

主服务器

开启路由功能

配置keepalived

lvs-server-backup

VIP:172.17.100.100

DIP:172.17.11.11

后端服务器

从服务器

开启路由功能

配置keepalived

rs01

RIP:172.17.1.7

后端服务器

 

rs02

RIP:172.17.22.22

后端服务器

 

  

顾客端进行测试:

[root@client ~]# for i in {1..20};do curl http://192.168.4.120;done   #客户端正常访问
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>

[root@DR1 ~]# systemctl stop keepalived.service   #关闭DR1的keepalived服务

[root@DR2 ~]# systemctl status keepalived.service   #观察DR2,可以看到DR2已经进入MASTER状态
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-09-04 11:33:04 CST; 7min ago
  Process: 12983 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 12985 (keepalived)
   CGroup: /system.slice/keepalived.service
           ├─12985 /usr/sbin/keepalived -D
           ├─12988 /usr/sbin/keepalived -D
           └─12989 /usr/sbin/keepalived -D

Sep 04 11:37:41 happiness Keepalived_healthcheckers[12988]: SMTP alert successfully sent.
Sep 04 11:40:22 happiness Keepalived_vrrp[12989]: VRRP_Instance(VIP_1) Transition to MASTER STATE
Sep 04 11:40:23 happiness Keepalived_vrrp[12989]: VRRP_Instance(VIP_1) Entering MASTER STATE
Sep 04 11:40:23 happiness Keepalived_vrrp[12989]: VRRP_Instance(VIP_1) setting protocol VIPs.
Sep 04 11:40:23 happiness Keepalived_vrrp[12989]: Sending gratuitous ARP on eno16777736 for 192.168.4.120
Sep 04 11:40:23 happiness Keepalived_vrrp[12989]: VRRP_Instance(VIP_1) Sending/queueing gratuitous ARPs on eno16777736 for 192.168.4.120
Sep 04 11:40:23 happiness Keepalived_vrrp[12989]: Sending gratuitous ARP on eno16777736 for 192.168.4.120
Sep 04 11:40:23 happiness Keepalived_vrrp[12989]: Sending gratuitous ARP on eno16777736 for 192.168.4.120
Sep 04 11:40:23 happiness Keepalived_vrrp[12989]: Sending gratuitous ARP on eno16777736 for 192.168.4.120
Sep 04 11:40:23 happiness Keepalived_vrrp[12989]: Sending gratuitous ARP on eno16777736 for 192.168.4.120

[root@client ~]# for i in {1..20};do curl http://192.168.4.120;done   #可以看到客户端正常访问
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>
<h1> 192.168.4.119 RS2 server</h1>
<h1> 192.168.4.118 RS1 server </h1>

2、在lvs-server-master 主上

更改keepalived主(lvs-server-master卡塔尔配置文件落到实处 virtual_instance 实例

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

① 全局段,故障通知邮件配置
global_defs {
   notification_email {
        root@localhost
   }
   notification_email_from root@along.com
   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

亚洲必赢app官方下载 6

 

(3)因为是骨干方式,所以从上的配备和主唯有几许间隔;所以能够把那么些构造文件拷过去

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

  

keepalived的主主结构

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 大概过一会才会显得

亚洲必赢app官方下载 7

 

 改革科雷傲S1和ENVISIONS2,增加新的VIP:

[root@RS1 ~]# cp RS.sh RS_bak.sh
[root@RS1 ~]# vim RS_bak.sh   #添加新的VIP
    #!/bin/bash
    #
    vip=192.168.4.121
    mask=255.255.255.255
    case $1 in
    start)
        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
        ifconfig lo:1 $vip netmask $mask broadcast $vip up
        route add -host $vip dev lo:1
        ;;
    stop)
        ifconfig lo:1 down
        echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
        echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
        echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
        echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
        ;;
    *)
        echo "Usage $(basename $0) start|stop"
        exit 1
        ;;
    esac
[root@RS1 ~]# bash RS_bak.sh start
[root@RS1 ~]# ifconfig
    ...
    lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 192.168.4.120  netmask 255.255.255.255
            loop  txqueuelen 0  (Local Loopback)

    lo:1: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 192.168.4.121  netmask 255.255.255.255
            loop  txqueuelen 0  (Local Loopback) 
[root@RS1 ~]# scp RS_bak.sh root@192.168.4.119:~
root@192.168.4.119's password: 
RS_bak.sh                100%  693     0.7KB/s   00:00

[root@RS2 ~]# bash RS_bak.sh   #直接运行脚本添加新的VIP 
[root@RS2 ~]# ifconfig
    ...
    lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 192.168.4.120  netmask 255.255.255.255
            loop  txqueuelen 0  (Local Loopback)

    lo:1: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 192.168.4.121  netmask 255.255.255.255
            loop  txqueuelen 0  (Local Loopback)

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

  

修改DR1和DR2:

[root@DR1 ~]# vim /etc/keepalived/keepalived.conf   #修改DR1的配置文件,添加新的实例,配置服务器组
    ...
    vrrp_instance VIP_2 {
        state BACKUP
        interface eno16777736
        virtual_router_id 2
        priority 90
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass UU**99^^
        }
        virtual_ipaddress {
            192.168.4.121/24 dev eno16777736 label eno16777736:1
        }
    }

    virtual_server_group ngxsrvs {
        192.168.4.120 80
        192.168.4.121 80
    }
    virtual_server group ngxsrvs {
        ...
    }
[root@DR1 ~]# systemctl restart keepalived.service   #重启服务
[root@DR1 ~]# ifconfig   #此时可以看到eno16777736:1,因为DR2还未配置
    eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.4.116  netmask 255.255.255.0  broadcast 192.168.4.255
            inet6 fe80::20c:29ff:fe93:270f  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:93:27:0f  txqueuelen 1000  (Ethernet)
            RX packets 54318  bytes 5480463 (5.2 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 38301  bytes 3274990 (3.1 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    eno16777736:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.4.120  netmask 255.255.255.0  broadcast 0.0.0.0
            ether 00:0c:29:93:27:0f  txqueuelen 1000  (Ethernet)

    eno16777736:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.4.121  netmask 255.255.255.0  broadcast 0.0.0.0
            ether 00:0c:29:93:27:0f  txqueuelen 1000  (Ethernet)
[root@DR1 ~]# ipvsadm -ln
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
      -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP  192.168.4.120:80 rr
      -> 192.168.4.118:80             Route   1      0          0         
      -> 192.168.4.119:80             Route   1      0          0         
    TCP  192.168.4.121:80 rr
      -> 192.168.4.118:80             Route   1      0          0         
      -> 192.168.4.119:80             Route   1      0          0

[root@DR2 ~]# vim /etc/keepalived/keepalived.conf   #修改DR2的配置文件,添加实例,配置服务器组
    ...
    vrrp_instance VIP_2 {
        state MASTER
        interface eno16777736
        virtual_router_id 2
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass UU**99^^
        }
        virtual_ipaddress {
            192.168.4.121/24 dev eno16777736 label eno16777736:1
        }
    }

    virtual_server_group ngxsrvs {
        192.168.4.120 80
        192.168.4.121 80
    }
    virtual_server group ngxsrvs {
        ...
    }
[root@DR2 ~]# systemctl restart keepalived.service   #重启服务
[root@DR2 ~]# ifconfig
    eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.4.117  netmask 255.255.255.0  broadcast 192.168.4.255
            inet6 fe80::20c:29ff:fe3d:a31b  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:3d:a3:1b  txqueuelen 1000  (Ethernet)
            RX packets 67943  bytes 6314537 (6.0 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 23250  bytes 2153847 (2.0 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    eno16777736:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.4.121  netmask 255.255.255.0  broadcast 0.0.0.0
            ether 00:0c:29:3d:a3:1b  txqueuelen 1000  (Ethernet)
[root@DR2 ~]# ipvsadm -ln
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
      -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP  192.168.4.120:80 rr
      -> 192.168.4.118:80             Route   1      0          0         
      -> 192.168.4.119:80             Route   1      0          0         
    TCP  192.168.4.121:80 rr
      -> 192.168.4.118:80             Route   1      0          0         
      -> 192.168.4.119:80             Route   1      0          0 

5、测试

(1)lvs负载均衡功能是不是开启

客商端访谈

亚洲必赢app官方下载 8

也能够详细测量试验

① 在rs1 上设置叁个测量检验一面

vim /data/web/test.html

real server 1

 

② 在rs2 上安装二个测量检验一面

vim /data/web/test.html

real server 2

 

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

亚洲必赢app官方下载 9

 

(2)测验keepalived的基本形式

① 使keepalive 的主宕机

service keepalived stop

 

会开采服务能照常访谈,不过VIP 漂移到了从上

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

亚洲必赢app官方下载 10

 

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

亚洲必赢app官方下载 11

 

顾客端测验:

[root@client ~]# for i in {1..20};do curl http://192.168.4.120;done
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
[root@client ~]# for i in {1..20};do curl http://192.168.4.121;done
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>
    <h1> 192.168.4.119 RS2 server</h1>
    <h1> 192.168.4.118 RS1 server </h1>

 

试验二:达成keepalived双主方式高可用基于LVS-DHighlander格局的行使实战:

尝试原理:

互为主干:主从都在职业;当中一个宕机了,VIP漂移到另二个上,提供劳务

1、实验情形,基本同上

机器名称

IP配置

服务角色

备注

lvs-server-1

VIP:172.17.100.100

DIP:172.17.1.6

负载均衡器

主服务器

开启路由功能

配置keepalived

lvs-server2

VIP:172.17.100.101

DIP:172.17.11.11

后端服务器

从服务器

开启路由功能

配置keepalived

rs01

RIP:172.17.1.7

后端服务器

 

rs02

RIP:172.17.22.22

后端服务器

 

 

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

能收看网卡外号 和 负载均衡攻略已经安装好了

亚洲必赢app官方下载 12

ipvsadm -Ln

亚洲必赢app官方下载 13

 

(3)因为是主旨情势,所以从上的配置和主唯有点差别;所以能够把那几个构造文件拷过去

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

 

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

能观望网卡别称 和 负载均衡计策已经设置好了,突显结果会等段时日再展现

亚洲必赢app官方下载 14

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

亚洲必赢app官方下载 15

 

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

 

5、测试

(1)lvs负载均衡功能是不是开启

客商端访谈
公网172.17.100.100不能不访谈80

亚洲必赢app官方下载 16

公网172.17.100.101只可以访谈443

亚洲必赢app官方下载 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

亚洲必赢app官方下载 18

 

(2)测验keepalived的双主形式

① 使keepalive 的轻松叁个宕机

service keepalived stop

 

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

亚洲必赢app官方下载 19

  

实验三:达成keepalived主从点子高可用基于LVS-NAT情势的选取实战:

推行原理:

主从:后生可畏主后生可畏从,主的在专门的学问,从的在复苏;主的宕机了,VIP和DIP都漂移到从上,由从提供服务,因为DIP需被rs作为网关,所以也需上浮

1、景况思虑

机器名称

IP配置

服务角色

备注

vs-server-master

VIP:172.17.100.100

DIP:192.168.30.100

负载均衡器

主服务器

开启路由功能

配置keepalived

lvs-server-backup

VIP:172.17.100.100

DIP:192.168.30.100

后端服务器

从服务器

开启路由功能

配置keepalived

rs01

RIP:192.168.30.107

后端服务器

网关指向DIP

rs02

RIP:192.168.30.7

后端服务器

网关指向DIP

只顾:要作保rs和DIP在一个网段,且不和VIP在一个网段

 

2、在lvs-server-master 主上

(1)vim keepalived.conf

global_defs {
   notification_email {
        root@localhost
   }
   notification_email_from root@along.com
   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

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

亚洲必赢app官方下载 20

ipvsadm -Ln

亚洲必赢app官方下载 21

 

(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 大概过一会才会显得

亚洲必赢app官方下载 22

 

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

 

5、测试

(1)lvs负载均衡作用是或不是展开

顾客端访谈

亚洲必赢app官方下载 23

也得以详细测验

① 在rs1 上设置三个测量检验一面

vim /data/web/test.html

real server 1

 

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

vim /data/web/test.html

real server 2

 

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

亚洲必赢app官方下载 24

 

 

(2)测量检验keepalived的主题方式

① 使keepalive 的主宕机

service keepalived stop

 

会意识服务能照常访问,不过VIP 和DIP 都上浮到了从上

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

亚洲必赢app官方下载 25

 

③ 使keepalive
的主重新开启服务,因为主的刚开始阶段级高,所以VIP和DIP又再度漂移到了主上

亚洲必赢app官方下载 26

 

试验四:达成keeaplived 故障通报机制

1、编写好本子

剧本首要内容:检查评定到基本产生变化,或不当,给何人发邮件;邮件内容是:在哪些日子,什么人产生了什么样变化

vim /etc/keepalived/notify.sh

#!/bin/bash
# Author: www.magedu.com
contact='root@localhost'
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

 

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

在instance 实例段增添,注意脚本的门道

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

例:

亚洲必赢app官方下载 27

  

试行五:完结keepaplived自定义脚本检测成效

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

 

方案意气风发:检查评定是不是留存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回到主上,主复苏服务;

  

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图