Você está na página 1de 11

Apache Tomcat 8 Application Server

Installation Guide
By :
Mohamed Moharam
System Engineer

The Apache Tomcat Server


The Apache Tomcat server is an open source, Java-based web application container that was
created to run servlet and JavaServer Pages (JSP) web applications. It was created under the
Apache-Jakarta subproject; however, due to its popularity, it is now hosted as a separate Apache
project, where it is supported and enhanced by a group of volunteers from the open source Java
community. Apache Tomcat is very stable and has all of the features of a commercial web
application container yet comes under Open Source Apache License. Tomcat also provides
additional functionality that makes it a great choice for developing a complete web application
solution. Some of the additional features provided by Tomcatother than being open source and
freeinclude the Tomcat Manager application, specialized realm implementations, and Tomcat
valves.

The Tomcat Directory Structure


The Tomcat installation directory is referred to as CATALINA_HOME. describes the directories
that compose a Tomcat installation. It is assumed that each of these directories is contained
within the
CATALINA_HOME directory.

Directory
/bin
/conf

Contents
Contains the startup and shutdown scripts for both Windows and Linux. Jar files
withclasses required for tomcat to start are also stored here.
Contains the main configuration files for Tomcat. The two most important are
server.xmland the global web.xml.

/lib

Contains the Tomcat Java Archive (jar) files, shared across all Tomcat components.
All
web applications deployed to Tomcat can access the libraries stored here. This
includesthe Servlet API and JSP API libraries.

/logs

Contains Tomcats log files.

/webapps
/work

The directory where all web applications are deployed, and where you place your
WAR
file when it is ready for deployment.
Tomcats working directory where Tomcat places all servlets that are generated from
JSPs. If you want to see exactly how a particular JSP is interpreted, look in this
directory.
Contain temp filesystems storage

/tmp

Install JAVA 8 (JDK 8u66) on CentOS.


This article will help you to Install JAVA 8 (JDK 8u66) or update on your system. Read
instruction carefully for downloading java from Linux command line.

Downloading Latest Java Archive


Download latest Java SE Development Kit 8 release from its official download page or use
following commands to download from shell.

For 64Bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie:
gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=acceptsecurebackup-cookie" "http://download.oracle.com/otnpub/java/jdk/8u66-b17/jdk-8u66-linux-x64.tar.gz"
# tar xzf jdk-8u66-linux-x64.tar.gz

Install Java with Alternatives


After extracting archive file use alternatives command to install it. alternatives command is
available in chkconfig package.

# cd /opt/jdk1.8.0_66/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_66/bin/java
2
# alternatives --config java
There are 3 programs which provide 'java'.
Selection

Command

----------------------------------------------+ 2

/opt/jdk1.8.0_66/bin/java

Enter to keep the current selection[+], or type selection number: 2

At this point JAVA 8 has been successfully installed on your system. We also recommend to
setup javac and jar commands path using alternatives

# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_66/bin/jar 2

# alternatives --install /usr/bin/javac javac


/opt/jdk1.8.0_66/bin/javac 2
# alternatives --set jar /opt/ jdk1.8.0_66/bin/jar
# alternatives --set javac /opt/ jdk1.8.0_66/bin/javac

Check Installed Java Version


Check the installed Java version on your system using following command.

root@tecadmin ~# java -version


java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

Configuring Environment Variables


Most of Java based applications uses environment variables to work. Set the Java environment
variables using following commands

Setup JAVA_HOME Variable

# export JAVA_HOME=/opt/jdk8

Setup JRE_HOME Variable

# export JRE_HOME=/opt/jdk8/jre

Setup PATH Variable

# export PATH=$PATH:/opt/jdk8/bin:/opt/jdk8/jre/bin

Also put all above environment variables in /etc/environment file for auto loading on system
boot.

Step 2: Downloading Tomcat Archive


Download Apache Tomcat 8 archive file using following commands or you can visit Tomcat
8official download page for download most recent available version. After downloading extract
archive file in /opt directory. You may change this location as per your setup.

# cd /opt
# wget http://www.us.apache.org/dist/tomcat/tomcat8/v8.0.27/bin/apache-tomcat-8.0.27.tar.gz
# tar xzf apache-tomcat-8.0.27.tar.gz

Step 3: Configure Environment Variables


Before starting Tomcat, configure CATALINA_HOME environment variable in your system
using following commands.
# echo "export CATALINA_HOME=\"/opt/tomcat8\"" >> ~/.bashrc
# source ~/.bashrc

Step 4: Starting Tomcat


Tomcat is very easy to use, There are no need to compile its source. You simple extract the
archive and start the tomcat server. Tomcat by default start on port 8080, So make sure no other
application using the same port.

# cd /opt/apache-tomcat-8.0.27

# ./bin/startup.sh

Step 5: Access Tomcat in Browser


Tomcat server works on port 8080 default. Access tomcat on web browser by connecting your
server on port 8080.
http://localhost:8080

Step 6 : verify Tomcat is running successful

Step 6: Setup User Accounts

Finally we need to create user accounts to secure and access admin/manager pages.
Editconf/tomcat-users.xml file in your editor and paste inside <tomcat-users> </tomcatusers> tags.

Now you can access the Tomcat Application Server with the username & password to deploy
applications and check server status as you see below .

Deploying WAR Archive


The WAR (Web Archive) file is a single file that contains all web application resources, and can
be deployed directly to Tomcat. The WAR file is actually a zip-compatible archived file . To
deploy a WAR-packaged web application, all you have to do is copy it to the
CATALINA_HOME/webapps directory. Make sure you remove the previously deployed
applications exploded directory. Upon server startup, Tomcat will pick up the apress.war file
and deploy it automatically. When Tomcat is up and running again, you can access the web
application from the browser in the same way as before.
The Second method 1-login to the Tomcat web server using username & password .2- choice
manage applications . 3- the middle you will see war file deploy section 4- choose the war file
5. press deploy now your application have been uploaded remotely and running in the apache
tomcat as you see in the following

(1)

(2)

(3)

(4)

Customizing the Java Virtual Machine


Exploring the java jvm and customize it to enhance application performance in memory and
issues related to garbage collections by controlling the max memory size for the JVM and min
memory for the heap size . by opining /opt/tomcat-server/bin/catalina.sh and modify memory
size as you see in the following

Connection Proxy
Since Tomcat typically listens on port 8080, rather than configure Tomcat on
port 80 for normal HTTP requests, we can use Nginx to proxy those
connections and rewrite the URLs
1- Install epel for nginx packages

2- Create new directory under /etc/nginx as you see below

3- Create new configuration file to to be able to access the server over port 80 instead off
8080 using nginx features as you see and restart the service now you can access it over
port 80 instead of 8080 http://server:80

Você também pode gostar