简体   繁体   English

Apache Tomcat关闭:java.net.ConnectException:连接被拒绝

[英]Apache Tomcat Shutdown :java.net.ConnectException: Connection refused

I installed tomcat 7 on centos 5.8. 我在centos 5.8上安装了tomcat 7。 Then I executed ./startup.sh and ./shutdown.sh, it worked well. 然后我执行了./startup.sh和./shutdown.sh,它运行良好。

Then I put a something.war under the webapps/. 然后,我在webapps /下放了一个something.war。 it worked well too. 它也运作良好。 But when i shutdown the tomcat, it doesn't work and throws an exception: 但是当我关闭tomcat时,它不起作用并抛出异常:

java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at java.net.Socket.connect(Socket.java:478)
        at java.net.Socket.<init>(Socket.java:375)
        at java.net.Socket.<init>(Socket.java:189)
        at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:499)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:371)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:453)

And i'm sure: 而且我敢肯定:

  1. The tomcat is running and works well before i execute ./shutdown.sh Tomcat正在运行并在执行./shutdown.sh之前运行良好

  2. The process of the tomcat is still alive, but it isn't listening the port 8080, after i execute ./shutdown.sh 在执行./shutdown.sh之后,tomcat的进程仍然有效,但是它没有监听端口8080。

Some possibilities come to my mind: 我想到了一些可能性:

  • It is possible that your webapp starts a thread that doesn't run as "daemon" - thus keeping the process alive. 您的webapp可能启动了一个没有作为“守护程序”运行的线程-从而使进程保持活动状态。 Change this in the webapp to behave more friendly - or implement a listener that shuts down the thread when your webapp is shutting down. 在webapp中将此更改为更友好的行为-或实现一个侦听器,以在webapp关闭时关闭线程。 You can test this by triggering a thread dump ( kill -3 pid ) on the running tomcat process, the output will (most likely) end up in catalina.out 您可以通过在正在运行的tomcat进程上触发线程转储( kill -3 pid )进行测试,输出(很可能)最终会在catalina.out中结束
  • There might be another tomcat running, on a different port - that's what you see in ps output 可能在另一个端口上正在运行另一个tomcat-这就是您在ps输出中看到的内容
  • You have changed the "shutdown" port (see tomcat's server.xml ) - that's what shutdown.sh is contacting in order to instruct tomcat to shut down 您已经更改了“ shutdown”端口(请参阅tomcat的server.xml )-这是shutdown.sh正在联系的状态,以指示tomcat关闭

Check that you have localhost in /etc/hosts for 127.0.0.1 检查您在/ etc / hosts中是否有localhost用于127.0.0.1

Mine used to be like this 我的曾经是这样的

127.0.0.1   centosIGW localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

It works after I add localhost to 127.0.0.1 我将localhost添加到127.0.0.1后可以使用

127.0.0.1   centosIGW localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM