【问题标题】:Possible to load balance across nodejs servers using apache可以使用 apache 跨 nodejs 服务器进行负载平衡
【发布时间】:2015-10-26 07:43:33
【问题描述】:

是否可以使用 apache 在一组 nodejs 服务器之间进行负载平衡?我还需要使用证书配置 apache 以提供 ssl 并仅提供 https 请求。

简单的设置是 2 台 apache 服务器作为我的负载平衡器。所有请求都将通过 https 进入这两个负载均衡器之一。

负载平衡器需要从那里确定将请求路由到哪个服务器。这将是运行相同节点进程的 6 台服务器之一。

我知道有 mod_cluster,但我只在 JBoss 设置中使用过它,并不确定这是否适用于 nodejs 服务器。

我也意识到这可能不是最好的设置,因为节点是单线程的,我可以尝试类似节点集群的东西。然而,节点集群似乎是垂直扩展而不是水平扩展。

我也知道有 nginx 和 haproxy,虽然我从来没有使用过它们中的任何一个并且对 apache 有更多的经验。也不确定 haproxy 和 nginx 是否支持只允许带有证书的 ssl 连接。

这种类型的负载平衡是否可以通过 apache 实现?如果可以,如何实现?

【问题讨论】:

    标签: node.js apache ssl https load-balancing


    【解决方案1】:

    如果您使用 mod_proxy 模块,则 apache 的使用与后面使用的服务器无关。因此,您还可以查看所有使用 mod_proxy 的 apache->tomcat 示例。

    在询问如何做之后,我添加了以下示例:

    <VirtualHost *:80>
            ProxyRequests off
    
            ServerName domain.com
    
            <Proxy balancer://mycluster>
                    # WebHead1
                    BalancerMember http://10.176.42.144:80
                    # WebHead2
                    BalancerMember http://10.176.42.148:80
    
                    # Security "technically we aren't blocking
                    # anyone but this the place to make those
                    # chages
                    Order Deny,Allow
                    Deny from none
                    Allow from all
    
                    # Load Balancer Settings
                    # We will be configuring a simple Round
                    # Robin style load balancer.  This means
                    # that all webheads take an equal share of
                    # of the load.
                    ProxySet lbmethod=byrequests
    
            </Proxy>
    
            # balancer-manager
            # This tool is built into the mod_proxy_balancer
            # module and will allow you to do some simple
            # modifications to the balanced group via a gui
            # web interface.
            <Location /balancer-manager>
                    SetHandler balancer-manager
    
                    # I recommend locking this one down to your
                    # your office
                    Order deny,allow
                    Allow from all
            </Location>
    
            # Point of Balance
            # This setting will allow to explicitly name the
            # the location in the site that we want to be
            # balanced, in this example we will balance "/"
            # or everything in the site.
            ProxyPass /balancer-manager !
            ProxyPass / balancer://mycluster/
    
    </VirtualHost>
    

    【讨论】:

    • mod_proxy 可以负载均衡吗?这和@madness 推荐的 mod_proxy_balancer 一样吗?
    • 是的 mod_proxy 可以。我添加了一个示例。
    • 这太有用了,太强大了……祝福你
    【解决方案2】:

    是的,如果您询问如何设置 Apache 负载均衡器,Check this out

    你见过node-http-proxy吗? Great little walkthrough here 如果您想保留所有节点,请不要太吓人。

    【讨论】:

    • 啊,不知道 mod_proxy_balancer。我会试一试。我偶然发现了 node-http-proxy,但我还需要设置 ssl(因此是 apache)。 node-http-proxy 可以做 ssl,还是我只是把 apache 扔到 node-http-proxy 前面?感谢您的帮助。
    • 使用证书遍历封面。
    猜你喜欢
    • 2013-03-24
    • 2018-03-12
    • 2012-06-04
    • 2016-08-23
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    相关资源
    最近更新 更多