Skip to content

DevOps-Projects-From-Scratch/Apache-Tomcat-Installation-On-Amazon-Linux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 

Repository files navigation

Apache-Tomcat-Installation-On-Amazon-Linux

Untitled

Overview of Tomcat:

  • Apache Tomcat, commonly referred to as Tomcat it is developed using the Java programming language.
  • Apache Tomcat is an open-source web server and servlet container used for hosting Java web applications.
  • It provides an environment to run Java Servlets and JavaServer Pages (JSPs) and is known for its simplicity and lightweight nature.

Prerequisites:

  • Apache Tomcat runs on port 8080 by default, so port 8080 must be open on EC2 Security Group.
  • Java to be installed it can be JDK (Java Development Kit) or JRE (Java Runtime Environment)
  • Version of Java to be installed depends upon Tomcat version.
  • You can look for it here https://tomcat.apache.org/whichversion.html

RAM and hard disk requirements:

  • The RAM and hard disk requirements for Apache Tomcat can vary depending on the specific version of Tomcat, the size and complexity of the applications being deployed, and the expected workload.

RAM Requirements:

  • For basic testing or development purposes, a minimum of 1 GB of RAM is typically sufficient.
  • For small-scale or low-traffic production environments, a minimum of 2-4 GB of RAM is recommended.
  • For medium to large-scale deployments or high-traffic environments, you should consider allocating 8 GB or more of RAM.
  • The exact amount will depend on factors such as the number of concurrent users, the size and complexity of deployed applications, and any additional services running on the server.

Hard Disk Requirements:

  • The base installation of Apache Tomcat requires around 200-300 MB of disk space.
  • Additional disk space will be needed for storing web applications, logs, and any other data generated by Tomcat.
  • The amount of disk space required will depend on the size and number of deployed applications and the volume of log data generated.

Step-1: Launch an instance.

1

Give a name to your instance: 2

Select Amazon Linux-2 AMI: 3

t2.micron is fine: 4

I am going with existing keypair, if you dont have one create new one: 5

Network setting: 6

Add new Inbound Security group rule to add 8080 port: 7

8GB storage is fine: 8

Check the summary if everything is fine launch instance: 9

you can see instance running shortly: 10

Step-2: Install Java.

amazon-linux-extras install java-openjdk11 -y
java --version

11

Step-3: Install Tomcat.

sudo su -
cd /
cd /opt
### Download tomcat binary
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.75/bin/apache-tomcat-9.0.75.zip

### unzip tomcat binary
unzip https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.75/bin/apache-tomcat-9.0.75.zip

### for convenience rename apache-tomcat-9.0.75 to tomcat.
mv apache-tomcat-9.0.75 tomcat

13

14

Step-4: Add Execute Permission to catalina.sh, startup.sh & shutdown.sh

cd /opt/tomcat/bin
chmod +x catalina.sh startup.sh shutdown.sh

15

Step-5: Create link files for Tomcat Server up and Down (optional)

we create softlink to start and stop Tomcat service from anywhere. if you Don't want to create softlink then you can start and stop Tomcat service by going to /opt/tomcat/bin directory.

ln -s /opt/tomcat/bin/startup.sh /usr/local/bin/tomcatup
ln -s /opt/tomcat/bin/shutdown.sh /usr/local/bin/tomcatdown
tomcatup 

17

Before starting Tomcat we can't access tomcat by web-browser.

16

After starting Tomcat we can access tomcat though web-browser.

18

Step-6: Update the user information in tomcat-users.xml

cd /opt/tomcat
cd conf

vi tomcat-users.xml

#Add below lines between <tomcat-users> tag

<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>   
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>

23

Step-7: Change Some Settings to Manage Tomcat

To access the Tomcat Manager App, Server Status, Host Manager you need to comment out value tag in some xml file 19

If you try to access Tomcat Manager App or Server Status or Host Manager with out doing the required settings then you will get 403 Access Denied Error. 20

cd /opt/tomcat
find -name context.xml
./conf/context.xml
./webapps/docs/META-INF/context.xml
./webapps/examples/META-INF/context.xml
./webapps/host-manager/META-INF/context.xml
./webapps/manager/META-INF/context.xml
#comment value tag sections in below all files
vi ./webapps/examples/META-INF/context.xml
vi ./webapps/host-manager/META-INF/context.xml
vi ./webapps/manager/META-INF/context.xml

Before Commenting the Value tag 21

After Commenting out the Value tag 22

To Apply The Changes Stop and Start the Tomcat Service

tomcatdown
tomcatup

24

Now we can access the tomcat Manager App, Server Status and Host Manager from web-browser 25

26

Note: Its not a Good practice to run tomcat services using root user.

  • Create a tomcat user.
  • Give ownership of /opt/tomcat directory to tomcat user.
  • Then run tomcat services using tomcat user.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published