Apache 负载均衡器设置和优雅重启
Apache Load Balancer settings & graceful restarts
我调查了 mod_proxy_balancer 的行为和正常重启。我发现,几乎所有关于负载平衡的设置都需要
A)重新启动而不是正常重新启动,或者
B) 给平衡器一个新的 id,然后优雅地重启
生效。
我举个例子。假设我们有一个这样配置的负载均衡器:
<VirtualHost 22.11.22.11:443>
ServerName Hostname
ProxyHCExpr isok {hc('body') =~ /==welcome ok1==/}
ProxyHCTemplate template1 hcinterval=1 hcexpr=isok hcmethod=get hcuri=/healthcheck.php
ProxyHCTemplate template2 hcinterval=1 hcexpr=isok hcmethod=head hcuri=/head_check.php
<Proxy balancer:mybalancer>
BalancerMember https://www.backend1.com:443 hctemplate=template1
BalancerMember https://www.backend1.com:443 hctemplate=template1
</Proxy>
<VirtualHost>
如果我们想把healthcheck模板改成"template2",这个配置是行不通的:
<VirtualHost 22.11.22.11:443>
ServerName Hostname
ProxyHCExpr isok {hc('body') =~ /==welcome ok1==/}
ProxyHCTemplate template1 hcinterval=1 hcexpr=isok hcmethod=get hcuri=/healthcheck.php
ProxyHCTemplate template2 hcinterval=1 hcexpr=isok hcmethod=head hcuri=/head_check.php
<Proxy balancer:mybalancer>
BalancerMember https://www.backend1.com:443 hctemplate=template2
BalancerMember https://www.backend1.com:443 hctemplate=template2
</Proxy>
<VirtualHost>
但是,如果我完全相同并重命名平衡器,它将在正常重启后工作:
<VirtualHost 22.11.22.11:443>
ServerName Hostname
ProxyHCExpr isok {hc('body') =~ /==welcome ok1==/}
ProxyHCTemplate template1 hcinterval=1 hcexpr=isok hcmethod=get hcuri=/healthcheck.php
ProxyHCTemplate template2 hcinterval=1 hcexpr=isok hcmethod=head hcuri=/head_check.php
<Proxy balancer:myNEWbalancer>
BalancerMember https://www.backend1.com:443 hctemplate=template2
BalancerMember https://www.backend1.com:443 hctemplate=template2
</Proxy>
<VirtualHost>
正如我所说,几乎所有与负载均衡器相关的设置都是相同的:
- hcinterval
- hctemplate
- hcuri
- hceexpr
- ProxySet stickysession=
- ProxySet lbmethod=
- ProxyHCTemplate
- ProxyHCExpr
- 切换健康检查on/off
使用 Apache v. 2.4.33 测试。
我们现在的策略是,将所有这些设置包含到一个散列中,然后使用散列作为 balancer-id。像这样,每当更改其中一个设置时,平衡器就会获得一个新的 ID,并且更改会起作用。
这是一个好的解决方案吗?有人为此找到了更好的workarround/solution,或者对为什么必须重命名平衡器有更多见解吗?重启对我们来说是没有选择的..
我发现了似乎与此相关的错误报告:
https://bz.apache.org/bugzilla/show_bug.cgi?id=58529
https://bz.apache.org/bugzilla/show_bug.cgi?id=49771
和:
https://bz.apache.org/bugzilla/show_bug.cgi?id=55152
上一个说是修复了,但是2.4.33还是出现这个问题
httpd更新到2.4.34版本(2018年7月16日星期一发布)后问题不再出现!上面提到的所有设置都可以更改,并在正常重启后成功应用。
我调查了 mod_proxy_balancer 的行为和正常重启。我发现,几乎所有关于负载平衡的设置都需要 A)重新启动而不是正常重新启动,或者 B) 给平衡器一个新的 id,然后优雅地重启 生效。
我举个例子。假设我们有一个这样配置的负载均衡器:
<VirtualHost 22.11.22.11:443>
ServerName Hostname
ProxyHCExpr isok {hc('body') =~ /==welcome ok1==/}
ProxyHCTemplate template1 hcinterval=1 hcexpr=isok hcmethod=get hcuri=/healthcheck.php
ProxyHCTemplate template2 hcinterval=1 hcexpr=isok hcmethod=head hcuri=/head_check.php
<Proxy balancer:mybalancer>
BalancerMember https://www.backend1.com:443 hctemplate=template1
BalancerMember https://www.backend1.com:443 hctemplate=template1
</Proxy>
<VirtualHost>
如果我们想把healthcheck模板改成"template2",这个配置是行不通的:
<VirtualHost 22.11.22.11:443>
ServerName Hostname
ProxyHCExpr isok {hc('body') =~ /==welcome ok1==/}
ProxyHCTemplate template1 hcinterval=1 hcexpr=isok hcmethod=get hcuri=/healthcheck.php
ProxyHCTemplate template2 hcinterval=1 hcexpr=isok hcmethod=head hcuri=/head_check.php
<Proxy balancer:mybalancer>
BalancerMember https://www.backend1.com:443 hctemplate=template2
BalancerMember https://www.backend1.com:443 hctemplate=template2
</Proxy>
<VirtualHost>
但是,如果我完全相同并重命名平衡器,它将在正常重启后工作:
<VirtualHost 22.11.22.11:443>
ServerName Hostname
ProxyHCExpr isok {hc('body') =~ /==welcome ok1==/}
ProxyHCTemplate template1 hcinterval=1 hcexpr=isok hcmethod=get hcuri=/healthcheck.php
ProxyHCTemplate template2 hcinterval=1 hcexpr=isok hcmethod=head hcuri=/head_check.php
<Proxy balancer:myNEWbalancer>
BalancerMember https://www.backend1.com:443 hctemplate=template2
BalancerMember https://www.backend1.com:443 hctemplate=template2
</Proxy>
<VirtualHost>
正如我所说,几乎所有与负载均衡器相关的设置都是相同的:
- hcinterval
- hctemplate
- hcuri
- hceexpr
- ProxySet stickysession=
- ProxySet lbmethod=
- ProxyHCTemplate
- ProxyHCExpr
- 切换健康检查on/off
使用 Apache v. 2.4.33 测试。
我们现在的策略是,将所有这些设置包含到一个散列中,然后使用散列作为 balancer-id。像这样,每当更改其中一个设置时,平衡器就会获得一个新的 ID,并且更改会起作用。 这是一个好的解决方案吗?有人为此找到了更好的workarround/solution,或者对为什么必须重命名平衡器有更多见解吗?重启对我们来说是没有选择的..
我发现了似乎与此相关的错误报告:
https://bz.apache.org/bugzilla/show_bug.cgi?id=58529
https://bz.apache.org/bugzilla/show_bug.cgi?id=49771
和:
https://bz.apache.org/bugzilla/show_bug.cgi?id=55152
上一个说是修复了,但是2.4.33还是出现这个问题
httpd更新到2.4.34版本(2018年7月16日星期一发布)后问题不再出现!上面提到的所有设置都可以更改,并在正常重启后成功应用。