amazon-web-servicesubuntutomcatconfigurationcloud

Tomcat virtual URL not working - AWS Ubuntu - java.net.BindException: Address already in use 8005


I'm very new to cloud hosting. Someone had setup an Ubuntu Linux server for me on AWS and I am trying to deploy my Servlet based application onto it, however, I'm having a problem with the use of Virtual URLs.

After I installed Tomcat10 I tried the server IP with the default port of 8080 and received the Tomcat landing page informing me that the setup was working and I got Tomcat installed and running successfully. Yay!

Now I took my Tomcat configuration from my Windows based servers that have been working for a decade now, copied them over to Tomcat on Ubuntu, and the URL is not connecting. The configuration is extremely simple. It changes the default port from 8080 to 80. And defines the virtual URL. See the config below.

Lastly, when I ping the Virtual URL the ping times out. When I mentioned that to the guy who setup the server for me he said it means nothing and that his setup is correct. I'm not a networking guru so have no idea what's going on. :(

Any and all ideas are absolutely welcome.

    <Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
      <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
<Host name="myappqa.mycompany.com" appBase="webapps-myappqa" unpackWARs="true" autoDeploy="false"></Host>
<Host name="mypp.mycompany.com" appBase="webapps-myapp" unpackWARs="true" autoDeploy="false"></Host>
    </Engine>

Adding the Tomcat log that John requested. I'm only adding lines that were problematic. Not the whole log file.

24-Jul-2024 17:52:03.118 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
24-Jul-2024 17:52:03.706 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-80"]
24-Jul-2024 17:52:03.727 SEVERE [main] org.apache.catalina.util.LifecycleBase.handleSubClassException Failed to initialize component [Connector["http-nio-80"]]
        org.apache.catalina.LifecycleException: Protocol handler initialization failed
                at org.apache.catalina.connector.Connector.initInternal(Connector.java:1016)
                at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:122)
                at org.apache.catalina.core.StandardService.initInternal(StandardService.java:525)
                at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:122)
                at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:961)
                at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:122)
                at org.apache.catalina.startup.Catalina.load(Catalina.java:708)
                at org.apache.catalina.startup.Catalina.load(Catalina.java:731)
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
                at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:302)
                at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:472)
        Caused by: java.net.BindException: Permission denied
                at java.base/sun.nio.ch.Net.bind0(Native Method)
                at java.base/sun.nio.ch.Net.bind(Net.java:565)
                at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:344)
                at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:301)
                at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:239)
                at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:194)
                at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1304)
                at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1317)
                at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:632)
                at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:77)
                at org.apache.catalina.connector.Connector.initInternal(Connector.java:1014)
                ... 11 more

24-Jul-2024 17:52:24.549 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [4185] milliseconds
24-Jul-2024 17:52:24.552 SEVERE [main] org.apache.catalina.core.StandardServer.await Failed to create server shutdown socket on address [localhost] and port [8005] (base port [8005] and offset [0])
        java.net.BindException: Address already in use
                at java.base/sun.nio.ch.Net.bind0(Native Method)
                at java.base/sun.nio.ch.Net.bind(Net.java:565)
                at java.base/sun.nio.ch.Net.bind(Net.java:554)
                at java.base/sun.nio.ch.NioSocketImpl.bind(NioSocketImpl.java:636)
                at java.base/java.net.ServerSocket.bind(ServerSocket.java:391)
                at java.base/java.net.ServerSocket.<init>(ServerSocket.java:278)
                at org.apache.catalina.core.StandardServer.await(StandardServer.java:537)
                at org.apache.catalina.startup.Catalina.await(Catalina.java:847)
                at org.apache.catalina.startup.Catalina.start(Catalina.java:795)
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
                at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
                at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
24-Jul-2024 17:52:24.552 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-80"]
24-Jul-2024 17:52:24.553 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]

sudo netstat -tulpn | grep :80 tcp6 0 0 127.0.0.1:8005 :::* LISTEN 11886/java

netstat Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 80 ip-999-99-9-999.eu-:ssh 88.888.88.888:28320 ESTABLISHED

sudo nc -w5 -z -v 127.0.0.1 80 nc: connect to 127.0.0.1 port 80 (tcp) failed: Connection refused

sudo wget 127.0.0.1:80 --2024-07-25 17:46:00-- http://127.0.0.1/ Connecting to 127.0.0.1:80... failed: Connection refused.


Solution

  • TC is trying to setup port 8005 as its "shutdown port".port 8005 is already linked to another process on the machine so it is not available.

    You will find the value of 8005 in %TOMCAT_HOME%/conf/server.xml. Change it to any other value, eg 9005 and TC will start.