Tomcat无法连接到8005端口

时间:2018-12-19 13:43:59

标签: java linux amazon-web-services ubuntu tomcat

我正在设置一个Web应用程序环境以运行Java应用程序。 该环境应该是:

  • AWS EC2 Ubuntu
  • Java 8
  • Tomcat 9

我启动了EC2实例并安装了Java,然后按照本指南进行操作以设置Tomcat: https://www.digitalocean.com/community/tutorials/install-tomcat-9-ubuntu-1804

现在systemctl尝试启动/重新启动Tomcat服务时,问题就出现了。这是我在查看systemctl日志时看到的内容:

Dec 19 13:35:25 ip-10-165-10-74 systemd[1]: Started Apache Tomcat Web Application Container.
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]: Dec 19, 2018 1:35:26 PM org.apache.catalina.startup.Catalina stopServer
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]: SEVERE: Could not contact [localhost:8005] (base port [8005] and offset [0]). Tomcat may not be running.
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]: Dec 19, 2018 1:35:26 PM org.apache.catalina.startup.Catalina stopServer
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]: SEVERE: Error stopping Catalina
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]: java.net.ConnectException: Connection refused (Connection refused)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.PlainSocketImpl.socketConnect(Native Method)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.Socket.connect(Socket.java:589)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.Socket.connect(Socket.java:538)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.Socket.(Socket.java:434)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.net.Socket.(Socket.java:211)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:513)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at java.lang.reflect.Method.invoke(Method.java:498)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:403)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]:         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:497)
Dec 19 13:35:26 ip-10-165-10-74 shutdown.sh[1725]: The stop command failed. Attempting to signal the process to stop through OS signal.
Dec 19 13:35:27 ip-10-165-10-74 shutdown.sh[1725]: Tomcat stopped.

据我了解,这里的问题是Tomcat无法连接到8005端口以监听关机命令。

但是,我在EC2安全组控制台中打开了此端口: enter image description here

另一个奇怪的是,Tomcat在重新启动ec2实例时可以正常启动,但是无法重新启动并引发上述异常。

这里可能是个问题?如何检查端口8005是否真正打开?

2 个答案:

答案 0 :(得分:0)

如果您在Windows上运行,则内置了一个资源监视器,用于查看使用的端口。

您应该可以在以下位置找到它:

Start >> All Programs >> Accessories >> System Tools >> Resource Monitor

然后您要做的就是寻找8005的可用性及其状态,

如果您在Mac / Linux系统上运行,那么我会在命令提示符下使用netstat进行检查。

您也可以$netstat -a查看当前使用的所有套接字。

答案 1 :(得分:-2)

由于您使用的是Ubuntu,因此请在术语中输入netstat -tlp

说明:

-t: tcp, -l: listening socket, -p: show pid and program name