我有一些Web服务器是MySQL后端。 HAProxy位于这些Web服务器的前面。所有Web服务器都使用https。
我尝试在http和https上使用http检查选项以确保数据库连接是否丢失,HAProxy将故障转移到另一个节点。我的haproxy配置文件:
global
log /dev/log local0
maxconn 4096
#debug
#quiet
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen http
bind *:80
mode http
balance roundrobin
stats enable
stats auth haproxy:haproxy
cookie JSESSIONID prefix
stick on src table https
option http-server-close
option forwardfor
default-server inter 5s fall 2
option httpchk
http-check expect ! string Database\ error
server sitea 192.168.0.20 cookie sitea check port 80
server siteb 192.168.0.21 cookie siteb check port 80
listen https
bind *:443
mode tcp
balance roundrobin
stick-table type ip size 5000k expire 2h store conn_cur
stick on src
option tcplog
option ssl-hello-chk
default-server inter 5s fall 2
option httpchk
http-check expect ! string Database\ error
server sitea 192.168.0.20:443 check ssl verify none
server siteb 192.168.0.21:443 check ssl verify none
看看最后两行。如果我指定“ssl verify none”,我的HAProxy可以成功检查Apache和MySQL的状态。但是,我无法通过https打开网页(它提示我这个网站无法提供安全连接.ERR_SSL_PROTOCOL_ERROR)。
如果删除该参数,可以再次打开网页,但HAProxy中的所有https服务器状态都变为DOWN。
P.S。我目前正在使用自签名证书,因为我还在测试。
答案 0 :(得分:0)
我找到了解决方案:因为我在apache节点上使用https,所以我必须将ssl证书内容复制到haproxy。为此,将私钥和CA颁发的证书内容复制并合并到一个文件中(在我的例子中,我将其放入/etc/haproxy/haproxy.pem)。
修改haproxy配置,更改
bind *:443
要
bind *:443 ssl crt /etc/haproxy/haproxy.pem