高可用性代理服务器/ Keepalived无法转发流量

时间:2019-02-28 14:09:00

标签: load-balancing redhat haproxy

我对HAProxy真的很陌生,并且Keepalived在本周的学习过程非常艰难,但是我认为我几乎快要实现目标了,我的怀疑是我错过了实现目标所需的非常简单的步骤。有人可以给我任何帮助,我将不胜感激。 我遇到的问题是,使用VIP时,负载均衡器似乎没有将流量转发到后端。我可以ping VIP,这样我就知道了。 我能够执行一次curl http://192.168.5.42命令并从MASTER节点本身获得所需的响应。但是,然后我尝试解决该问题,并使用以下设置将HAProxy.xml文件添加到了/ etc / firewalld / services文件夹中,现在我无法执行该命令:

在我的实验室中,我有以下设置

2台装有HAProxy和Keepalived的RHEL 7.6服务器

2 x Windows 2016 IIS服务器,带有默认IIS页面,绑定在80上

RHEL-A Keepalived设置:

! keepalived的配置文件

global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.5.42 dev ens33 label ens33:100
}
}
virtual_server 192.168.5.42 80 {
delay_loop 10
protocol TCP
lb_algo rr

Use direct routing
lb_kind DR
persistence_timeout 7200

real_server 192.168.5.50 80 {
    weight 1
    TCP_CHECK {
      connect_timeout 5
      connect_port 80
    }
}

real_server 192.168.5.51 80 {
    weight 1
    TCP_CHECK {
      connect_timeout 5
      connect_port 80
    }
}
}

RHEL-A HAProxy设置

#---------------------------------------------------------------------

Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the ‘-r’ option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot      /var/lib/haproxy
pidfile     /var/run/haproxy.pid
maxconn     4000
user        haproxy
group       haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------

common defaults that all the ‘listen’ and ‘backend’ sections will
use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000

#---------------------------------------------------------------------

main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
bind    192.168.5.42:80
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 app1 192.168.5.50
server app2 192.168.5.51

RHEL-B Keepalived设置

! Configuration File for keepalived

global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.5.42 dev ens33 label ens33:100
}
}
virtual_server 192.168.5.42 80 {
delay_loop 10
protocol TCP
lb_algo rr

Use direct routing
lb_kind DR
persistence_timeout 7200

real_server 192.168.5.50 80 {
    weight 1
    TCP_CHECK {
      connect_timeout 5
      connect_port 80
    }
}

real_server 192.168.5.51 80 {
    weight 1
    TCP_CHECK {
      connect_timeout 5
      connect_port 80
    }
}
}

RHEL-B HAProxy设置

#---------------------------------------------------------------------

Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the ‘-r’ option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot      /var/lib/haproxy
pidfile     /var/run/haproxy.pid
maxconn     4000
user        haproxy
group       haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------

common defaults that all the ‘listen’ and ‘backend’ sections will
use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000

#---------------------------------------------------------------------

main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
bind    192.168.5.42:80
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 app1 192.168.5.50
server app2 192.168.5.51

0 个答案:

没有答案