高可用架构二基于HAProxy+Keepalived高可用负载均衡web服务的搭建

Posted python运维实践

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高可用架构二基于HAProxy+Keepalived高可用负载均衡web服务的搭建相关的知识,希望对你有一定的参考价值。

一.高可用

1.1.什么是高可用?

计算机系统的可用性(availability)是通过系统的可靠性(reliability)和可维护性(maintainability)来度量的。 工程上通常用平均无故障时间(MTTF)来度量系统的可靠性,用平均维修时间(MTTR)来度量系统的可维护性。 于是可用性被定义为: MTTF/(MTTF+MTTR)*100%

2)HA的容错备援运作过程自动侦测(Auto-Detect)阶段 由主机上的软件通过冗余侦测线,经由复杂的监听程序。逻辑判断,来相互侦测对方运行的情况,所检查的项目有:主机硬件(CPU和周边)、主机网络、主机操作系统、数据库引擎及其它应用程序、主机与磁盘阵列连线。为确保侦测的正确性,而防止错误的判断,可设定安全侦测时间,包括侦测时间间隔,侦测次数以调整安全系数,并且由主机的冗余通信连线,将所汇集的讯息记录下来,以供维护参考。 自动切换(Auto-Switch)阶段 某一主机如果确认对方故障,则正常主机除继续进行原来的任务,还将依据各种容错备援模式接管预先设定的备援作业程序,并进行后续的程序及服务。 自动恢复(Auto-Recovery)阶段 在正常主机代替故障主机工作后,故障主机可离线进行修复工作。在故障主机修复后,透过冗余通讯线与原正常主机连线,自动切换回修复完成的主机上。整个回复过程完成由EDI-HA自动完成,亦可依据预先配置,选择回复动作为半自动或不回复。

1.2.HA三种工作方式:

(1)主从方式 (非对称方式)工作原理:主机工作,备机处于监控准备状况;当主机宕机时,备机接管主机的一切工作,待主机恢复正常后,按使用者的设定以自动或手动方式将服务切换到主机上运行,数据的一致性通过共享存储系统解决。(2)双机双工方式(互备互援)工作原理:两台主机同时运行各自的服务工作且相互监测情况,当任一台主机宕机时,另一台主机立即接管它的一切工作,保证工作实时,应用服务系统的关键数据存放在共享存储系统中。(3)集群工作方式(多服务器互备方式)工作原理:多台主机一起工作,各自运行一个或几个服务,各为服务定义一个或多个备用主机,当某个主机故障时,运行在其上的服务就可以被其它主机接管。

二.集群

2.1 什么是集群?

简单的说,集群(cluster)就是一组计算机,它们作为一个整体向用户提供一组网络资源。这些单个的计算机系统就是集群的节点(node)。 更详细的说,集群(一组协同工作的计算机)是充分利用计算资源的一个重要概念,因为它能够将工作负载从一个超载的系统(或节点)迁移到集群中的另一个系统上。其处理能力是与专用计算机(小型机,大型机)可相比,但其性价比高于专用计算机. 常见的硬件有:结点,网络,存储,软件有:机群系统,节点系统,应用支撑软件。 Cluster集群技术可如下定义:一组相互独立的服务器在网络中表现为单一的系统,并以单一系统的模式加以管理。此单一系统为客户工作站提供高可靠性的服务。大多数模式下,集群中所有的计算机拥有一个共同的名称,集群内任一系统上运行的服务可被所有的网络客户所使用。Cluster必须可以协调管理各分离的组件的错误和失败,并可透明地向Cluster中加入组件。一个Cluster包含多台(至少二台)拥有共享数据存储空间的服务器。任何一台服务器运行一个应用时,应用数据被存储在共享的数据空间内。每台服务器的操作系统和应用程序文件存储在其各自的本地储存空间上。Cluster内各节点服务器通过一内部局域网相互通讯。当一台节点服务器发生故障时,这台服务器上所运行的应用程序将在另一节点服务器上被自动接管。当一个应用服务发生故障时,应用服务将被重新启动或被另一台服务器接管。当以上的任一故障发生时,客户都将能很快连接到新的应用服务上。

2.2 集群系统的主要优点:

  • (1)高可扩展性:

  • (2)高可用性HA:集群中的一个节点失效,它的任务可传递给其他节点。可以有效防止单点失效。

  • (3)高性能:负载平衡集群允许系统同时接入更多的用户。

  • (4)高性价比:可以采用廉价的符合工业标准的硬件构造高性能的系统。

2.3 集群系统的分类

虽然,根据集群系统的不同特征可以有多种分类方法,但是一般把集群系统分为两类:

  • (1)高可用(High Availability)集群,简称HA集群。 这类集群致力于提供高度可靠的服务。就是利用集群系统的容错性对外提供7*24小时不间断的服务,如高可用的文件服务器、数据库服务等关键应用。 负载均衡集群:使任务可以在集群中尽可能平均地分摊不同的计算机进行处理,充分利用集群的处理能力,提高对任务的处理效率。 在实际应用中这几种集群类型可能会混合使用,以提供更加高效稳定的服务。如在一个使用的网络流量负载均衡集群中,就会包含高可用的网络文件系统、高可用的网络服务。

  • (2)、性能计算(High Perfermance Computing)集群,简称HPC集群,也称为科学计算集群。 在这种集群上运行的是专门开发的并行应用程序,它可以把一个问题的数据分布到多台的计算机上,利用这些计算机的共同资源来完成计算任务,从而可以解决单机不能胜任的工作(如问题规模太大,单机计算速度太慢)。 这类集群致力于提供单个计算机所不能提供的强大的计算能力。如天气预报、石油勘探与油藏模拟、分子模拟、生物计算等。

三.Keepalived

3.1简介

Keepalived的作用是检测服务器的状态,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工作正常后Keepalived自动将服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的服务器。

3.2原理

3.3作用

主要用作RealServer的健康状态检查以及LoadBalance主机和BackUP主机之间failover的实现。

四.实现架构

【高可用架构二】基于HAProxy+Keepalived高可用负载均衡web服务的搭建


场景说明:

1.服务器操作系统

5台服务器均为centos7.3操作系统

2.应用软件

 
   
   
 
  1. [root@node01 ~]# rpm -qa | grep haproxy

  2. haproxy-1.5.18-7.el7.x86_64

  3. [root@node01 /]# rpm -qa | grep keepalived

  4. keepalived-1.3.5-6.el7.x86_64

  5. [root@node01 /]#

  6. [root@web01 ~]# httpd -v

  7. Server version: Apache/2.4.6 (CentOS)

  8. Server built:   Apr 20 2018 18:10:38    

3.服务器IP规划

负载均衡器2台: 192.168.150.71/24 192.168.150.72/24 虚拟IP: 192.168.150.70/24 Web服务器3台: 192.168.150.73/24 192.168.150.74/24 192.168.150.75/24

五.系统软件安装与部署

本次主要配置haproxy+keepalived实现高可用负载均衡的功能。 2台haproxy提供负载均衡和应用代理服务。 其中node01作为主服务器MASTER,node02作为备份服务器BACKUP。 对外表现为一个虚拟IP,主服务器会发送特定的消息给备份服务器,当备份服务器收不到这个消息的时候,即主服务器宕机的时候,备份服务器就会接管虚拟IP,继续提供服务,从而保证了高可用性。Keepalived是VRRP的完美实现。

1.安装前的准备工作

 
   
   
 
  1. [root@node01 ~]# systemctl disable firewalld

  2. [root@node01 ~]# systemctl stop firewalld

  3. [root@node01 ~]#

  4. [root@node01 ~]# vi /etc/sysconfig/selinux

  5. This file controls the state of SELinux on the system.

  6. # SELINUX= can take one of these three values:

  7. #     enforcing - SELinux security policy is enforced.

  8. #     permissive - SELinux prints warnings instead of enforcing.

  9. #     disabled - No SELinux policy is loaded.

  10. SELINUX=disabled

  11. # SELINUXTYPE= can take one of three two values:

  12. #     targeted - Targeted processes are protected,

  13. #     minimum - Modification of targeted policy. Only selected processes are protected.

  14. #     mls - Multi Level Security protection.

  15. SELINUXTYPE=targeted

在备份节点上node02进行同样的操作。

2.yum方式安装haproxy和keepalived软件

在两台负载均衡服务器node01和node02上安装:

 
   
   
 
  1. [root@node01 /]# yum install haproxy keepalived -y

  2. 已加载插件:fastestmirror, langpacks

  3. base                                                                                                                                                                      | 3.6 kB  00:00:00    

  4. extras                                                                                                                                                                    | 3.4 kB  00:00:00    

  5. updates                                                                                                                                                                   | 3.4 kB  00:00:00    

  6. updates/7/x86_64/primary_db                                                                                                                                               | 2.0 MB  00:00:00    

  7. Loading mirror speeds from cached hostfile

  8. * base: mirrors.aliyun.com

  9. * extras: mirrors.huaweicloud.com

  10. * updates: mirrors.huaweicloud.com

  11. 软件包 haproxy-1.5.18-7.el7.x86_64 已安装并且是最新版本

  12. 软件包 keepalived-1.3.5-6.el7.x86_64 已安装并且是最新版本

  13. 无须任何处理

  14. [root@node01 /]#

3.配置keepalived主节点和备份节点及通知脚本

1)主节点配置文件

 
   
   
 
  1. [root@node01 keepalived]# pwd

  2. /etc/keepalived

  3. [root@node01 keepalived]# cat keepalived.conf

  4. ! Configuration File for keepalived

  5. global_defs {

  6.   notification_email {

  7.    root@localhost

  8.   }

  9.   notification_email_from keepalived@localhost

  10.   smtp_server 127.0.0.1

  11.   smtp_connect_timeout 30

  12.   router_id node01

  13.   vrrp_macst_group4 224.0.100.19

  14. }

  15. vrrp_instance http {

  16.    state MASTER

  17.    interface enp2s0

  18.    virtual_router_id 51

  19.    priority 100

  20.    advert_int 1

  21.    authentication {

  22.        auth_type PASS

  23.    auth_pass haopython

  24.    }

  25.    virtual_ipaddress {

  26.        192.168.150.70/24 dev enp2s0

  27.    }

  28. }

  29. notify_master "/etc/keepalived/notify.sh master"

  30. notify_backup "/etc/keepalived/notify.sh backup"

  31. notify_fault "/etc/keepalived/notify.sh fault"

  32. }

  33. [root@node01 keepalived]#

2)备份节点配置文件:

 
   
   
 
  1. [root@node02 keepalived]# pwd

  2. /etc/keepalived

  3. [root@node02 keepalived]# ls

  4. keepalived.conf  notify.sh

  5. [root@node02 keepalived]# cat keepalived.conf

  6. ! Configuration File for keepalived

  7. global_defs {

  8.   notification_email {

  9.    root@localhost

  10.   }

  11.   notification_email_from keepalived@localhost

  12.   smtp_server 127.0.0.1

  13.   smtp_connect_timeout 30

  14.   router_id inode2

  15.   vrrp_macst_group4 224.0.100.19

  16. }

  17. vrrp_instance http {

  18.    state BACKUP

  19.    interface enp2s0

  20.    virtual_router_id 51

  21.    priority 98

  22.    advert_int 1

  23.    authentication {

  24.        auth_type PASS

  25.    auth_pass haopython

  26.    }

  27.    virtual_ipaddress {

  28.        192.168.150.70/24 dev enp2s0

  29.    }

  30. }

  31. notify_master "/etc/keepalived/notify.sh master"

  32. notify_backup "/etc/keepalived/notify.sh backup"

  33. notify_fault "/etc/keepalived/notify.sh fault"

  34. }

  35. [root@node02 keepalived]#

3)编写通知脚本 在主备份服务器上编写如下脚本 主备一样:

 
   
   
 
  1. [root@node01 keepalived]# cat notify.sh

  2. #!/bin/bash

  3. #

  4. contact='root@localhost'

  5. notify() {

  6. mailsubject="$(hostname) to be $1, vip floating"

  7. mailbody="$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1"

  8. echo "$mailbody" | mail -s "$mailsubject" $contact

  9. }

  10. case $1 in

  11. master)

  12. notify master

  13. ;;

  14. backup)

  15. notify backup

  16. ;;

  17. fault)

  18. notify fault

  19. ;;

  20. *)

  21. echo "Usage: $(basename $0) {master|backup|fault}"

  22. exit 1

  23. ;;

  24. esac

  25. [root@node01 keepalived]#

备份节点

 
   
   
 
  1. [root@node02 keepalived]# cat notify.sh

  2. #!/bin/bash

  3. #

  4. contact='root@localhost'

  5. notify() {

  6. mailsubject="$(hostname) to be $1, vip floating"

  7. mailbody="$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1"

  8. echo "$mailbody" | mail -s "$mailsubject" $contact

  9. }

  10. case $1 in

  11. master)

  12. notify master

  13. ;;

  14. backup)

  15. notify backup

  16. ;;

  17. fault)

  18. notify fault

  19. ;;

  20. *)

  21. echo "Usage: $(basename $0) {master|backup|fault}"

  22. exit 1

  23. ;;

  24. esac

  25. [root@node02 keepalived]# pwd

  26. /etc/keepalived

  27. [root@node02 keepalived]#

4.配置haproxy

Node01和node02两个节点的配置是一样的

 
   
   
 
  1. [root@node01 haproxy]# pwd

  2. /etc/haproxy

  3. [root@node01 haproxy]# cat haproxy.cfg

  4. #---------------------------------------------------------------------

  5. # Example configuration for a possible web application.  See the

  6. # full configuration options online.

  7. #

  8. #   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt

  9. #

  10. #---------------------------------------------------------------------

  11. #---------------------------------------------------------------------

  12. # Global settings

  13. #---------------------------------------------------------------------

  14. global

  15.    # to have these messages end up in /var/log/haproxy.log you will

  16.    # need to:

  17.    #

  18.    # 1) configure syslog to accept network log events.  This is done

  19.    #    by adding the '-r' option to the SYSLOGD_OPTIONS in

  20.    #    /etc/sysconfig/syslog

  21.    #

  22.    # 2) configure local2 events to go to the /var/log/haproxy.log

  23.    #   file. A line like the following can be added to

  24.    #   /etc/sysconfig/syslog

  25.    #

  26.    #    local2.*                       /var/log/haproxy.log

  27.    #

  28.    log         127.0.0.1 local2

  29.    chroot      /var/lib/haproxy

  30.    pidfile     /etc/haproxy/haproxy.cfg

  31.    maxconn     4000

  32.    user        haproxy

  33.    group       haproxy

  34.    daemon

  35.    # turn on stats unix socket

  36.    stats socket /var/lib/haproxy/stats

  37. #---------------------------------------------------------------------

  38. # common defaults that all the 'listen' and 'backend' sections will

  39. # use if not designated in their block

  40. #---------------------------------------------------------------------

  41. defaults

  42.    mode                    http

  43.    log                     global

  44.    option                  httplog

  45.    option                  dontlognull

  46.    option http-server-close

  47.    option forwardfor       except 127.0.0.0/8

  48.    option                  redispatch

  49.    retries                 3

  50.    timeout http-request    10s

  51.    timeout queue           1m

  52.    timeout connect         10s

  53.    timeout client          1m

  54.    timeout server          1m

  55.    timeout http-keep-alive 10s

  56.    timeout check           10s

  57.    maxconn                 3000

  58. #---------------------------------------------------------------------

  59. # main frontend which proxys to the backends

  60. #---------------------------------------------------------------------

  61. frontend  web *:80

  62.    acl url_static       path_beg       -i /static /images /javascript /stylesheets

  63.    acl url_static       path_end       -i .jpg .gif .png .css .js

  64.    use_backend static          if url_static

  65.    default_backend             app

  66. #---------------------------------------------------------------------

  67. # static backend for serving up images, stylesheets and such

  68. #---------------------------------------------------------------------

  69. backend static

  70.    balance     roundrobin

  71.    server      static1 192.168.150.73:80 check

  72.    server      static2 192.168.150.74:80 check

  73. #---------------------------------------------------------------------

  74. # round robin balancing between the various backends

  75. #---------------------------------------------------------------------

  76. backend app

  77.    balance     roundrobin

  78.    server  app1 192.168.150.73:80 check

  79.    server  app2 192.168.150.74:80 check

  80. listen stats

  81.    bind :10086

  82.    stats   uri     /admin?stats

  83.    stats   auth    admin:admin

  84.    stats   admin   if TRUE

  85. [root@node01 haproxy]#

六.启动服务

 
   
   
 
  1. [root@node01 /]# systemctl start haproxy

  2. [root@node01 /]# systemctl start keepalived

  3. [root@node01 /]#

  4. [root@node02 /]# systemctl start haproxy

  5. [root@node02 /]# systemctl start keepalived

  6. [root@node02 /]#

七.测试服务启动情况

Node01节点:

 
   
   
 
  1. [root@node01 /]# systemctl start keepalived

  2. [root@node01 /]# systemctl status -l keepalived

  3. ● keepalived.service - LVS and VRRP High Availability Monitor

  4.   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)

  5.   Active: active (running) since 二 2018-05-29 08:49:17 CST; 55min ago

  6.  Process: 27208 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)

  7. Main PID: 27211 (keepalived)

  8.   CGroup: /system.slice/keepalived.service

  9.           ├─27211 /usr/sbin/keepalived -D

  10.           ├─27212 /usr/sbin/keepalived -D

  11.           └─27213 /usr/sbin/keepalived -D

  12. 529 08:49:18 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  13. 529 08:49:18 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  14. 529 08:49:18 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  15. 529 08:49:18 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  16. 529 08:49:23 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  17. 529 08:49:23 node01 Keepalived_vrrp[27213]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on enp2s0 for 192.168.150.70

  18. 529 08:49:23 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  19. 529 08:49:23 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  20. 529 08:49:23 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  21. 529 08:49:23 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  22. [root@node01 /]#

NODE02节点:

 
   
   
 
  1. [root@node02 /]# systemctl status -l keepalived

  2. ● keepalived.service - LVS and VRRP High Availability Monitor

  3.   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)

  4.   Active: active (running) since 六 2018-05-26 10:26:44 CST; 2 days ago

  5.  Process: 3143 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)

  6. Main PID: 3144 (keepalived)

  7.   CGroup: /system.slice/keepalived.service

  8.           ├─3144 /usr/sbin/keepalived -D

  9.           ├─3145 /usr/sbin/keepalived -D

  10.           └─3146 /usr/sbin/keepalived -D

  11. 529 08:48:36 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  12. 529 08:48:41 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  13. 529 08:48:41 node02 Keepalived_vrrp[3146]: VRRP_Instance(http) Sending/queueing gratuitous ARPs on enp2s0 for 192.168.150.70

  14. 529 08:48:41 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  15. 529 08:48:41 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  16. 529 08:48:41 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  17. 529 08:48:41 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  18. 529 08:49:17 node02 Keepalived_vrrp[3146]: VRRP_Instance(http) Received advert with higher priority 100, ours 98

  19. 529 08:49:17 node02 Keepalived_vrrp[3146]: VRRP_Instance(http) Entering BACKUP STATE

  20. 529 08:49:17 node02 Keepalived_vrrp[3146]: VRRP_Instance(http) removing protocol VIPs.

  21. [root@node02 /]#

NODE01节点:

 
   
   
 
  1. [root@node01 /]# systemctl status -l haproxy

  2. ● haproxy.service - HAProxy Load Balancer

  3.   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)

  4.   Active: active (running) since 二 2018-05-29 08:49:08 CST; 58min ago

  5. Main PID: 27195 (haproxy-systemd)

  6.   CGroup: /system.slice/haproxy.service

  7.           ├─27195 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid

  8.           ├─27197 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  9.           └─27199 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  10. 529 08:49:08 node01 systemd[1]: Started HAProxy Load Balancer.

  11. 529 08:49:08 node01 systemd[1]: Starting HAProxy Load Balancer...

  12. 529 08:49:08 node01 haproxy-systemd-wrapper[27195]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  13. [root@node01 /]#

NODE02节点:

 
   
   
 
  1. [root@node02 /]# systemctl status -l haproxy

  2. ● haproxy.service - HAProxy Load Balancer

  3.   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)

  4.   Active: active (running) since 二 2018-05-29 08:46:45 CST; 1h 2min ago

  5. Main PID: 8945 (haproxy-systemd)

  6.   CGroup: /system.slice/haproxy.service

  7.           ├─8945 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid

  8.           ├─8946 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  9.           └─8947 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  10. 529 08:46:45 node02 systemd[1]: Started HAProxy Load Balancer.

  11. 529 08:46:45 node02 systemd[1]: Starting HAProxy Load Balancer...

  12. 529 08:46:45 node02 haproxy-systemd-wrapper[8945]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  13. [root@node02 /]#

下面停掉NODE01节点,然后在NODE02上查看NODE02的状态变化

 
   
   
 
  1. [root@node01 /]# systemctl stop haproxy

  2. [root@node01 /]# systemctl stop keepalived

  3. [root@node01 /]#

 
   
   
 
  1. [root@node02 /]# systemctl status -l keepalived

  2. ● keepalived.service - LVS and VRRP High Availability Monitor

  3.   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)

  4.   Active: active (running) since 六 2018-05-26 10:26:44 CST; 2 days ago

  5.  Process: 3143 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)

  6. Main PID: 3144 (keepalived)

  7.   CGroup: /system.slice/keepalived.service

  8.           ├─3144 /usr/sbin/keepalived -D

  9.           ├─3145 /usr/sbin/keepalived -D

  10.           └─3146 /usr/sbin/keepalived -D

  11. 529 10:00:52 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  12. 529 10:00:52 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  13. 529 10:00:52 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  14. 529 10:00:52 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  15. 529 10:00:57 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  16. 529 10:00:57 node02 Keepalived_vrrp[3146]: VRRP_Instance(http) Sending/queueing gratuitous ARPs on enp2s0 for 192.168.150.70

  17. 529 10:00:57 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  18. 529 10:00:57 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  19. 529 10:00:57 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  20. 529 10:00:57 node02 Keepalived_vrrp[3146]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  21. [root@node02 /]#

  22. [root@node02 /]#

  23. [root@node02 /]# systemctl status -l haproxy

  24. ● haproxy.service - HAProxy Load Balancer

  25.   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)

  26.   Active: active (running) since 二 2018-05-29 08:46:45 CST; 1h 14min ago

  27. Main PID: 8945 (haproxy-systemd)

  28.   CGroup: /system.slice/haproxy.service

  29.           ├─8945 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid

  30.           ├─8946 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  31.           └─8947 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  32. 529 08:46:45 node02 systemd[1]: Started HAProxy Load Balancer.

  33. 529 08:46:45 node02 systemd[1]: Starting HAProxy Load Balancer...

  34. 529 08:46:45 node02 haproxy-systemd-wrapper[8945]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

  35. [root@node02 /]#

Node01节点:

 
   
   
 
  1. [root@node01 /]# systemctl status -l keepalived

  2. ● keepalived.service - LVS and VRRP High Availability Monitor

  3.   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)

  4.   Active: inactive (dead)

  5. 529 08:49:23 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  6. 529 08:49:23 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  7. 529 08:49:23 node01 Keepalived_vrrp[27213]: Sending gratuitous ARP on enp2s0 for 192.168.150.70

  8. 529 10:00:51 node01 Keepalived[27211]: Stopping

  9. 529 10:00:51 node01 systemd[1]: Stopping LVS and VRRP High Availability Monitor...

  10. 529 10:00:51 node01 Keepalived_vrrp[27213]: VRRP_Instance(VI_1) sent 0 priority

  11. 529 10:00:51 node01 Keepalived_vrrp[27213]: VRRP_Instance(VI_1) removing protocol VIPs.

  12. 529 10:00:52 node01 Keepalived_vrrp[27213]: Stopped

  13. 529 10:00:52 node01 Keepalived[27211]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2

  14. 529 10:00:52 node01 systemd[1]: Stopped LVS and VRRP High Availability Monitor.

  15. [root@node01 /]#

八.在浏览器中查看和修改haproxy的相关参数

【高可用架构二】基于HAProxy+Keepalived高可用负载均衡web服务的搭建

【高可用架构二】基于HAProxy+Keepalived高可用负载均衡web服务的搭建


学习|生活|分享|积累|永不停步


请留下你指尖的温度

让太阳拥抱你

微信ID:goodpython


以上是关于高可用架构二基于HAProxy+Keepalived高可用负载均衡web服务的搭建的主要内容,如果未能解决你的问题,请参考以下文章

RabbitMQ---集群,Haproxy+Keepalive 实现高可用负载均衡,Federation Exchange和Federation Queue

keepalive高可用haproxy实现URL资源的动静分离

实现基于Haproxy+Keepalived负载均衡高可用架构

Keepalive+Haproxy高可用集群安装与配置

高可用haproxy调度varnish服务器缓存后端动静分离集群架构

高可用pxc+rocketmq+es+redis+minio+keepalive+haproxy 实操