简体   繁体   English

使用proxy_balancer的Apache负载平衡

[英]Apache load balancing with proxy_balancer

I am having difficulties configuring apache 2.4 to use it's proxy_balancer mod. 我在配置apache 2.4以使用它的proxy_balancer mod时遇到困难。 My use case is fairly straight forward. 我的用例相当简单。 Requests are reaching the apache node which should be load balanced to the cluster. 请求到达apache节点,该节点应负载均衡到集群。 This is my config : 这是我的config

<VirtualHost *:80>

    ProxyRequests off

    ServerName localhost

    <Proxy balancer://geocode>

            BalancerMember "http://192.168.2.11:8080/ors/status"
            BalancerMember "http://192.168.2.35:8080/ors/status"

            Require all granted

            ProxySet lbmethod=byrequests

    </Proxy>

    <Location /balancer-manager>

            SetHandler balancer-manager

            Require all granted

    </Location>

    ProxyPass /balancer-manager !
    ProxyPass "/geocodelb" "balancer://geocode"
    ProxyPass "/geocode" "http://192.168.2.35:8080/ors/status"

</VirtualHost>

When navigating to localhost:80/geocodelb I receive 404 Not Found : 导航到localhost:80/geocodelb我收到404 Not Found

129.206.205.50 - - [01/Oct/2017:19:39:55 +0000] "GET /geocodelb 
HTTP/1.1" 404 164 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; 
rv:56.0) Gecko/20100101 Firefox/56.0"

but localhost:80/geocode works: 但是localhost:80/geocode可以工作:

129.206.205.50 - - [01/Oct/2017:19:40:07 +0000] "GET /geocode HTTP/1.1" 
200 757 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) 
Gecko/20100101 Firefox/56.0"

(The ../status points to a tomcat instance and returns a json object) ../status指向一个tomcat实例并返回一个json对象)

If I replace the url's of the BalancerMembers with something arbitrary - like google.com - it works. 如果我用任意的内容替换BalancerMembers的网址-例如google.com则可以。

I can also reach the balancer-manager at localhost:80/balancer-manager and obtain the correct information. 我还可以通过localhost:80/balancer-manager到达localhost:80/balancer-manager并获取正确的信息。 If I am not mistaken it is telling me that everything looks ok (see screenshot). 如果我没记错的话,那就是告诉我一切看起来都不错(请参见屏幕截图)。 What am I missing here? 我在这里想念什么?

在此处输入图片说明

The reason for this not working is that the balancermember must be a url to a server, without a path. 之所以不起作用,是因为balancermember必须是服务器的url,没有路径。 The path is to be added in the ProxyPass directive, like this balancer://orsbackend/ors/geocode . 路径将添加到ProxyPass指令中,例如balancer://orsbackend/ors/geocode Here the working config: 这是工作配置:

<VirtualHost *:80>

        ProxyRequests off

        ServerName localhost

        <Proxy balancer://orsbackend>
                BalancerMember "http://192.168.2.11:8080"
                BalancerMember "http://192.168.2.35:8080"
                ProxySet lbmethod=byrequests
        </Proxy>

        <Location /balancer-manager>
                SetHandler balancer-manager

                Require all granted
        </Location>

        ProxyPass /balancer-manager !

        ProxyPass "/geocode" "balancer://orsbackend/ors/geocode"

</VirtualHost>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM