Configure the Tomcat server under Ubuntu and set up the method of automatic startup

  • 2020-04-01 04:19:36
  • OfStack

Now that we are Ubuntu, we should make good use of the new lide package manager.
1.Tomcat needs JDK support, so let's talk about the installation of JDK first. If you have installed JDK, you can directly see article 2.
1.1 to install the JDK
Search for "sun-java" in novato, install the latest JDK, such as "sun-java6-jdk," and click on the application to automatically install.
1.2 configure JDK environment variables
The installation is automatic, but the configuration needs to be done yourself.
1.2.1 modify the user environment variables


 $ vi /home/fancy( Your username )/.bashrc

In the.bashrc file add:


  export JAVA_HOME="/usr/lib/jvm/java-6-sun"
  export CLASSPATH="$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
  export PATH="$PATH:$JAVA_HOME/bin"

1.2.2 modify the environment variables for all users


  $sudo vi /etc/profile

Add:


  export JAVA_HOME="/usr/lib/jvm/java-6-sun"
  export CLASSPATH="$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
  export PATH="$PATH:$JAVA_HOME/bin"

2.Tomcat installation and configuration, here is the key
2.1 install Tomcat through xinlide
Without further ado, search for "tomcat" and select the appropriate package to use.
2.2 the Tomcat configuration
This is the point of the point.


 $sudo vi /etc/profile

Add:


  export CATALINA_HOME="/usr/share/tomcat5.5"

Note:
A. Some places on the Internet say set TOMCAT_HOME, which is not true;
B. It is also said on the Internet that conf/server.xml and web.xml need to be modified, which is not necessary in ubuntu when installing with the new stand (of course, it can be changed later when needed, but not when first installed).
OK, configuration complete. Restart! The /etc/profile change will not take effect until the computer is restarted.
3. Start the Tomcat service
3.1 go to /usr/share-tomcat5.5/bin and you can see that there are several bash scripts to use


  $./startup.sh

The service is ready to start.
Note that tomcat does not need to be installed with apache and can be used directly as a web server.
The result of running./startup.sh should be:


 Using CATALINA_BASE: /usr/share/tomcat5.5
  Using CATALINA_HOME: /usr/share/tomcat5.5
  Using CATALINA_TMPDIR: /usr/share/tomcat5.5/temp
  Using JRE_HOME: /usr/lib/jvm/java-6-sun

3.2 you may have the following problems when running./startup.sh:


  touch: cannot touch `/usr/share/tomcat5.5/logs/catalina.out': Permission denied ./catalina.sh: 323: cannot create /usr/share/tomcat5.5/logs/catalina.out

The reason is that the permissions of the directory logs after installation are not enough. You can change it by:


  $ sudo chmod 766 ./logs -R

4. Check whether the service was started successfully
Open your browser and type: localhost:8180.
The default port of Tomcat is 8180, you can conf/server.xml inside
Modified to
Then you can access localhost directly.
If the service is open, you will see the Tomcat navigation home page.
5. Turn off the service
Just run shutdown.sh under bin/.


  $./shutdown.sh

The normal results are as follows:


  Using CATALINA_BASE: /usr/share/tomcat5.5
  Using CATALINA_HOME: /usr/share/tomcat5.5
  Using CATALINA_TMPDIR: /usr/share/tomcat5.5/temp
  Using JRE_HOME: /usr/lib/jvm/java-6-sun

Setup tips for Tomcat bootup

Installed Tomcat 5.5, very simple, will download the installation file package unzip, into the corresponding directory, and then in the Linux environment to set the corresponding environment variables such as: JAVA_HOME, CATALINA_HOME, and so on, in the bin directory of Tomcat. If you need to add tomcat to the bootup queue, you need to do the following:

Login as root:


  cd /etc/rc.d/init.d/ 

  vi tomcat 

The contents of the document are as follows:


#!/bin/sh
#
# tomcat: Start/Stop/Restart tomcat
#
# chkconfig: 2345 80 20
# description: Tomcat is a Java Servlet Container
#
#
# match these values to your environment:
export CATALINA_BASE=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CATALINA_TMPDIR=/usr/local/tomcat/temp
export JRE_HOME=/usr/java/jdk15



# Source function library.
. /etc/rc.d/init.d/functions

TOMCAT=/usr/local/tomcat

start() {
echo -n $"Starting Tomcat: "
$TOMCAT/bin/catalina.sh start
}

stop() {
echo -n $"Stopping Tomcat: "
$TOMCAT/bin/catalina.sh stop

}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
;;
status)
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
;;
esac
exit $RETVAL

Modify tomcat as a runnable file, please refer to the following command:


  chmod a+x tomcat 

Add the tomcat command to the system startup queue using the chkconfig command:


  chkconfig --add tomcat 

View the status of apachectl:


  chkconfig --list tomcat 

Ok, all done, very simple record, I hope to help you, but also let me remember!


Related articles: