我正在尝试研究针对以下场景对长时间运行的 TCP 连接进行负载平衡的最佳方法:
我们在一组冗余防火墙后面有多个服务器,客户端与我们的后端服务器建立长期运行(通常 10-15 小时)的 TCP 连接。
现在,“负载平衡”是通过客户端循环方法处理的,以通过 IP 地址列表,这些 IP 地址都位于我们的防火墙中,并相应地 NAT 到后端服务器。
我想摆脱这种方法,只有一个公共 IP,并有一个单独的负载平衡器,可以检查服务器的运行状况/负载并相应地分发传入的客户端连接请求。
这里的一个问题是,每个客户端在 3 个不同的端口上建立 3 个套接字连接,如果这些连接是“粘性的”,我更喜欢,因此所有这 3 个连接请求都发送到同一个后端服务器。
我一直在研究例如 HAProxy,但我不确定它是否真的适合我的场景。我们的连接数相对较少(约 300 个客户端 * 每个客户端 3 个套接字连接)。通常我们看到每个套接字约 15KB/s 的连续数据传输量。
非常感谢您对此的任何意见!
谢谢,
汤姆
我的 HAProxy 有问题,下面是我的haproxy.cfg的片段,
acl url_a path_beg /a
acl dom_eye hdr_dom(host) -i www.mydomin.com
use_backend eye1 if dom_eye
use_backend eye2 if dom_eye url_a
Run Code Online (Sandbox Code Playgroud)
但我希望所有的 url 都以/a开头,使用 eye2。
而且,我发现当像下面这样切换use_backend的顺序时,
acl url_a path_beg /a
acl dom_eye hdr_dom(host) -i www.mydomin.com
use_backend eye2 if dom_eye url_a
use_backend eye1 if dom_eye
Run Code Online (Sandbox Code Playgroud)
它对我有用。
但是我不明白Haproxy的“匹配顺序规则”,也找不到谷歌的任何解释。
对此有何想法?
我已经通过 xinetd 使用 HAProxy设置了负载平衡 MySQL 从站。2 个负载均衡器共享一个由 Pacemaker 管理的虚拟 IP:
crm configure show:
node SVR120-27148.localdomain
node SVR255-53192.localdomain
primitive failover-ip ocf:heartbeat:IPaddr2 \
params ip="192.168.5.9" cidr_netmask="32" \
op monitor interval="5s" \
meta is-managed="true"
primitive haproxy ocf:heartbeat:haproxy \
params conffile="/etc/haproxy/haproxy.cfg" \
op monitor interval="30s" \
meta is-managed="true"
colocation haproxy-with-failover-ip inf: haproxy failover-ip
order haproxy-after-failover-ip inf: failover-ip haproxy
property $id="cib-bootstrap-options" \
dc-version="1.0.12-unknown" \
cluster-infrastructure="openais" \
no-quorum-policy="ignore" \
expected-quorum-votes="2" \
stonith-enabled="false" \
last-lrm-refresh="1342783084"
Run Code Online (Sandbox Code Playgroud)
/etc/haproxy/haproxy.cfg:
global
log 127.0.0.1 local1 debug …Run Code Online (Sandbox Code Playgroud) 抱歉,如果之前有人问过这个问题,但我似乎找不到太多关于它的信息。
我们将使用 HAProxy 来平衡我们的 MariaDB Galera 集群。我在这方面看到的所有文章/教程都使用 Keepalived(或类似的东西)进行主动/被动 HAProxy 设置。
有什么好的理由为什么你不应该有一个主动/主动设置?
每个 HAProxy 节点都可以有一个固定的 IP,并且都有一个浮动的 IP。在正常情况下,请求在两个 HAProxy 节点之间共享,如果一个节点宕机,另一个将使用它的浮动 IP 并处理两个 IP 下的请求。当另一个恢复时,它会再次获取其浮动 IP 和负载份额。
我很感激你对此的意见。
卢克
我想将大约 100 多个站点从一台服务器迁移到另一台服务器。当前计划是逐渐为每个添加一个 acl,因为它们被移动以将流量引导到新服务器。
这是一个简化的例子
front http_frontend
bind *:80
acl is_new hdr_end(host) -i sub1.domain.com
acl is_new hdr_end(host) -i sub2.domain.com
acl is_new hdr_end(host) -i www.domain2.com
mode http
# etc
use_backend web1 if is_new
default_backend legacy1
Run Code Online (Sandbox Code Playgroud)
一旦他们都被感动了,我们就会改变 default_backend
有没有办法从另一个文件中读取这些 acl?或者从文件中读取域 - 也许像这样?
acl is_new hdr_end(host) -i /path/to/file
Run Code Online (Sandbox Code Playgroud)
例如,我将所有安全证书包括在下面,这样的东西会很棒!
bind *:443 ssl crt /etc/haproxy/certs.d
Run Code Online (Sandbox Code Playgroud)
如果没有,这不是世界末日,它只是美好而整洁:)。
我使用以下行设置了 HAProxy 服务器:
bind *:443 ssl crt /etc/ssl/domain.com/domain.com.pem
我有以下文件:
/etc/ssl/domain.com/domain.com.key
/etc/ssl/domain.com/domain.com.csr
我从 Geotrust 购买了一个证书,它给了我一个Primary Intermediate Certificate,Secondary Intermediate Certificate和End Entity Certificate
我已经按照 PIC、SID、EEC、KEY 顺序连接了文件,/etc/ssl/domain.com/domain.com.pem其中传递openssl verify /etc/ssl/domain.com/domain.com.pem和openssl verify -CAfile /etc/ssl/domain.com/domain.com.pem /etc/ssl/domain.com/domain.com.pem
我还使用http://www.sslshopper.com/certificate-decoder.html验证了这个文件
当我跑步时,haproxy -f /etc/haproxy/haproxy.cfg -c我得到
'bind *:443 : inconsistencies between private key and certificate loaded from PEM file '/etc/ssl/domain.com/domain.com.pem'
Proxy 'http-in': no SSL certificate specified for bind '*:443' at [/etc/haproxy/haproxy.cfg] (use 'crt')
我是 SSL 证书的新手,我被困在哪里。谷歌搜索的答案让我跑了一英里,我没有进一步前进。
我在以这种方式创建 .pem …
我的 haproxy.cfg 文件有一个使用主机名的后端服务器:
backend servers
server myapp ${PORTAL_PORT_3000_TCP_ADDR}:${PORTAL_PORT_3000_TCP_PORT} maxconn 32
Run Code Online (Sandbox Code Playgroud)
myapp 正在链接到 haproxy docker 容器的其他 docker 容器中运行。提到的环境变量在 haproxy 容器中有值,但是当容器启动时会引发此错误
[ALERT] 244/134924 (8) : parsing [/etc/haproxy.cfg:16] : Unknown host in '${PORTAL_PORT_3000_TCP_ADDR}:${PORTAL_PORT_3000_TCP_PORT}'
[ALERT] 244/134924 (8) : Error(s) found in configuration file : /etc/haproxy.cfg
[ALERT] 244/134934 (8) : Fatal errors found in configuration.
Run Code Online (Sandbox Code Playgroud) 我有一个 HAProxy 路由 HTTPS,无需使用 SNI 终止。
配置类似于以下内容:
frontend ft_ssl_vip
bind 0.0.0.0:5000
mode tcp
option tcplog
tcp-request inspect-delay 5s
tcp-request content accept if { req.ssl_hello_type 1 }
default_backend bk_ssl_default
# Using SNI to take routing decision
backend bk_ssl_default
mode tcp
acl application_1 req.ssl_sni -i foo.example.com
acl application_2 req.ssl_sni -i bar.example.com
use-server server1 if application_1
use-server server2 if application_2
use-server server3 if !application_1 !application_2
option ssl-hello-chk
server server1 127.0.0.1:777
server server2 127.0.0.1:778
server server3 127.0.0.1:779
Run Code Online (Sandbox Code Playgroud)
我还需要通过同一端口 (5000) 路由 HTTP 流量。
如何修改我的配置以通过 SNI …
我收到错误:
[ALERT] 342/125339 (1) : sendmsg logger #1 failed: No such file or directory (errno=2)
Run Code Online (Sandbox Code Playgroud)
/srv/dockervolume/haproxy/etc/rsyslog.d/49-haproxy.conf 文件:
$AddUnixListenSocket /var/lib/haproxy/dev/log
local0.* -/var/log/haproxy/haproxy_0.log
local1.* -/var/log/haproxy/haproxy_1.log
if ($programname == 'haproxy') then -/var/log/haproxy/haproxy.log
& ~
Run Code Online (Sandbox Code Playgroud)
/srv/dockervolume/haproxy/etc/haproxy/haproxy.cfg 文件:
global
log /var/lib/haproxy/dev/log local0 debug
chroot /var/lib/haproxy
maxconn 2048
tune.ssl.default-dh-param 2048
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
timeout connect 5000
timeout client 10000
timeout server 10000
backend my_backend …Run Code Online (Sandbox Code Playgroud) 用法:Haproxy 作为 SSL 终止
要求:我们的私钥受密码保护,并且我们不允许删除私钥的密码
问题:如果我运行以下命令,haproxy -f /pathtoconf则会显示密码提示,一旦提供密码,haproxy 就会启动
为了解决这个问题,我使用了 Expect 脚本,它会自动提供密码
自动填充密码的脚本
#!/usr/bin/expect -f
set timeout 20
spawn nohup haproxy -f /opt/reverse-proxies/demo.cfg
expect "Enter PEM pass phrase:"
send "password\r"
expect_background
expect eof
exit
Run Code Online (Sandbox Code Playgroud)
我计划使用 ansible-playbook 来自动化它,但我的问题是有什么干净的方法来提供私钥的密码,我对此进行了一些搜索,但找不到任何相同的配置。haproxy 团队发表了一些声明,计划提供一种干净的方法,但无法在 1.6 中实现,并计划在 1.7 中实现。我查看了 1.7 的发行说明,但找不到太多关于该主题的信息。haproxy 是否为私钥密码提供了任何配置,或者如果有人已经实现了一个很好的解决方案来克服这个问题,请您指导我朝这个方向前进。
我的示例配置
global
log 127.0.0.1 local2 debug
defaults
timeout connect 5000
timeout client 50000
timeout server 50000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
log global
bind *:4000 ssl …Run Code Online (Sandbox Code Playgroud) haproxy ×10
connection ×1
keepalived ×1
mysql ×1
openssl ×1
password ×1
private-key ×1
rewrite ×1
ssl ×1
tcp ×1