Linux - How to install apache tomcat linux, Instructions to install Apache Tomcat

How to install apache tomcat linux


This page provides steps to install Tomcat 5.5 in a CentOS Linux server. These instructions install tomcat under the root account.
Instructions to install Tomcat
1) Go to tomcat.apache.org, and download the most recent stable version of tomcat.
2) Install tomcat under /opt
# cd /opt

# wget http://apache.hoxt.com/tomcat/tomcat-5/v5.5.20/bin/apache-tomcat-5.5.20.tar.gz

Expand the archive.
# tar -zxvpf apache-tomcat-5.5.20.tar.gz
Set a symbolic link that points to the tomcat directory. This will enable you to upgrade tomcat to later versions without having to modify scripts that start and stop tomcat.
# ln -s apache-tomcat-5.5.20 tomcat
We want the system to start up tomcat when it boots, and cleanly shutdown tomcat when the system shuts down. To do this, start by creating /etc/init.d/tomcat with the following contents.
#! /bin/sh
#
# tomcat   Starts tomcat
#
# chkconfig: 2345 98 02
# description: tomcat is a J2EE web application container.
#
. /etc/init.d/functions
. /etc/profile.d/java.sh
export TOMCAT_HOME=/opt/tomcat
[ -f ${TOMCAT_HOME}/bin/startup.sh ] || exit 0
[ -f ${TOMCAT_HOME}/bin/shutdown.sh ] || exit 0

set -e

case "$1" in
   start)
      echo -n "Starting tomcat... "
      $TOMCAT_HOME/bin/startup.sh >> /var/log/tomcat 2>&1
      echo "started."
      ;;
   stop)
      echo -n "Stopping tomcat... "
      $TOMCAT_HOME/bin/shutdown.sh >>/var/log/tomcat 2>&1
      sleep 1
      rm -f $TOMCAT_HOME/logs/*
      echo "stopped."
      ;;
   restart|force-reload)
      echo -n "Restarting tomcat... "
      $TOMCAT_HOME/bin/shutdown.sh >>/var/log/tomcat 2>&1
      sleep 1
      $TOMCAT_HOME/bin/startup.sh >>/var/log/tomcat 2>&1
      echo "restarted."
      ;;
   *)
      N=/etc/init.d/tomcat
      echo "Usage: $N {start|stop|restart}" >&2
      exit 1
      ;;
esac

exit 0

Make the tomcat initialization script executable.
# chmod +x /etc/init.d/tomcat

Turn on tomcat to start and stop with the system.
# chkconfig --add tomcat
We will test that tomcat runs correctly. First, install elinks.
# yum install elinks
Start elinks, and then exit elinks by pressing q.

Start tomcat.
# service tomcat start
Try to access tomcat's default start page.
# elinks http://localhost:8080/
Test System Restart. Reboot your system, and try the previous tests to make sure tomcat comes up as expected. The following command will reboot your system immediately.
# shutdown -r now

Open Port 8080
If you wish to access tomcat directly from other hosts, then you need to open port 8080. If you will use tomcat behind apache, then you shouldn't open a port to tomcat. Prepare for Production Use

Run the following command to stop the tomcat service.
# service tomcat stop
Modify /opt/tomcat/conf/tomcat-users.xml, so that it has the following contents. (Replace username turner with another name of your choosing, and set a strong password not equal to your user password.)
<?xml version='1.0'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="turner" password="a-strong-password" roles="admin,manager"/>
</tomcat-users>

Remove the preinstalled applications you don't need.
# rm -rf /opt/tomcat/webapps/*
# rm -rf /opt/tomcat/work
To deploy a war file, go to the manager application running on your machine. For example,
# http://localhost:8080/manager/html/
You need to log in with the username and password you specified in the tomcat-users file. Use the section WAR file to deploy to upload a war file and configure it.

Configuring HTTPS

This section contains optional instructions to setup tomcat to provide HTTPS service over port 8443.

Create a keystore file with a self-signed certificate. Make sure you set the CN variable to the url of your server. (The slash at the end of the line in the following example is for line continuation.) You should replace test.com with the fully qualified domain name of your server.

To generate the keystore from the command line, do the following.
keytool -genkey \
        -keystore /opt/tomcat/conf/keystore \
        -alias tomcat \
        -keyalg RSA \
        -keysize 2048 \
        -dname CN=test.com \
        -validity 35600 \
        -storepass changeit \
        -keypass changeit

To generate the keystore from an ant build file, do the following.
<target name="create-tomcat-keystore">
   <delete file="${tomcat-keystore}" />
   <exec executable="keytool">
      <arg value="-genkey" />
      <arg value="-keyalg" />
      <arg value="RSA" />
      <arg value="-keysize" />
      <arg value="2048" />
      <arg value="-dname" />
      <arg value="CN=localhost" />
      <arg value="-alias" />
      <arg value="tomcat" />
      <arg value="-keystore" />
      <arg value="${keystore}" />
      <arg value="-keypass" />
      <arg value="changeit" />
      <arg value="-storepass" />
      <arg value="changeit" />
   </exec>
</target>
Uncomment the Connector element in /opt/tomcat/conf/server.xml that has a port attribute set to 8443. Also, add keystoreFile and keystorePass attributes to this element as follows.
keystoreFile="conf/keystore"
keystorePass="changeit"
Note: if you want to change this to another port number, then make sure you change the redirect attribute of the unencrypted connector element to your new value.

Test your configuration by starting (or restarting) tomcat, and pointing your browser to something like the following: https://test.com:8443/.

If you need to a self-signed certificate from the keystore, do something like the following. (Change the name of the file to something that reflects your server name.)
keytool -export \
        -alias tomcat \
        -keypass changeit \
        -storepass changeit \
        -keystore /opt/tomcat/conf/keystore \
        -rfc \
        -file jb340-3.cer 

The topic on Linux - How to install apache tomcat linux is posted by - Math

Hope you have enjoyed, Linux - How to install apache tomcat linuxThanks for your time

Tech Bluff