简体   繁体   中英

How to start 2 Tomcat Servers simultaneously Correctly from different directory?

I have 2 Tomcat Servers in different directory D and EI want to start these Servers simultaneously.

What I did:

1st Approach:

1)By reading on various sites I found to change the port no of the tomcat which i did.

2)In my Catalina_Home folder I have path value of CATALINA_HOME=D:\\tomcat\\apache-tomcat-7.0.70.

When I start Tomcat from drive EI get an error in Tomcat of Drive E which is

INFO: Server startup in 105794 ms
Aug 22, 2016 10:37:29 AM org.apache.catalina.core.StandardServer await
SEVERE: StandardServer.await: create[localhost:8005]:
java.net.BindException: Address already in use: JVM_Bind
    at java.net.DualStackPlainSocketImpl.bind0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
    at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
    at java.net.PlainSocketImpl.bind(Unknown Source)
    at java.net.ServerSocket.bind(Unknown Source)
    at java.net.ServerSocket.<init>(Unknown Source)
  at org.apache.catalina.core.StandardServer.await(StandardServer.java:444)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:781)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:727)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)

Aug 22, 2016 10:37:29 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-apr-8080"]
Aug 22, 2016 10:37:29 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-apr-8009"]
Aug 22, 2016 10:37:29 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Aug 22, 2016 10:37:29 AM org.apache.catalina.loader.WebappClassLoaderBase  clear ReferencesThreads
SEVERE: The web application [/Subs_Engine] appears to have started a thread name
d [Abandoned connection cleanup thread] but has failed to stop it. This is  very
likely to create a memory 

2nd Approach:

As said I tried the following things in cmdPrompt for tomcat defined in E Drive

@Edit 在此处输入图片说明 And I get the following prompt saying

在此处输入图片说明

3rd Approach:

a)Port Nos I have verified.They both are different in each directory of Server.

b)I have opened startup.bat and have replaced CATALINA_HOME with CATALINA_HOME_E.

c)I have set CATALINA_HOME_E in System and User defined environment variable as E:\\apache-tomcat-7.0.70.

And in System variables the path variable I have added is %CATALINA_HOME_E%\\lib;

Now the tomcat got started but I am getting the error:

INFO: Server startup in 105794 ms
Aug 22, 2016 10:37:29 AM org.apache.catalina.core.StandardServer await
SEVERE: StandardServer.await: create[localhost:8005]:
java.net.BindException: Address already in use: JVM_Bind
    at java.net.DualStackPlainSocketImpl.bind0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
    at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
    at java.net.PlainSocketImpl.bind(Unknown Source)
    at java.net.ServerSocket.bind(Unknown Source)
    at java.net.ServerSocket.<init>(Unknown Source)
  at org.apache.catalina.core.StandardServer.await(StandardServer.java:444)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:781)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:727)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)

The reason I see for this error is that Tomcat I am starting from E drive is starting from D drive . I saw the port on which I am running Tomcat which is 7080 for http using >netstat -ano|find ":7080"

I didn't find anything running. So,I have cofigured the path settings wrong.

Am I doing it right for this approach?

Can anyone guide me why how to correct this?

Here is what you should try

a) Set different ports for both the tomcat instances. This is done by editing the server.xml and ensuring that there is no port conflict. In port selection ensure that you have no "other" applications listening in (Different application lets say listening in on 8085 - non tomcat may be for example)

b) Do not set a global path for startServer.bat or have both the startServer.bat in the command line or user profile. Everytime you start startServer on the command line ensure you set the path then and there. Since you mention D and E , i assume windows here.

On the command line

a) cd ... b) SET CATALINA_HOME=D:...\\TomcatOnD\\ c) SET PATH=%PATH%;D:...\\TomcatOnD\\bin d)startServer.bat

do the same thing , with different path for the tomcat on E:\\

see if the servers boot up. Hopefully they should :)

what you have to do is

  1. use different port for the second server
  2. use different catalina for the second server

i will leave first tomcat as is, the one on D: the one we will change is the E:

1- open conf/server.xml for tomcat which is installed on E: find the port config element (tag) named Connector change the port to any unused port, ex 9090

<Connector port="9090" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

make sure the one on D: does not use the same port too.

2- open the bin/startup.bat for server installed on E: and replace all CATALINA_HOME to CATALINA_HOME_E you can use different name if you want.

3- add new System Enviroment key CATALINA_HOME_E make it point to E:\\apache-tomcat-7.0.70\\bin

now you can start both servers using startup.bat files located on E:\\apache-tomcat-7.0.70\\bin and D:\\apache-tomcat-7.0.70\\bin

i have used this method years ago on a windows, though it is not tested recently. but i assume it will still work

Don't add E:\\apache-tomcat-7.0.70\\bin or D:\\apache-tomcat-7.0.70\\bin to PATH as when you do so, if you type startup in cmd it may start the same instance twice. instead navigate to the folder and start the bat file

if you need to add to PATH you need to rename the startup files, so they end like this startupd.bat and startupe.bat so no mixing will occur when you start servers using command.

EDIT: as per your feedback on this method tomcat uses a connection -i think- it's for some internal signaling and communication, may be to send the shutdown signal to the server?! which is on port 8005 by default you need to set a new port on the E: tomcat, it's on server.xml conf file tag SERVER <Server port="8005" shutdown="SHUTDOWN" set a new port, may be 8006

Check the configuration file server.xml
The ports defined in
<Connector connectionTimeout="20000" port="9090" protocol="HTTP/1.1" redirectPort="8443"/>
and
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443"/>

should be different for each tomcat instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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