簡體   English   中英

如何為許多 Spring-Boot 編寫配置 Apache 負載均衡器?

[英]How to write configuration Apache load balancer for many Spring-Boot?

我們想使用 Apache 負載平衡將負載分散到多個服務器上。 我們計划在 Apache LB 上做許多 http://load_balancer:port/app_name 重定向,例如:

http://load_balancer:port/app1 ---> Apache LB ---> http://server1:port1, http://server2:port1

http://load_balancer:port/app2 ---> Apache LB ---> http://server1:port2, http://server2:port2....

For Apache LB configuration file as below, when we use http://load_balancer:port in web browser then Apache LB works as expected.

如何重寫配置以便在web瀏覽器中輸入http://load_balancer:port/app?

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy "balancer://mycluster">
    BalancerMember "http://server1:port" route=1 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
    BalancerMember "http://server2:port" route=2 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
    ProxySet stickysession=ROUTEID
</Proxy>

<Proxy "balancer://myws">
    BalancerMember "ws://http://server1:port" route=1 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
    BalancerMember "ws://http://server2:port" route=2 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
    ProxySet stickysession=ROUTEID
</Proxy>

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) balancer://myws/$1 [P,L]

RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) balancer://mycluster/$1 [P,L]

第二種配置

我們使用如下提示作為代理標志。 Apache LoadBalancer 適用於“http://load_balancer:port/”。 我的配置文件:

ProxyPass "/" "balancer://mycluster/" stickysession=JSESSIONID|jsessionid scolonpathdelim=On 
<Proxy "balancer://mycluster">
    BalancerMember "http://server1:8727" route=1
    BalancerMember "http://server2:8193" route=2
</Proxy>

當我們將配置更改為 ProxyPass "/test" 以從 web 瀏覽器中引用 "http://load_balancer:port/test" 時,access.log 文件中出現錯誤(404):

  • 獲取/測試/ HTTP/1.1 200 2375
  • GET /static/css/app.77ac3251.css HTTP/1.1 404 196
  • ...

您可以使用 apache 代理通行證,而不是使用代理標志的重寫器。 您可以在官方文檔中找到有關配置的所有詳細信息: https://httpd.apache.org/docs/2.4/mod/mod_proxy_balancer.ZFC35FDC70D5FC69D269883A82EZA7

我們編寫了如下配置,它按預期工作:

<Proxy balancer://test.cl>
  Header add Set-Cookie "test.ROUTEID=ROUTE.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
  BalancerMember  http://server1:8727 route=test_00 keepalive=On connectiontimeout=5 retry=180
  BalancerMember  http://server2:9393 route=test_10 keepalive=On connectiontimeout=5 retry=180
  ProxySet lbmethod=bybusyness stickysession=ROUTEID
</Proxy>
<Location /test>
 ProxyPreserveHost On
  ProxyPass         balancer://test.cl
  ProxyPassReverse  balancer://test.cl
</Location>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM