无法联系localhost:8005。关闭tomcat时Tomcat可能没有运行错误

时间:2017-07-25 06:59:30

标签: java apache tomcat tomcat8

您好我正在尝试关闭并启动tomcat服务器。但是我在运行shutdown.sh时遇到错误。请检查以下错误并建议我完成。

错误:

Using CATALINA_BASE:   /opt/tomcat8
Using CATALINA_HOME:   /opt/tomcat8
Using CATALINA_TMPDIR: /opt/tomcat8/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_74
Using CLASSPATH:       /opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcat-ju                                                                                        li.jar
Jul 24, 2017 11:01:47 PM org.apache.catalina.startup.Catalina stopServer
SEVERE: Could not contact localhost:8005. Tomcat may not be running.
Jul 24, 2017 11:01:48 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.ja                                                                                        va:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket                                                                                        Impl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java                                                                                        :188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at java.net.Socket.<init>(Socket.java:434)
        at java.net.Socket.<init>(Socket.java:211)

另请查找日志:

24-Jul-2017 23:48:28.884 SEVERE [main] org.apache.catalina.core.StandardServer.await StandardServer.await: create[localhost:8005]: 
 java.net.BindException: Address already in use
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
    at java.net.ServerSocket.bind(ServerSocket.java:375)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at org.apache.catalina.core.StandardServer.await(StandardServer.java:420)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:717)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:663)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

24-Jul-2017 23:48:28.884 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8082"]
24-Jul-2017 23:48:28.884 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
24-Jul-2017 23:48:28.884 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
24-Jul-2017 23:48:28.988 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8082"]
24-Jul-2017 23:48:28.990 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8082"]
24-Jul-2017 23:48:28.992 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
24-Jul-2017 23:48:28.992 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]

5 个答案:

答案 0 :(得分:2)

在端口8005上运行了一些应用程序,因为tomcat无法绑定端口上的网络。您的shutdown.sh将抛出异常,因为服务器尚未启动(因为启动服务器时出现问题)

  • 解决方案1(推荐):在/opt/tomcat8/conf/server.xml中将端口从8005更改为8006
  • 解决方案2:请netstat -tulnp | grep 8005检查哪个应用程序正在使用8005并将其关闭。

答案 1 :(得分:1)

如果时间戳正确,则表明您的tomcat启动在23:00左右失败,并且您尝试在11:00关闭不存在的tomcat服务

答案 2 :(得分:1)

您可以尝试添加 出口JRE_HOME = $ JAVA_HOME / jre 在/ etc / profile中,然后运行 来源/ etc / profile 对我来说合适。

答案 3 :(得分:1)

http://blog.51cto.com/zero01/2053974。我今天遇到同样的问题。当我要执行shudown.sh时,日志显示tomcat可能未运行,并且拒绝了与端口8005的连接。当我使用netstat -atunp时,我发现没有进程监听端口8005。因此,tomcat应该无法启动。我搜索,并在下面显示的链接中找到答案。关键是更改此文件

  

$ JAVA_HOME / jre / lib / security / java.security

要更改的数据是在'random'之前添加char'u'

  

securerandom.source =文件:/ dev / random

     

securerandom.source =文件:/ dev / urandom

,并且有效。但是我不知道为什么?有人可以告诉我吗?希望这对其他人有帮助。

答案 4 :(得分:0)

尝试从./catalina.sh运行开始 一切都好,那么它将出现在屏幕上 或者它会显示一些错误  就像在我的情况下

[root@localhost bin]# ./catalina.sh run
Using CATALINA_BASE:   /root/Desktop/tomcat/apache-tomcat-8.5.23
Using CATALINA_HOME:   /root/Desktop/tomcat/apache-tomcat-8.5.23
Using CATALINA_TMPDIR: /root/Desktop/tomcat/apache-tomcat-8.5.23/temp
Using JRE_HOME:        /root/Desktop/jdk1.8.0_144/jre
Using CLASSPATH:       /root/Desktop/tomcat/apache-tomcat-8.5.23/bin/bootstrap.jar:/root/Desktop/tomcat/apache-tomcat-8.5.23/bin/tomcat-juli.jar
Invalid maximum heap size: -Xmx512MB
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

更改内存堆大小然后肯定会工作

[root@localhost bin]# ./catalina.sh run
Using CATALINA_BASE:   /root/Desktop/tomcat/apache-tomcat-8.5.23
Using CATALINA_HOME:   /root/Desktop/tomcat/apache-tomcat-8.5.23
Using CATALINA_TMPDIR: /root/Desktop/tomcat/apache-tomcat-8.5.23/temp
Using JRE_HOME:        /root/Desktop/jdk1.8.0_144/jre
Using CLASSPATH:       /root/Desktop/tomcat/apache-tomcat-8.5.23/bin/bootstrap.jar:/root/Desktop/tomcat/apache-tomcat-8.5.23/bin/tomcat-juli.jar
10-Oct-2017 02:28:13.782 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.23
10-Oct-2017 02:28:13.808 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Sep 28 2017 10:30:11 UTC
10-Oct-2017 02:28:13.808 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.23.0
10-Oct-2017 02:28:13.808 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
10-Oct-2017 02:28:13.808 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-123.el7.x86_64
10-Oct-2017 02:28:13.809 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
10-Oct-2017 02:28:13.809 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /root/Desktop/jdk1.8.0_144/jre
10-Oct-2017 02:28:13.809 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_144-b01
10-Oct-2017 02:28:13.809 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
10-Oct-2017 02:28:13.810 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /root/Desktop/tomcat/apache-tomcat-8.5.23
10-Oct-2017 02:28:13.810 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /root/Desktop/tomcat/apache-tomcat-8.5.23
10-Oct-2017 02:28:13.810 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/root/Desktop/tomcat/apache-tomcat-8.5.23/conf/logging.properties
10-Oct-2017 02:28:13.811 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
10-Oct-2017 02:28:13.811 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
10-Oct-2017 02:28:13.811 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
10-Oct-2017 02:28:13.811 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/root/Desktop/tomcat/apache-tomcat-8.5.23
10-Oct-2017 02:28:13.811 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/root/Desktop/tomcat/apache-tomcat-8.5.23
10-Oct-2017 02:28:13.812 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/root/Desktop/tomcat/apache-tomcat-8.5.23/temp
10-Oct-2017 02:28:13.812 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
10-Oct-2017 02:28:15.306 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8081"]
10-Oct-2017 02:28:15.518 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
10-Oct-2017 02:28:15.551 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
10-Oct-2017 02:28:15.558 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
10-Oct-2017 02:28:15.568 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 4756 ms
10-Oct-2017 02:28:15.869 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
10-Oct-2017 02:28:15.870 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.23
10-Oct-2017 02:28:16.072 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/ROOT]
10-Oct-2017 02:28:18.435 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/ROOT] has finished in [2,362] ms
10-Oct-2017 02:28:18.436 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/docs]
10-Oct-2017 02:28:18.540 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/docs] has finished in [89] ms
10-Oct-2017 02:28:18.541 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/examples]
10-Oct-2017 02:28:20.151 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/examples] has finished in [1,611] ms
10-Oct-2017 02:28:20.152 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/host-manager]
10-Oct-2017 02:28:20.320 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/host-manager] has finished in [168] ms
10-Oct-2017 02:28:20.321 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/manager]
10-Oct-2017 02:28:20.438 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/root/Desktop/tomcat/apache-tomcat-8.5.23/webapps/manager] has finished in [117] ms
10-Oct-2017 02:28:20.461 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8081"]
10-Oct-2017 02:28:20.540 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
10-Oct-2017 02:28:20.547 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 4978 ms



^C10-Oct-2017 02:29:29.604 INFO [Thread-5] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8081"]
10-Oct-2017 02:29:29.695 INFO [Thread-5] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
10-Oct-2017 02:29:29.748 INFO [Thread-5] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
10-Oct-2017 02:29:30.063 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8081"]
10-Oct-2017 02:29:30.069 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
10-Oct-2017 02:29:30.077 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8081"]
10-Oct-2017 02:29:30.094 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE:   /root/Desktop/tomcat/apache-tomcat-8.5.23
Using CATALINA_HOME:   /root/Desktop/tomcat/apache-tomcat-8.5.23
Using CATALINA_TMPDIR: /root/Desktop/tomcat/apache-tomcat-8.5.23/temp
Using JRE_HOME:        /root/Desktop/jdk1.8.0_144/jre
Using CLASSPATH:       /root/Desktop/tomcat/apache-tomcat-8.5.23/bin/bootstrap.jar:/root/Desktop/tomcat/apache-tomcat-8.5.23/bin/tomcat-juli.jar

Tomcat开始了。 然后再次尝试关闭

from /bin# ./shutdown
[root@localhost bin]# ./shutdown.sh
Using CATALINA_BASE:   /root/Desktop/tomcat/apache-tomcat-8.5.23
Using CATALINA_HOME:   /root/Desktop/tomcat/apache-tomcat-8.5.23
Using CATALINA_TMPDIR: /root/Desktop/tomcat/apache-tomcat-8.5.23/temp
Using JRE_HOME:        /root/Desktop/jdk1.8.0_144/jre
Using CLASSPATH:       /root/Desktop/tomcat/apache-tomcat-8.5.23/bin/bootstrap.jar:/root/Desktop/tomcat/apache-tomcat-8.5.23/bin/tomcat-juli.jar
祝你好运