6要terwq 发表于 2017-10-30 10:19:56

Haproxy+keepalived做简单的高可用(主主模式)

Haproxy:

    Haproxy是一个开源的高性能的反向代理或者说是负载均衡服务软件之一,它支持双机热备、虚拟主
机、基于TCP和HTTP应用代理等功能。其配置简单,而且拥有很好的对服务器节点的健康检查功能(相当
于keepalived健康检查),当其代理的后端服务器出现故障时,Haproxy会自动的将该故障服务器摘除,
当服务器的故障恢复后Haproxy还会自动将RS服务器加入。
    HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费、快速
并且可靠的一种解决方案。HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持
或七层处理。HAProxy运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得
它可以很简单安全的整合进您当前的架构中,同时可以保护你的web服务器不被暴露到网络上。
   Haproxy 配置中分成五部分内容,分别如下:
    1、global:参数是进程级的,通常是和操作系统相关。这些参数一般只设置一次,如果配置无误,
就不需要再次进行修改
    2、defaults:配置默认参数,这些参数可以被用到frontend,backend,Listen组件

    3、frontend:接收请求的前端虚拟节点,Frontend可以更加规则直接指定具体使用后端的backend
    4、backend:后端服务集群的配置,是真实服务器,一个Backend对应一个或者多个实体服务器
    5、Listen Fronted和backend的组合体

Haproxy支持两种主要代理模式:

    第一个是4层tcp代理(例如:可用于邮件服务内部协议通信服务器、Mysql服务等)。Haproxy软件
的四层tcp代理应用非常优秀,配置非常简单方便,比LVS和Nginx要方便很多,因为不需要在RS端执行脚
本即可实现应用代理。说明:由于Haproxy采用的是NAT模式,数据包来去都会经过Haproxy,因此,在流
量特别大的情况下,其性能不如LVS。在一般的中小型公司,建议采用haproxy做负载均衡,而不要使用
LVS或者Nginx。
    第二个是7层代理(如HTTP代理)。在4层tcp代理模式下,Haproxy仅在客户端和服务器之间双向转
发流量。但是在7层模式下Haproxy会分析应用层协议,并且能通过运行、拒绝、交换、增加、修改或者
删除请求(request)或者回应(reponse)里指定内容来控制协议。Haproxy软件的最大优点在于其7层
的根据URL请求头应用过滤的功能,一般用在LVS软件的下一层,或者像官方推荐的可以挂在硬件负载均
衡NS、F5下使用。

搭建环境(CentOS 7)

拓扑图如下:



      主机         ip      角色

   haproxy-1      10.0.0.11haproxy+keepalivevip1:10.0.0.100
vip2:10.0.0.200

   haproxy-2
      10.0.0.12haproxy+keepalive
       web-1      10.0.0.13      web服务器

       web-2      10.0.0.13      web服务器


开始配置服务

1、先配置相关主机和相关时间同步服务器:

1
2
3
4
5
6
7
8
9
10
##关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
##关闭selinux
vim /etc/selinux/config
SELINUX=disabled
##同步时间
yum install -y ntpdate
crontab -e
*/5 * * * * ntpdate cn.pool.ntp.org





2、配置web服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
##安装apache服务
#yum install -y httpd
#echo "It is web1" >> /var/www/html/index.html
#systemctl restart httpd
#systemctl enable httpd
#yum install -y httpd
#echo "It is web2" >> /var/www/html/index.html
#systemctl restart httpd
#systemctl enable httpd

##访问web服务
# curl 10.0.0.13
It is web1
# curl 10.0.0.14
It is web2





3、配置haproxy和keepalive

3.1、安装haproxy

1
2
# yum install -y haproxy
# yum install -y haproxy






1
2
3
4
5
6
7
8
9
10
##相关配置:
global:全局配置段
    进程及安全配置相关的参数
    性能调整相关的参数
    Debug相关的参数
proxies:代理配置段
    defaults:为frontend, backend以及listen提供默认配置;
    frontend:前端,相当于Nginx中的server{ ... };
    backend:后端,相当于nginx中的upstream { ...};
    listen:前后端的直接组合;





3.2、配置haproxy的日志文件
##定义日志系统相关属性

log <address> <facility> ]:
<address>:日志服务器地址;
:每行日志记录的最大长度;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
##添加日志(haproxy.cfg):
# vim haproxy.cfg
log         127.0.0.1 local2

##修改syslog.conf:
# vim /etc/rsyslog.conf
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514

local2.*         /var/log/haproxy.log


##重启两个服务即可看到日志文件:
# systemctl restart rsyslog
# systemctl restart haproxy
# cd /var/log/
# ls haproxy.log
haproxy.log

##把日志文件配置同步到主机haproxy-2上
# scp /etc/haproxy/haproxy.cfg 10.0.0.12:/etc/haproxy/haproxy.cfg
# scp /etc/rsyslog.conf 10.0.0.12:/etc/rsyslog.conf
# systemctl restart rsyslog
# systemctl restart haproxy
# cd /var/log/
# ls haproxy.log
haproxy.log





3.3、配置haproxy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
##修改配置文件
# vim /etc/haproxy/haproxy.cfg
frontendmain *:80
    acl url_static       path_beg       -i /static /images /javascript /stylesheets
    acl url_static       path_end       -i .jpg .gif .png .css .js
    use_backend static          if url_static
    default_backend             app
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
    balance   roundrobin
    server      static 127.0.0.1:4331 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
    balance   roundrobin
    server   web-110.0.0.13:80 check
    server   web-210.0.0.14:80 check



##把配置文件同步到haproxy-2上去
# scp /etc/rsyslog.conf 10.0.0.12:/etc/rsyslog.conf

##重启服务
# systemctl restart haproxy
# systemctl enable haproxy
# systemctl restart haproxy
# systemctl enable haproxy

##测试,看看能不能访问web
# curl 10.0.0.11
It is web1
# curl 10.0.0.11
It is web2
# curl 10.0.0.11
It is web1
# curl 10.0.0.11
It is web2
##现在haproxy就已经配置好了





3.4、配置keepalive
安装keepalive


1
2
# yum install -y keepalived
# yum install -y keepalived





配置keepalive
##主机haproxy-1的keepalive配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

vrrp_script check_haproxy {
      script "/etc/keepalived/check_haproxy.sh"
      interval 2
      weight 2
}
global_defs {
   notification_email {
   acassen@firewall.loc
   }
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 50
    nopreempt
    priority 150
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 123456
    }
    virtual_ipaddress {
      10.0.0.100
    }
    track_script {
      check_haproxy
   }
}
vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    nopreempt
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 123456
    }
    virtual_ipaddress {
      10.0.0.200
    }
    track_script {
      check_haproxy
   }
}




##主机haproxy-2的keepalive配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

vrrp_script check_haproxy {
      script "/etc/keepalived/check_haproxy.sh"
      interval 2
      weight 2
}
global_defs {
   notification_email {
   acassen@firewall.loc
   }
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 50
    nopreempt
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 123456
    }
    virtual_ipaddress {
      10.0.0.100
    }
    track_script {
      check_haproxy
   }
}
vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 51
    nopreempt
    priority 150
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 123456
    }
    virtual_ipaddress {
      10.0.0.200
    }
    track_script {
      check_haproxy
   }
}




##haproxy检测脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# cat /etc/keepalived/check_haproxy.sh
#!/bin/bash
h=`ps -C haproxy --no-header |wc -l`
if [ $h -eq 0 ];then
systemctl stop keepalived
fi
# chmod a+x /etc/keepalived/check_haproxy.sh
# cat /etc/keepalived/check_haproxy.sh
#!/bin/bash
h=`ps -C haproxy --no-header |wc -l`
if [ $h -eq 0 ];then
systemctl stop keepalived
fi
# chmod a+x /etc/keepalived/check_haproxy.sh





启动keepalive

##主机haproxy-1(由于优先级的问题,可以看到vip1在haproxy-1上)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# systemctl restart keepalived
# systemctl enable keepalived         
# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-10-28 12:30:32 CST; 1s ago
Process: 2445 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 2446 (keepalived)
   CGroup: /system.slice/keepalived.service
         ├─2446 /usr/sbin/keepalived -D
         ├─2447 /usr/sbin/keepalived -D
         └─2448 /usr/sbin/keepalived -D
Oct 28 12:30:33 haproxy-1 Keepalived_vrrp: VRRP_Instance(VI_1) Changing effective priority from 150 to 152
Oct 28 12:30:33 haproxy-1 Keepalived_vrrp: VRRP_Instance(VI_2) Changing effective priority from 100 to 102
Oct 28 12:30:34 haproxy-1 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Oct 28 12:30:34 haproxy-1 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Oct 28 12:30:34 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:30:34 haproxy-1 Keepalived_vrrp: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 10.0.0.100
Oct 28 12:30:34 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:30:34 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:30:34 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:30:34 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
# ip addr
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:1d:7a:63 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.11/24 brd 10.0.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 10.0.0.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::8ec5:50ac:d71:20d7/64 scope link
       valid_lft forever preferred_lft forever
    inet6 fe80::f87c:449f:eb4a:ba03/64 scope link tentative dadfailed
       valid_lft forever preferred_lft forever





##主机haproxy-2(由于优先级的问题,可以看到vip2在haproxy-2上)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# systemctl start keepalived
# systemctl enable keepalived
# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-10-28 12:30:09 CST; 5s ago
Process: 9158 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 9159 (keepalived)
   CGroup: /system.slice/keepalived.service
         ├─9159 /usr/sbin/keepalived -D
         ├─9160 /usr/sbin/keepalived -D
         └─9161 /usr/sbin/keepalived -D
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: VRRP_Instance(VI_1) Changing effective priority from 100 to 102
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: VRRP_Instance(VI_2) Changing effective priority from 150 to 152
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: VRRP_Instance(VI_2) Entering MASTER STATE
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: VRRP_Instance(VI_2) setting protocol VIPs.
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: VRRP_Instance(VI_2) Sending/queueing gratuitous ARPs on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.200
# ip addr
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:76:bf:48 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.12/24 brd 10.0.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 10.0.0.200/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::f87c:449f:eb4a:ba03/64 scope link
       valid_lft forever preferred_lft forever





访问web服务:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# curl 10.0.0.100
It is web1
# curl 10.0.0.100
It is web2
# curl 10.0.0.100
It is web1
# curl 10.0.0.100
It is web2
#
# curl 10.0.0.200
It is web1
# curl 10.0.0.200
It is web2
# curl 10.0.0.200
It is web1
# curl 10.0.0.200
It is web2





测试


在haproxy-1上把haproxy服务给关闭掉,看看vip1会不会飘到haproxy-2上,同时也看看网页还能不能正常访问:

##在haproxy-1上关闭haproxy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# systemctl stop haproxy
# systemctl status haproxy
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
Oct 28 11:30:32 haproxy-1 haproxy-systemd-wrapper: haproxy-systemd-wrapper: exit, haproxy RC=1
Oct 28 11:30:32 haproxy-1 systemd: Unit haproxy.service entered failed state.
Oct 28 11:30:32 haproxy-1 systemd: haproxy.service failed.
Oct 28 12:18:47 haproxy-1 systemd: Started HAProxy Load Balancer.
Oct 28 12:18:47 haproxy-1 systemd: Starting HAProxy Load Balancer...
Oct 28 12:18:47 haproxy-1 haproxy-systemd-wrapper: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
Oct 28 12:45:34 haproxy-1 systemd: Stopping HAProxy Load Balancer...
Oct 28 12:45:34 haproxy-1 haproxy-systemd-wrapper: haproxy-systemd-wrapper: SIGTERM -> 2371.
Oct 28 12:45:34 haproxy-1 systemd: Stopped HAProxy Load Balancer.
Oct 28 12:45:34 haproxy-1 haproxy-systemd-wrapper: haproxy-systemd-wrapper: exit, haproxy RC=0





##查看haproxy-1的keepalive服务是否已经停掉了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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)
Oct 28 12:30:39 haproxy-1 Keepalived_vrrp: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 10.0.0.100
Oct 28 12:30:39 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:30:39 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:30:39 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:30:39 haproxy-1 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:06 haproxy-1 Keepalived: Stopping
Oct 28 12:51:06 haproxy-1 systemd: Stopping LVS and VRRP High Availability Monitor...
Oct 28 12:51:06 haproxy-1 Keepalived_vrrp: VRRP_Instance(VI_1) sent 0 priority
Oct 28 12:51:06 haproxy-1 Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
Oct 28 12:51:07 haproxy-1 systemd: Stopped LVS and VRRP High Availability Monitor.
# ip addr
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:1d:7a:63 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.11/24 brd 10.0.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::8ec5:50ac:d71:20d7/64 scope link
       valid_lft forever preferred_lft forever
    inet6 fe80::f87c:449f:eb4a:ba03/64 scope link tentative dadfailed
       valid_lft forever preferred_lft forever





##查看haproxy-2的keepalive服务状态和ip,可以看到vip1已经成功飘到haproxy-2上了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-10-28 12:30:09 CST; 21min ago
Process: 9158 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 9159 (keepalived)
   CGroup: /system.slice/keepalived.service
         ├─9159 /usr/sbin/keepalived -D
         ├─9160 /usr/sbin/keepalived -D
         └─9161 /usr/sbin/keepalived -D
Oct 28 12:51:07 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:07 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:07 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:07 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp: Sending gratuitous ARP on ens33 for 10.0.0.100
# ip addr
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:76:bf:48 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.12/24 brd 10.0.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 10.0.0.200/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet 10.0.0.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::f87c:449f:eb4a:ba03/64 scope link
       valid_lft forever preferred_lft forever





##访问web网页(可以看到web页面还是可以正常访问的)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# curl 10.0.0.100
It is web1
# curl 10.0.0.100
It is web2
# curl 10.0.0.100
It is web1
# curl 10.0.0.100
It is web2
# curl 10.0.0.200
It is web1
# curl 10.0.0.200
It is web2
# curl 10.0.0.200
It is web1
# curl 10.0.0.200
It is web2





    这次的haproxy+keepalive做简单的高可用实验就已经到此结束了。如果有写错的地方,欢迎各位大神指出来,我会去改正的。如果有写的不好的地方,请多多见谅!!!
页: [1]
查看完整版本: Haproxy+keepalived做简单的高可用(主主模式)