1. 程式人生 > >Linux下關閉tomcat報錯java.net.ConnectException: Connection refused

Linux下關閉tomcat報錯java.net.ConnectException: Connection refused

Linux下關閉tomcat報錯,具體如下:

Using CATALINA_BASE:   /home/alpha/apache-tomcat-7.0.62
Using CATALINA_HOME:   /home/alpha/apache-tomcat-7.0.62
Using CATALINA_TMPDIR: /home/alpha/apache-tomcat-7.0.62/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /home/alpha/apache-tomcat-7.0.62/bin/bootstrap.jar:/home/alpha/apache-tomcat-7.0.62/bin/tomcat-juli.jar
Aug 05, 2018 10:11:41 PM org.apache.catalina.startup.Catalina stopServer
SEVERE: Could not contact localhost:8095. Tomcat may not be running.
Aug 05, 2018 10:11:41 PM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop: 
java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:579)
        at java.net.Socket.connect(Socket.java:528)
        at java.net.Socket.<init>(Socket.java:425)
        at java.net.Socket.<init>(Socket.java:208)
        at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:498)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:370)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:457)

報錯原因:

        tomcat埠被佔用,或者tomcat在沒開啟的時候就關閉,導致報錯;

解決方案:

        1.使用命令:ps aux | grep tomcat      檢視tomcat的所有程序號

        2.使用命令:kill -9 程序號    依次關閉佔用埠的程序,然後重新啟動tomcat

     3.如果第二步不好使,則使用命令:sudo su -        獲取超管許可權,再使用命令:/home/alpha/apache-tomcat-7.0.62/bin/startup.sh  (即你的tomcat的startup.sh檔案的位置),執行即可啟動tomcat成功。