Ubuntu EC2 服务器未连接到 Tomcat7 和 GeoServer 的公共(public) IP 端口 8080

标签 ubuntu amazon-ec2 timeout tomcat7

我们有一台运行 Flask 应用程序的服务器,它使用 Tomcat7 下的 GeoServer 在内部为应用程序本身提供 map 数据,并通过 WMS 在外部为经过身份验证的用户提供 map 数据。

这一切都工作正常,直到在一些次要代码编辑/重新加载、命令行更新/升级和重新启动(包括从 EC2 控制台重新启动)之后停止工作。

经过一些挖掘和调试,似乎系统的所有元素都单独工作正常,但是通过端口 8080 对 Tomcat7 和 GeoServer 的关键请求没有连接和超时(通常在大约 2 分钟后)。

我查看了很多类似问题的在线帮助,并检查、实现和测试了一些建议,但似乎没有什么可以清除障碍。

我不是专家(尽管我在这个过程中学到了很多东西!)而且据我所知,我已经尝试了所有明显的和推荐的东西。

我现在似乎在绕圈子(即无处​​可去),因此非常感谢收到关于我下一步可能尝试什么的任何建议。

背景信息:

  • 具有公有和私有(private) IP 的 EC2 实例,没有弹性 IP 或负载均衡器
  • Ubuntu Xenial 16.04、Apache 2.4.18、Tomcat7、GeoServer 2.11.0
  • 安全组配置并应用于 EC2 实例,规则如下:

    INBOUND RULES
    Type             Protocol   Port Range  Source
    HTTP             TCP        80          0.0.0.0/0
    HTTP             TCP        80          ::/0
    Custom TCP Rule  TCP        8080        x.x.x.x/32
    Custom TCP Rule  TCP        5432        x.x.x.x/32
    SSH              TCP        22          x.x.x.x/32
    Custom TCP Rule  TCP        443         0.0.0.0/0
    Custom TCP Rule  TCP        443         ::/0
    
    OUTBOUND RULES
    Type             Protocol   Port Range  Destination
    All traffic      All        All         0.0.0.0/0
    
  • 域名解析Ok到公网IP

  • 防火墙已禁用 - sudo ufw status 返回“状态:不活动”
  • 可以通过 SSH 从 PuTTY 连接到服务器
  • 可以使用 http://Public-IP:8080/geoserver/web/ 从浏览器访问 GeoServer Web Admin
  • 检查 this post 并更新/usr/share/tomcat7/bin/catalina.sh 以添加以下内容:

    JAVA_OPTS=" $JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Ad=true "
    
  • 检查 this post 并更新/etc/tomcat7/server.xml 以生成连接器字符串:

    <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           URIEncoding="UTF-8"
           redirectPort="8443"
           address="0.0.0.0"
           useIPVHosts="true" />
    
  • 使用 netstat 检查在不同端口上监听的内容:

    root@ip-xxx-xx-xx-xx:/var/log/apache2# netstat -ltnpa | grep -i --colour LISTEN
    tcp    0      0 127.0.0.1:587           0.0.0.0:*       LISTEN      1438/sendmail: MTA:
    tcp    0      0 0.0.0.0:8080            0.0.0.0:*       LISTEN      1437/java
    tcp    0      0 0.0.0.0:22              0.0.0.0:*       LISTEN      1208/sshd
    tcp    0      0 0.0.0.0:5432            0.0.0.0:*       LISTEN      1350/postgres
    tcp    0      0 127.0.0.1:25            0.0.0.0:*       LISTEN      1438/sendmail: MTA:
    tcp    0      0 127.0.0.1:8005          0.0.0.0:*       LISTEN      1437/java
    tcp6   0      0 :::80                   :::*            LISTEN      1456/apache2
    tcp6   0      0 :::22                   :::*            LISTEN      1208/sshd
    tcp6   0      0 :::5432                 :::*            LISTEN      1350/postgres
    tcp6   0      0 :::443                  :::*            LISTEN      1456/apache2
    

观察到的问题

调试显示 Flask 应用程序向 http://Public-IP:8080/geoserver/roar/wms 发送了格式良好的请求?...但是对 urllib2.urlopen(req) 的调用抛出异常“[Errno 110] 连接超时”,这是通过 abort(404) 报告的.

如果我获取请求字符串(使用公共(public) IP)并将其粘贴到浏览器中,它就可以正常工作。请注意,这是 http://而不是 https://- 不确定这是否重要 - 请参阅下面有关使用 https://

的说明

如果我使用公共(public) IP 从命令行尝试 cURL,我会收到超时消息:

    connect to Public-IP port 8080 failed: Connection timed out
    * Failed to connect to Public-IP port 8080: Connection timed out
    * Closing connection 0

如果我使用本地主机从命令行尝试 cURL,例如到端口 8080 上的 Tomcat7,它可以工作......

    $ curl -v localhost:8080/
    *   Trying 127.0.0.1...
    * Connected to localhost (127.0.0.1) port 8080 (#0)
    > GET / HTTP/1.1
    > Host: localhost:8080
    > User-Agent: curl/7.47.0
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < Server: Apache-Coyote/1.1
    < Accept-Ranges: bytes
    < ETag: W/"1896-1493801565000"
    < Last-Modified: Wed, 03 May 2017 08:52:45 GMT
    < Content-Type: text/html
    < Content-Length: 1896
    < Date: Fri, 22 Jun 2018 09:39:46 GMT
    <
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Apache Tomcat</title>
    </head>
    <body>
    <h1>It works !</h1>
    etc…….

如果我使用私有(private) IP 从命令行尝试 cURL,例如到端口 8080 上的 Tomcat7,它可以工作......

    $ curl -v Private-IP:8080/
    *   Trying Private-IP...
    * Connected to Private-IP (Private-IP) port 8080 (#0)
    > GET / HTTP/1.1
    > Host: Private-IP:8080
    > User-Agent: curl/7.47.0
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < Server: Apache-Coyote/1.1
    < Accept-Ranges: bytes
    < ETag: W/"1896-1493801565000"
    < Last-Modified: Wed, 03 May 2017 08:52:45 GMT
    < Content-Type: text/html
    < Content-Length: 1896
    < Date: Fri, 22 Jun 2018 09:42:30 GMT
    <
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Apache Tomcat</title>
    </head>
    <body>
    <h1>It works !</h1>
    etc…….

如果我只是尝试使用带有域名或公共(public) IP 的 http://从浏览器连接到端口 8080,我会收到 Tomcat7 index.html ‘It works!’ 响应。

如果我使用 https://尝试相同的操作,我会从 Mozilla 获得以下信息......

   Secure Connection Failed
   An error occurred during a connection to Public-IP:8080. SSL received a record that
   exceeded the maximum permissible length. Error code: SSL_ERROR_RX_RECORD_TOO_LONG
       The page you are trying to view cannot be shown because the authenticity of the received data
       could not be verified.

和来自 IE(建议的设置打开)...

    This page can’t be displayed
    Turn on TLS 1.0, TLS 1.1, and TLS 1.2 in Advanced settings and try connecting to
    https://Public-IP:8080  again. If this error persists, it is possible that this site uses an
    unsupported protocol or cipher suite such as RC4 (link for the details), which is not considered
    secure. Please contact your site administrator.

来自 Chrome ......

    This site can’t provide a secure connection
    Public-IP sent an invalid response.
    Try running Windows Network Diagnostics.
    ERR_SSL_PROTOCOL_ERROR

最佳答案

如果 Flask 应用程序和 GeoServer 运行在同一个 EC2 服务器上,它们应该通过 localhost 而不是私有(private) IP 或公共(public) IP 在彼此之间进行通信

关于Ubuntu EC2 服务器未连接到 Tomcat7 和 GeoServer 的公共(public) IP 端口 8080,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50986747/

相关文章:

linux - 强制引导进入 Linux 命令行

ubuntu - 克鲁萨德 : is it possible to connect to remote server with identity file?

angularjs - ExpressJS/NodeJS - 反向代理部署

windows - 使用 PuTTY 连接到运行 freeSSHd 的 Amazon EC2 Windows 实例

events - Compact Framework - 在不活动一段时间后锁定 UI 的超时功能

ruby-on-rails - rvm 在根据默认设置重新启动后切换到旧的 ruby​​ 版本

mmap可以通过函数传递地址吗?

php - 我的 CentOS linux 机器上的 PHP 是什么用户?根?

javascript - node.js 在一定时间后发出事件

perl - 当运行时间超过特定时间限制而不退出时,我可以告诉 perl 发出警报/信号吗?