在 Docker 容器中对 Apache 和 2 个 Tomcats 进行负载均衡时,无法正确设置我的端口

Unable to get my ports set up correctly when load balancing between Apache and 2 Tomcats all in Docker Containers

提问人:Liveo13 提问时间:7/18/2023 更新时间:7/18/2023 访问量:21

问:

我正在尝试设置一个测试来了解负载平衡,但我无法让所有设置正常工作。几天来,我尝试了许多设置变化,但我无法让它正常工作。

我有 1 个运行 apache 服务器的 docker 容器和 2 个运行 tomcat 的 docker 容器来提供网页。apache 将用作两个 tomcat 之间的负载均衡器。为什么我无法通过以下设置在 webapps/blah/index.html 的 tomcats 上访问我的负载平衡网站?

我能够在容器之间ping。

码头工人

检查 docker 端口配置和 ip 地址:

# docker ps
CONTAINER ID   IMAGE                      COMMAND              CREATED      STATUS          PORTS                                                 NAMES
069d7a807cec   tomcat:9.0-jdk11-openjdk   "catalina.sh run"    5 days ago   Up 29 minutes   8080/tcp, 0.0.0.0:8084->8084/tcp, :::8084->8084/tcp   tomcat4
4f260c3e0638   tomcat:9.0-jdk11-openjdk   "catalina.sh run"    5 days ago   Up 58 seconds   8080/tcp, 0.0.0.0:8083->8083/tcp, :::8083->8083/tcp   tomcat3
d4abb29c37de   httpd                      "httpd-foreground"   5 days ago   Up 46 hours     0.0.0.0:8082->80/tcp, :::8082->80/tcp       
# docker inspect bridge

        "ConfigOnly": false,
        "Containers": {
            "069d7a807cec20cfae90e7c5f913440d691ad576c555b53d79cb2c59505e6bb3": {
                "Name": "tomcat4",
                "EndpointID": "f7bf5a42f1ad9caa4b3f6a2333b567178aba79bfa8804d0fb3af6c82a9d59b9e",
                "MacAddress": "02:42:ac:11:00:04",
                "IPv4Address": "172.17.0.4/16",
                "IPv6Address": ""
            },
            "4f260c3e063809f124bd8a6fe2f22ab474b340282b83692d65bb0b4cfb56adce": {
                "Name": "tomcat3",
                "EndpointID": "21ee68b206fcfd9577a92d575e100544ef5400c481389b597db307509ecdbc63",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            },
            "d4abb29c37dedef040aafdb6aeb5e9f91cdef8a8c6c5a41537a2d831c3345636": {
                "Name": "httpd2",
                "EndpointID": "5783e5a537fc2617b9bd0122e4653554d86b1b18cb7c040c8aebf00221945b3c",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },

Apache 服务器在 httpd.conf 中设置了以下内容(在其他服务器中):

ServerRoot "/usr/local/apache2"

Listen 80

ServerName: 172.17.0.2

mod_proxy_http、mod_proxy_balancer 和 mod_proxy 都已加载并包含在内。

Apache 服务器具有以下负载平衡设置:

<VirtualHost *:80>
        CustomLog logs/access.log combined
        ProxyRequests off
        <Proxy balancer://lbcluster>
                BalancerMember http://172.17.0.3:8083 route=tomcat3
                BalancerMember http://172.17.0.4:8084 route=tomcat4
                ProxySet lbmethod=byrequests
        </Proxy>
        ProxyPass / balancer://lbcluster/
        ProxyPassReverse / balancer://lbcluster/
</VirtualHost>

Tomcat 配置

我的 tomcat3 和 tomcat4 有一个文件夹 webapps/blah,其中包含一个文件索引.html其中包含基本的 html。

TomCat3 在 Server.xml 中具有以下内容:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" 
               maxConnection="200" />

    <Engine name="Catalina" defaultHost="172.17.0.3" jvmRoute="tomcat3">

如果我尝试使用以下命令访问废话:

lynx http://172.17.0.2:8082/blah

我得到一个 503。

我在访问.log中得到以下内容:

172.17.0.1 - - [18/Jul/2023:10:16:51 +0000] "GET /blah HTTP/1.0" 503 299 "-" "Lynx/2.9.0dev.12 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/3.7.7"

直接进入 tomcat3 给了我:

lynx http://172.17.0.3:8083/blah

Alert!: Unexpected network read error; connection aborted.
Can't Access `http://localhost:8083/blah'
Alert!: Unable to access document.

如果我进入 tomcat3 并在容器内运行以下命令,

http://localhost:8080/blah

我明白了

Unable to connect to the remote host
Docker Apache Tomcat 负载均衡

评论


答: 暂无答案