双主模型高可用负载均衡集群的实现(keepalived+lvs-dr)

实现keepalived双主模型lvs高可用集群

一、拓扑图

二、环境准备

两台负载均衡调度器,两台web服务器。

调度器A环境:

VS:一张网卡

DIP:192.168.0.7/24

VIP(主):192.168.0.200

VIP(备):192.168.0.201

软件包:yum install -y keepalived ipvsadm nginx(作用:sorry-server服务)

调度器B环境:

VS:一张网卡

DIP:192.168.0.8/24

VIP(主):192.168.0.201

VIP(备):192.168.0.200

软件包:yum install -y keepalived ipvsadm nginx(作用:sorry-server服务)

web服务器A环境:

RS1:192.168.0.3

lo:0:192.168.0.200

lo:1:192.168.0.201

软件包:yum install -y httpd

web服务器B环境:

RS1:192.168.0.4

lo:0:192.168.0.200

lo:1:192.168.0.201

软件包:yum install -y httpd

三、配置

调度器A配置

主要操作:ip配置,时间同步、hosts文件更改,修改主机名(确保主从节点能够通信)、keepalived.conf配置文件更改,通知脚本配置(两个脚本),ipvsadm规则查看

ip配置

[[email protected]]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:0c:d2:06 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.7/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.0.200/24 scope global secondary ens33:1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe0c:d206/64 scope link 
       valid_lft forever preferred_lft forever

时间同步

ntpdate ntp-server-ip #时间服务器的ip

hosts文件

[[email protected] keepalived]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 node1
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 node1
192.168.0.8 node2
192.168.0.7 node1

主机名修改

hostnamectl set-hostname node1

keepalived.conf配置文件更改

[[email protected] keepalived]# cat keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1 
   smtp_connect_timeout 10
   router_id node1
vrrp_mcast_group4 224.0.0.223
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 110
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass JzvnmfkY 
    }
    virtual_ipaddress {
        192.168.0.200/24 dev ens33 label ens33:1
    }
notify_master "/etc/keepalived/notify1.sh master"
notify_backup "/etc/keepalived/notify1.sh backup"
notify_fault "/etc/keepalived/notify1.sh fault"
}
virtual_server 192.168.0.200 80 {
    delay_loop 3
    lb_algo wrr
    lb_kind DR
    protocol TCP
    sorry_server 127.0.0.1 80
    real_server 192.168.0.3 80 {
        weight 2
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.0.4 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
}
}
vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 52
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass JzvnmfkY 
    }
    virtual_ipaddress {
        192.168.0.201/24 dev ens33 label ens33:2
    }
notify_master "/etc/keepalived/notify2.sh master"
notify_backup "/etc/keepalived/notify2.sh backup"
notify_fault "/etc/keepalived/notify2.sh fault"
}
virtual_server 192.168.0.201 80 {
    delay_loop 3
    lb_algo wrr
    lb_kind DR
    protocol TCP
    sorry_server 127.0.0.1 80
    real_server 192.168.0.3 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.0.4 80 {
        weight 2
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
}
}

通知脚本配置

脚本1

[[email protected] keepalived]# cat notify1.sh 
#!/bin/bash
#description: An example of notify script
#
vip=192.168.0.200
contact=‘[email protected]‘
notify(){
local mailsubject="$(hostname) to be $1:$vip floating"
local mailbody="$(date +‘%F %T‘):vrrp1 transition,$(hostname) changed to be $1"
echo "$mailbody" | mail -s "$mailsubject" $contact
}
case $1 in
master)
notify master
;;
backup)
notify backup
;;
fault)
notify fault
;;
*)
echo "Usage:$(basename $0) {master|backup|fault}"
exit 1
;;
esac

脚本2

[[email protected] keepalived]# cat notify2.sh 
#!/bin/bash
#description: An example of notify script
#
vip=192.168.0.201
contact=‘[email protected]‘
notify(){
local mailsubject="$(hostname) to be $1:$vip floating"
local mailbody="$(date +‘%F %T‘):vrrp2 transition,$(hostname) changed to be $1"
echo "$mailbody" | mail -s "$mailsubject" $contact
}
case $1 in
master)
notify master
;;
backup)
notify backup
;;
fault)
notify fault
;;
*)
echo "Usage:$(basename $0) {master|backup|fault}"
exit 1
;;
esac

ipvsadm规则查看

[[email protected] keepalived]# 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.0.200:80 wrr
  -> 192.168.0.3:80               Route   2      0          0         
  -> 192.168.0.4:80               Route   1      0          0         
TCP  192.168.0.201:80 wrr
  -> 192.168.0.3:80               Route   1      0          0         
  -> 192.168.0.4:80               Route   2      0          0

调度器B配置

主要操作:ip配置,时间同步、hosts文件更改,修改主机名(确保主从节点能够通信)、keepalived.conf配置文件更改,通知脚本配置(两个脚本),ipvsadm规则查看

ip配置

[[email protected] keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:3f:e3:9e brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.8/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.0.201/24 scope global secondary ens33:2
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe3f:e39e/64 scope link 
       valid_lft forever preferred_lft forever

时间同步

ntpdate ntp-server-ip

hosts文件更改

[[email protected] keepalived]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 node2
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 node2
192.168.0.7 node1
192.168.0.8 node2

主机名修改

hostnamectl set-hostname node2

keepalived.conf配置文件更改

[[email protected] keepalived]# cat keepalived.conf 
! Configuration File for keepalived
global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1 
   smtp_connect_timeout 10
   router_id node2
vrrp_mcast_group4 224.0.0.223
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass JzvnmfkY 
    }
    virtual_ipaddress {
        192.168.0.200/24 dev ens33 label ens33:1
    }
        notify_master "/etc/keepalived/notify1.sh master"
        notify_backup "/etc/keepalived/notify1.sh backup"
        notify_fault "/etc/keepalived/notify1.sh fault"
}
virtual_server 192.168.0.200 80 {
    delay_loop 3
    lb_algo wrr
    lb_kind DR
    protocol TCP
sorry_server 127.0.0.1 80
    real_server 192.168.0.3 80 {
        weight 2
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.0.4 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
}
}
vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass JzvnmfkY
    }
    virtual_ipaddress {
        192.168.0.201/24 dev ens33 label ens33:2
    }
        notify_master "/etc/keepalived/notify2.sh master"
        notify_backup "/etc/keepalived/notify2.sh backup"
        notify_fault "/etc/keepalived/notify2.sh fault"
}
virtual_server 192.168.0.201 80 {
    delay_loop 3
    lb_algo wrr
    lb_kind DR
    protocol TCP
sorry_server 127.0.0.1 80
    real_server 192.168.0.3 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.0.4 80 {
        weight 2
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
}
}

通知脚本配置(同调度器A的脚本一致)

脚本1

[[email protected] keepalived]# cat notify1.sh 
#!/bin/bash
#description: An example of notify script
#
vip=192.168.0.200
contact=‘[email protected]‘
notify(){
local mailsubject="$(hostname) to be $1:$vip floating"
local mailbody="$(date +‘%F %T‘):vrrp1 transition,$(hostname) changed to be $1"
echo "$mailbody" | mail -s "$mailsubject" $contact
}
case $1 in
master)
notify master
;;
backup)
notify backup
;;
fault)
notify fault
;;
*)
echo "Usage:$(basename $0) {master|backup|fault}"
exit 1
;;
esac

脚本2

[[email protected] keepalived]# cat notify2.sh 
#!/bin/bash
#description: An example of notify script
#
vip=192.168.0.201
contact=‘[email protected]‘
notify(){
local mailsubject="$(hostname) to be $1:$vip floating"
local mailbody="$(date +‘%F %T‘):vrrp2 transition,$(hostname) changed to be $1"
echo "$mailbody" | mail -s "$mailsubject" $contact
}
case $1 in
master)
notify master
;;
backup)
notify backup
;;
fault)
notify fault
;;
*)
echo "Usage:$(basename $0) {master|backup|fault}"
exit 1
;;
esac

web服务器A配置

ip配置

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 192.168.0.201/32 brd 192.168.0.201 scope global lo:1
       valid_lft forever preferred_lft forever
    inet 192.168.0.200/32 brd 192.168.0.200 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ab:50:14 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.4/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feab:5014/64 scope link 
       valid_lft forever preferred_lft forever

lvs-dr-预配置脚本

脚本1

[[email protected] ~]# cat vip200-setrs.sh 
#!/bin/bash
#
vip=192.168.0.200
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

脚本2

[[email protected] ~]# cat vip201-setrs.sh 
#!/bin/bash
#
vip=192.168.0.201
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

web服务器B配置

ip配置

[[email protected] ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 192.168.0.201/32 brd 192.168.0.201 scope global lo:1
       valid_lft forever preferred_lft forever
    inet 192.168.0.200/32 brd 192.168.0.200 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ab:50:14 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.4/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feab:5014/64 scope link 
       valid_lft forever preferred_lft forever

lvs-dr-预设脚本

脚本内容同web服务A相同,拷贝过去即可

vip200-setrs.sh  vip201-setrs.sh

客户端测试

ip配置

[[email protected] ~]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d0:37:77 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.14/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed0:3777/64 scope link 
       valid_lft forever preferred_lft forever

curl测试

 [[email protected] ~]# for i in {1..10};do curl http://192.168.0.200;done
backend server1
backend server1
backend server2
backend server1
backend server1
backend server2
backend server1
backend server1
backend server2
backend server1
[[email protected] ~]# for i in {1..10};do curl http://192.168.0.201;done
backend server1
backend server2
backend server2
backend server1
backend server2
backend server2
backend server1
backend server2
backend server2
backend server1

四、健康状态查看以及故障排查参考方式

方式1:查看keepalived的切换过程

systemctl status keepalived

方式2:mail命令查看邮件

方式3:查看web服务器日志

tail /var/log/httpd/access_log

tail /var/log/httpd/error_log

五、模拟故障

1.模拟调度器B故障

调度器B上操作

停止keepalived服务

systemctl stop keepalived
[[email protected] keepalived]# systemctl status keepalived #分析以下信息,VIP2已移除
Jul 02 10:18:53 node2 systemd[1]: Stopping LVS and VRRP High Availability Monitor...
Jul 02 10:18:53 node2 Keepalived_vrrp[50773]: VRRP_Instance(VI_2) sending 0 priority
Jul 02 10:18:53 node2 Keepalived_vrrp[50773]: VRRP_Instance(VI_2) removing protocol VIPs.
Jul 02 10:18:53 node2 systemd[1]: Stopped LVS and VRRP High Availability Monitor.

查看ip

[[email protected] keepalived]# ip a           #VIP2移除
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:3f:e3:9e brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.8/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe3f:e39e/64 scope link 
       valid_lft forever preferred_lft forever

调度器A操作

[[email protected] keepalived]# systemctl status keepalived #分析以下信息,可知VIP漂移到调度A
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2017-07-02 10:07:36 CST; 17min ago
  Process: 20019 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 20020 (keepalived)
   CGroup: /system.slice/keepalived.service
           ├─20020 /usr/sbin/keepalived -D
           ├─20021 /usr/sbin/keepalived -D
           └─20022 /usr/sbin/keepalived -D
Jul 02 10:07:37 node1 Keepalived_vrrp[20022]: Opening script file /etc/keepalived/notify1.sh
Jul 02 10:07:37 node1 Keepalived_healthcheckers[20021]: Netlink reflector reports IP 192.168.0.200 added
Jul 02 10:07:42 node1 Keepalived_vrrp[20022]: VRRP_Instance(VI_1) Sending gratuitous ARPs on ens33 for 192.168.0.200
Jul 02 10:18:54 node1 Keepalived_vrrp[20022]: VRRP_Instance(VI_2) Transition to MASTER STATE
Jul 02 10:18:55 node1 Keepalived_vrrp[20022]: VRRP_Instance(VI_2) Entering MASTER STATE
Jul 02 10:18:55 node1 Keepalived_vrrp[20022]: VRRP_Instance(VI_2) setting protocol VIPs.
Jul 02 10:18:55 node1 Keepalived_vrrp[20022]: VRRP_Instance(VI_2) Sending gratuitous ARPs on ens33 for 192.168.0.201
Jul 02 10:18:55 node1 Keepalived_vrrp[20022]: Opening script file /etc/keepalived/notify2.sh
Jul 02 10:18:55 node1 Keepalived_healthcheckers[20021]: Netlink reflector reports IP 192.168.0.201 added
Jul 02 10:19:00 node1 Keepalived_vrrp[20022]: VRRP_Instance(VI_2) Sending gratuitous ARPs on ens33 for 192.168.0.201

查看邮件

[[email protected] keepalived]# mail        #node1成为VIP192.168.0.201的主节点
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 1 message
>   1 root                  Sun Jul  2 10:18  19/702   "node1 to be master:192.168.0.201 floating"
& 1  
Message  1:
From [email protected]  Sun Jul  2 10:18:55 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Sun, 02 Jul 2017 10:18:55 +0800
To: [email protected]
Subject: node1 to be master:192.168.0.201 floating
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: RO
2017-07-02 10:18:55:vrrp2 transition,node1 changed to be master

2.模拟web服务器A故障(RS1)

webA上操作

[[email protected] ~]# systemctl stop httpd

调度器A上操作

查看邮件

[[email protected] keepalived]# mail #分析以下信息,可知RS1宕机
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 4 messages 2 new
    1 root                  Sun Jul  2 10:18  19/702   "node1 to be master:192.168.0.201 floating"
    2 root                  Sun Jul  2 10:28  19/702   "node1 to be backup:192.168.0.201 floating"
>N  3 [email protected]  Sun Jul  2 10:28  17/642   "[node1] Realserver [192.168.0.3]:80 - DOWN"
 N  4 [email protected]  Sun Jul  2 10:28  17/642   "[node1] Realserver [192.168.0.3]:80 - DOWN"

客户端请求查看

[[email protected] ~]# curl http://192.168.0.200 #只能访问到RS2
backend server2

调度器B上操作

[[email protected] keepalived]# mail #分析以下信息,可知RS1宕机
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 4 messages 2 new
    1 root                  Sun Jul  2 10:28  19/702   "node2 to be backup:192.168.0.200 floating"
    2 root                  Sun Jul  2 10:28  19/702   "node2 to be master:192.168.0.201 floating"
>N  3 [email protected]  Sun Jul  2 10:28  17/642   "[node2] Realserver [192.168.0.3]:80 - DOWN"
 N  4 [email protected]  Sun Jul  2 10:28  17/642   "[node2] Realserver [192.168.0.3]:80 - DOWN"

3.模拟web服务双机故障

RS1和RS2停止web服务

调度器A上操作

查看邮件                #分析以下信息,可知双机宕机

    [[email protected] keepalived]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 6 messages 2 new
    1 root                  Sun Jul  2 10:18  19/702   "node1 to be master:192.168.0.201 floating"
    2 root                  Sun Jul  2 10:28  19/702   "node1 to be backup:192.168.0.201 floating"
    3 [email protected]  Sun Jul  2 10:28  18/653   "[node1] Realserver [192.168.0.3]:80 - DOWN"
    4 [email protected]  Sun Jul  2 10:28  18/653   "[node1] Realserver [192.168.0.3]:80 - DOWN"
>N  5 [email protected]  Sun Jul  2 10:36  17/642   "[node1] Realserver [192.168.0.4]:80 - DOWN"
 N  6 [email protected]  Sun Jul  2 10:36  17/642   "[node1] Realserver [192.168.0.4]:80 - DOWN"

查看keepalived状态

[[email protected] keepalived]# systemctl status keepalived    #分析以下信息,双机宕机,启动sorry服务器  
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2017-07-02 10:07:36 CST; 30min ago
  Process: 20019 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 20020 (keepalived)
   CGroup: /system.slice/keepalived.service
           ├─20020 /usr/sbin/keepalived -D
           ├─20021 /usr/sbin/keepalived -D
           └─20022 /usr/sbin/keepalived -D
Jul 02 10:36:31 node1 Keepalived_healthcheckers[20021]: Removing alive servers from the pool for VS [192.168.0.200]:80
Jul 02 10:36:31 node1 Keepalived_healthcheckers[20021]: Remote SMTP server [127.0.0.1]:25 connected.
Jul 02 10:36:31 node1 Keepalived_healthcheckers[20021]: SMTP alert successfully sent.
Jul 02 10:36:32 node1 Keepalived_healthcheckers[20021]: Error connecting server [192.168.0.4]:80.
Jul 02 10:36:32 node1 Keepalived_healthcheckers[20021]: Removing service [192.168.0.4]:80 from VS [192.168.0.201]:80
Jul 02 10:36:32 node1 Keepalived_healthcheckers[20021]: Lost quorum 1-0=1 > 0 for VS [192.168.0.201]:80
Jul 02 10:36:32 node1 Keepalived_healthcheckers[20021]: Adding sorry server [127.0.0.1]:80 to VS [192.168.0.201]:80
Jul 02 10:36:32 node1 Keepalived_healthcheckers[20021]: Removing alive servers from the pool for VS [192.168.0.201]:80
Jul 02 10:36:32 node1 Keepalived_healthcheckers[20021]: Remote SMTP server [127.0.0.1]:25 connected.
Jul 02 10:36:32 node1 Keepalived_healthcheckers[20021]: SMTP alert successfully sent.

客户端请求

[[email protected] ~]# curl http://192.168.0.201        #请求至sorry服务器的web页面
sorry server
[[email protected] ~]# curl http://192.168.0.200
sorry server
时间: 2024-10-23 08:18:40

双主模型高可用负载均衡集群的实现(keepalived+lvs-dr)的相关文章

LVS+Keepalived搭建MyCAT高可用负载均衡集群

LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一.目前有三种IP负载均衡技术(VS/NAT.VS/TUN和VS/DR),十种调度算法(rrr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq). Keepalvied Keepalived在这里主要用作RealServer的健康状态检查以及Mast

nginx+keepalived的高可用负载均衡集群构建

实验架构图: 实验环境 Nginx和Keepalived原理介绍 参考博客:http://467754239.blog.51cto.com/4878013/1541421 1.nginx Nginx进程基于于Master+Slave(worker)多进程模型,自身具有非常稳定的子进程管理功能.在Master进程分配模式下,Master进程永远不进行业务处理,只是进行任务分发, 从而达到Master进程的存活高可靠性,Slave(worker)进程所有的业务信号都 由主进程发出,Slave(wor

Keepalived+LVS(dr)高可用负载均衡集群的实现

一 环境介绍 1.操作系统CentOS Linux release 7.2.1511 (Core) 2.服务keepalived+lvs双主高可用负载均衡集群及LAMP应用keepalived-1.2.13-7.el7.x86_64ipvsadm-1.27-7.el7.x86_64httpd-2.4.6-45.el7.centos.x86_64mariadb-5.5.52-1.el7.x86_64php-5.4.16-42.el7.x86_64 二 原理及拓扑图 1.vrrp协议vrrp(Vir

Nginx高可用负载均衡集群实例架设

Nginx高可用负载均衡集群实例架设一. Nginx高可用集群拓扑架构 node1:17216.100.67node2:170.16.100.68VIP:172.16.100.89RS1:172.16.100.6RS2:172.16.100.69 注意:nginx的高可用集群架构的所有RS的内核参数arp_ignore和arp_announce都为0. 二. Nginx的高可用集群架设步骤1. 在所有node节点(172.16.100.67,172.16.100.68)上安装nginx服务.[e

DNS+keepalived+lvs实现高可用负载均衡集群

1.目的: 部署两台lvs调度器并利用keepalived实现主主模型,DNS添加两条A记录指向lvs调度器实现轮询,最终实现高可用负载均衡集群效果 2.拓扑规划: 3.配置实践 (1)同步所有机器时间 在每台机器实行ntp同步: [[email protected] ~]# ntpdate 10.1.0.1 26 Oct 20:10:57 ntpdate[5533]: step time server 10.1.0.1 offset -32408.643564 sec (2)先配置RS,在RS

Nginx+Keepalived搭建高可用负载均衡集群

Nginx+Keepalived搭建高可用负载均衡集群   一. 环境说明 前端双Nginx+keepalived,nginx反向代理到后端的tomcat集群实现负载均衡,Keepalived实现集群高可用. 操作系统: Centos 6.6_X64 Nginx版本: nginx-1.9.5 Keepalived版本:keepalived-1.2.13 结构: Keepalived+nginx-MASTER:10.6.1.210         Keepalived+nginx-BACKUP:

Haproxy+Keepalived搭建Weblogic高可用负载均衡集群

配置环境说明:   KVM虚拟机配置 用途 数量 IP地址 机器名 虚拟IP地址 硬件 内存3G  系统盘20G cpu 4核 Haproxykeepalived 2台 192.168.1.10192.168.1.20 Haserver01Haserver02 192.168.30192.168.40 内存6G  系统盘20G cpu 4核 Weblogic 4台 192.168.1.100192.168.1.150 192.168.1.200 192.168.1.250 Clusters01C

Keepalived+Nginx实现高可用负载均衡集群

一 环境介绍 1.操作系统CentOS Linux release 7.2.1511 (Core) 2.服务keepalived+lvs双主高可用负载均衡集群及LAMP应用keepalived-1.2.13-7.el7.x86_64nginx-1.10.2-1.el7.x86_64httpd-2.4.6-45.el7.centos.x86_64 二 原理及拓扑图 1.vrrp协议在现实的网络环境中,两台需要通信的主机大多数情况下并没有直接的物理连接.对于这样的情况,它们之间路由怎样选择?主机如何

HAProxy高可用负载均衡集群部署

HAProxy高可用负载均衡集群部署 基本信息: 系统平台:VMware WorkStation 系统版本: CentOS Linux release 7.2.1511 (Core) 内核版本: 3.10.0-327.el7.x86_64 集群架构: 前端:HAProxy 1.虚拟FQDN:www.simpletime.net 2.VIP:192.168.39.1:DIP:172.16.39.50 3.调度服务器:Varnish1.Varnish2 4.调度算法:URL_Hash_Consist