在一台电脑上同时启动两个tomcat

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/allofhuan/article/details/53131318

最近在学习cms快速建站系统,由于公司已经有一个在做的项目,自己又在研究cms的工作流程,所以需要启动两个tomcat。
(翻到最后直达结果)
首先我们要了解一下tomcat根目录下的 server.xml里面几个默认的端口号:
server port=”8005“:负责关闭tomcat服务
Connector port=”8080“:负责建立http连接
Connector port=”8009“:负责和其他的HTTP服务器建立连接
那下面就开始了 以tomcat6和tomcat7为示例:
首先我们把两个tomcat部署到myeclipse上面,先跑起一个
这里写图片描述

这时候再启动tomcat6报错如下:
8080端口被占用:

Failed to start connector [Connector[HTTP/1.1-8080]]
LifecycleException:  service.getName(): "Catalina";  Protocol handler start failed: java.lang.IllegalStateException: Unable to initialise endpoint. A previous call to init() failed. See previous log messages for details.
    at org.apache.catalina.connector.Connector.start(Connector.java:1227)
    at org.apache.catalina.core.StandardService.start(StandardService.java:540)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    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.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
十一月 11, 2016 6:01:38 下午 org.apache.coyote.ajp.AjpAprProtocol start

8009端口被占用:

Failed to start connector [Connector[AJP/1.3-8009]]
LifecycleException:  service.getName(): "Catalina";  Protocol handler start failed: java.lang.IllegalStateException: Unable to initialise endpoint. A previous call to init() failed. See previous log messages for details.
    at org.apache.catalina.connector.Connector.start(Connector.java:1227)
    at org.apache.catalina.core.StandardService.start(StandardService.java:540)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    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.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
十一月 11, 2016 6:01:38 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 942 ms
十一月 11, 2016 6:01:38 下午 org.apache.catalina.core.StandardServer await

8005端口被占用:

严重: StandardServer.await: create[8005]: 
java.net.BindException: Address already in use: JVM_Bind
    at java.net.DualStackPlainSocketImpl.bind0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)
    at java.net.ServerSocket.bind(ServerSocket.java:376)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at org.apache.catalina.core.StandardServer.await(StandardServer.java:404)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:676)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:628)
    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.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
十一月 11, 2016 6:01:38 下午 org.apache.coyote.http11.Http11AprProtocol pause

这个时候我们没有修改任何配置文件,两个tomcat都是默认的端口,三个端口都是一样的,所以控制台报了三个信息。
接下来我们修改tomcat6配置文件conf文件夹下面的server.xml文件,将8080端口改为8089,报错如下:

严重: Failed to start connector [Connector[AJP/1.3-8009]]
LifecycleException:  service.getName(): "Catalina";  Protocol handler start failed: java.lang.IllegalStateException: Unable to initialise endpoint. A previous call to init() failed. See previous log messages for details.
    at org.apache.catalina.connector.Connector.start(Connector.java:1227)
    at org.apache.catalina.core.StandardService.start(StandardService.java:540)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    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.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
十一月 11, 2016 6:25:59 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 998 ms
十一月 11, 2016 6:25:59 下午 org.apache.catalina.core.StandardServer await
严重: StandardServer.await: create[8005]: 
java.net.BindException: Address already in use: JVM_Bind
    at java.net.DualStackPlainSocketImpl.bind0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)
    at java.net.ServerSocket.bind(ServerSocket.java:376)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at org.apache.catalina.core.StandardServer.await(StandardServer.java:404)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:676)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:628)
    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.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

现在我们将其余两个端口8009改为9009,8005改为9005,再次启动tomcat,服务正常启动。期间我试过几次每次改一个端口发现
仅仅修改8080端口和8005端口服务可以启动,但是还是会报错,而仅仅修改8080端口和8009端口则不行,具体原因还在学习中。。。。。

总结:在一台电脑上同时启动两个tomcat服务器只需要将tomcat根目录中的conf中的server.xml文件修改其中的8080,8005,8009三个默认端口号
改成不被其他进程占用的端口即可

以上是菜鸟学习结果,如有不对的地方望大神指出改正,感激不尽。

展开阅读全文

没有更多推荐了,返回首页