Booting two Tomcat under Linux

Source: Internet
Author: User
Tags parent directory server port

Free to learn nginx, want to configure a load balance. However, the prerequisite is that there are two web containers. Two computers are not to think about. You can only try to start two tomcat on a machine. Originally thought quite simple, as long as changed port is good. Who knows that just changing the port will not succeed. Online find a lot of solutions, either complex to die, or say foggy. So decided to combine the online statement and their own ideas, to write a plan again.

Let's talk about the solution first. (I'm using tomcat-7.0.62, the path of installation is/usr/local/apache-tomcat-7.0.62)

1. Make a copy of the original Tomcat, place the address casually, and take the file name as you please. I copy it as/usr/local/apache-tomcat-7.0.62-copy

2. Modify the/usr/local/apache-tomcat-7.0.62-copy/conf/server.xml, the intention is not to let the port conflict with the original

There are three ports in this server.xml, and the default settings are listed below. These three ports are to be modified. (I started with the idea that as long as the simple after adding a 1, to become 80051,80801,80091, anyway, as long as the port maximum not more than 65535 on the line.) Results report what port out of range error ..... All right, then change to 8006,8081,8010.

1 <!--This seems to be the closed port, the specific role is unclear-->2 <server port= "8005" shutdown= "Shutdown" >3  4 <!--This should know what the port is.-->5  <connector port= "8080" protocol= "http/1.1"  connectiontimeout= "20000" redirectport= "8443"/>6  7  8  <!--comment on what AJP 1.3 of the connection port, specifically what role or not clear-->9  <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>

3. Add the following two in the ~/.bash_profile.

1 Export CATALINA_BASE2=/USR/LOCAL/APACHE-TOMCAT-7.0.62-COPY2 Export catalina_home2=/usr/local/ Apache-tomcat-7.0.62-copy

After the modification is complete, use the command source ~/.bash_profile to make the newly configured environment variable take effect

You can see that the effect of these two lines is to add environment variables, but the method of adding environment variables is not the only one. So no matter what the method, the purpose of adding these two environment variables is OK.

4. Modify the/usr/local/apache-tomcat-7.0.62-copy//bin/catalina.sh and add the following green two lines at the beginning of the position. (almost at the beginning of the catalina.sh position)

1 # Resolve Links-$ may a Softlink 2 prg= "$" 3  4 While [-H ' $PRG]; do 5   ls= ' ls-ld "$PRG" ' 6   link= ' E Xpr "$ls": ' .*-> \ (. *\) $ ' 7   if expr "$link": '/.* ' >/dev/null; then 8     prg= "$link" 9   else10     prg= ' DirName "$PRG" '/"$link" one   fi12 done13 "Get standard environment Variables15 prgdir= ' dirname" $PRG "' + # only SE T catalina_home if not already set18 [-Z "$CATALINA _home"] && catalina_home= ' CD "$PRGDIR/..." >/dev/null; PWD ' # Copy catalina_base from Catalina_home if not already set21 [-Z ' $CATALINA _base "] && catalina_base=" $ Catalina_home "Catalina_home= $CATALINA _home224 catalina_base= $CATALINA _base2

5. Start two Tomcat, respectively.

Well, the following is my own explanation of catalina.sh, which has nothing to do with starting two tomcat.

The code for the fourth step above is to get catalina_home and catalina_base.

The first paragraph is to say that if SH is a link, the processing method. $ A is the name of the bash file.

1 # Resolve Links-$ may a Softlink 2 prg= "$" 3  4 While [-H ' $PRG]; do 5   ls= ' ls-ld "$PRG" ' 6   link= ' E Xpr "$ls": ' .*-> \ (. *\) $ ' 7   if expr "$link": '/.* ' >/dev/null; then 8     prg= "$link" 9   else10     prg= ' DirName "$PRG" '/"$link"   fi12 Done

One of the following sentences is to get the folder where bash is located.

1 # GET Standard environment Variables2 prgdir= ' dirname "$PRG" '

The following note is clearly written, if we configure the CATALINA_HOME environment variable, then do nothing, if not configured, then let the variable Cataline_home point to PRGIDR parent directory, is actually the Tomcat installation directory.

1 # only set Catalina_home if not already set2 [-Z "$CATALINA _home"] && catalina_home= ' CD "$PRGDIR/:" >/dev/ Null PWD ' 3 4 # Copy catalina_base from Catalina_home if not already set5 [-Z ' $CATALINA _base "] && catalina_base=" $CAT Alina_home "

Our modifications mean no matter what the front catalina_home and catalina_base set for, anyway finally I fits, all set for what I want, i.e. the code below

1 catalina_home= $CATALINA _home22 catalina_base= $CATALINA _base2

Here's another explanation:

In theory, the above configuration is possible. But there is a small flaw: assuming that the environment variables $catalina_home2 and $CATALINA_BASE2 are located under the root user, then Tomcat can only be started with the root user, the other users will not start at all.

And if someone does not know that catalina.sh has been modified to replicate apache-tomcat-7.0.62-copy to another place, such as another server, he will find that Tomcat cannot boot ... In fact, catalina.sh so much better, that is, the green of the two lines move forward a move.

1 # Resolve Links-$ may a Softlink 2 prg= "$" 3  4 While [-H ' $PRG]; do 5   ls= ' ls-ld "$PRG" ' 6   link= ' E Xpr "$ls": ' .*-> \ (. *\) $ ' 7   if expr "$link": '/.* ' >/dev/null; then 8     prg= "$link" 9   else10     prg= ' DirName "$PRG"/"$link"   fi12 done13 "Get standard environment Variables15 prgdir= ' dirname" $PRG "' Catalina_ Home= $CATALINA _home218 catalina_base= $CATALINA _base219 # only set Catalina_home if not already set21 [-z] $CATALINA _ho ME "] && catalina_home= ' CD $PRGDIR/..." >/dev/null; PWD ' $ # Copy catalina_base from Catalina_home if not already set24 [-Z ' $CATALINA _base "] && catalina_base=" $ Catalina_home "

Booting two Tomcat under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.