0% found this document useful (0 votes)
10 views5 pages

Tomcat Installation On EC2 Instance Document

This document outlines the installation and configuration steps for Java, Jenkins, Maven, and Tomcat on an EC2 instance. It includes commands for installing each component, setting up a Jenkins job, and configuring Tomcat to run on a different port. Additionally, it provides instructions for managing user roles and credentials in Tomcat and integrating it with Jenkins for automated builds.

Uploaded by

naveen.t2412
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Tomcat Installation On EC2 Instance Document

This document outlines the installation and configuration steps for Java, Jenkins, Maven, and Tomcat on an EC2 instance. It includes commands for installing each component, setting up a Jenkins job, and configuring Tomcat to run on a different port. Additionally, it provides instructions for managing user roles and credentials in Tomcat and integrating it with Jenkins for automated builds.

Uploaded by

naveen.t2412
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Jenkins, Java & Maven Installtion EC2 Instance

1. Java installation
Yum http://13.58.116.34:8080/ install java-1.8.0 -y

2. Jenkins installation
sudo yum install Jenkins

sudo systemctl daemon-reload

service jenkin status

3. Maven installation
git clone https://github.com/mkyong/maven-examples

# mvn archetype:generate

cd java-web-project

git clone https://github.com/sahosarath/saho.git

export PATH=/opt/apache-maven-3.8.5/bin:$PATH

4. Through this we can download the java pom.xml file


http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.mkyong.web</groupId>

<artifactId>java-web-project</artifactId>

<version>java-web-project</version>

<packagingg>jar</packaging>

<name>java-web-project</name>

<description>Blank project for GraalVM</description>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncodin

<maven.compiler.target>${java.version}</maven.compiler.target>

<maven.compiler.source>${java.version}</maven.compiler.source>

<java.version>1.8</java.version>

<spring-boot.version>2.2.2.RELEASE</spring-boot.version>

<start-class>java-web-project.App</start-class>
<graal.version>19.2.1</graal.version>

</properties>

<dependencies>

<dependency>

<groupId>com.oracle.substratevm</groupId>

<artifactId>svm</artifactId>

<version>${graal.ver

(or)
We can get the pom.xml file Directly from the developer in real time work (By using fork)

5. Go to the Jenkins dashboard and Click on New Item


6. Enter the item name
7. Choose the Freestyle project option (In real time Depends on project we can choose
the project) & ok

8.
Note: Make sure that we have Tomcat server is up and running
9. Go to the post build – give Required credentials and tomcat version
10. Go to that job and build now
11. Go to the workspace and console output

cd /var/lib/jenkins/workspace/hello-world/webapp/src/main/webapp/index.jsp

12. Go to the manage Jenkins – configure – build triggers – select poll scm - given the timings (It
will trigger automatically when you change the code it will trigger at schedule time) – apply
and save

13. git add .


14. git commit -m "pom.xml"
15. git push origin 'dev'
16. Go to the tomcat cat server and check the output

Tomcat installation on EC2 instance


Pre-requisites

1. EC2 instance with yum install default-jdk

# java-open jdk-y

Install Apache Tomcat


1. Download tomcat packages from https://tomcat.apache.org/download-
80.cgi

# cd /opt
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.64/bin/apache-
tomcat-9.0.64.tar.gz
Un zip the file tar xvzf apache-tomcat-9.0.64.tar.gz
2. mv apache-tomcat-9.0.64 tomcat
3. give executing permissions to startup.sh and shutdown.sh which are
under bin.

# chmod 700 *.sh


Note: you may get below error while starting tomcat incase if you
dont install Java
Neither the JAVA_HOME nor the JRE_HOME environment variable is
defined At least one of this environment variables is needed to run
this program

4. create link files for tomcat startup.sh and shutdown.sh


5. # ln -s /opt/tomcat/tomcat/bin/startup.sh /usr/sbin/tomcatup
6. # ln -s /opt/tomcat/tomcat/bin/shutdown.sh /usr/sbin/tomcatdown
7. # ./startup.sh
8. /usr/local/bin/tomcatdown
tomcatup

Check point :

access tomcat application from browser on port 8080

 http://<Public_IP>:8080

Using unique ports for each application is a best practice in an


environment. But tomcat and Jenkins runs on ports number 8080. Hence
lets change tomcat port number to 8090. Change port number in
conf/server.xml file under tomcat home

cd /opt/tomcat/conf
# update port number in the "connecter port" field in server.xml
# restart tomcat after configuration update
# tomcatdown
# tomcatup

Check point :

Access tomcat application from browser on port 8090

 http://<Public_IP>:8090

1. now application is accessible on port 8090. but tomcat application


doest allow to login from browser. changing a default parameter in
context.xml does address this issue
2. # search for context.xml
# find / -name context.xml

3. above command gives 3 context.xml files. comment () Value


ClassName field on files which are under webapp directory. After that
restart tomcat services to effect these changes. At the time of
writing this lecture below 2 files are updated.
4. Vi /opt/tomcat/webapps/host-manager/META-INF/context.xml (we can give
starting <!—- and ending --> and save the file)
5. Vi /opt/tomcat/webapps/manager/META-INF/context.xml (we can give
starting <!—- and ending --> and save the file
6.
7. # Restart tomcat services
8. ./shutdown.sh
9. ./startup.sh

10. Update users information in the tomcat-users.xml file goto


tomcat home directory and Add below users to conf/tomcat-
users.xml file
11. <role rolename="manager-gui"/>
12. <role rolename="manager-script"/>
13. <role rolename="manager-jmx"/>
14. <role rolename="manager-status"/>
15. <user username="admin" password="admin" roles="manager-gui,
manager-script, manager-jmx, manager-status"/>
16. <user username="deployer" password="deployer" roles="manager-
script"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>

17. Restart serivce and try to login to tomcat application from the
browser. This time it should be Successful
18. Go to the Jenkins dashboard – manage Jenkins – select
credentials – select Jenkins (global credentials) – add credentials –
give user name - tomcat passwd – s3cret ( refer point no 16) - save
19. Now we go to the Jenkins dashboard and select job – give to
the post build – select container like tomcat 9 – give tomcat ip –
select credentials – apply & save
20. Go to the job and build now – check once in output (in
terminal only you check the output in cd
/workspace/webapp/main/src/webapp/index.jsp)
21. Go to the same job – configure- in build section you give
polyscm (give the timing like */2 * * * *) It will trigger automatically
every 2 min after anything you changes in the file
22. Now you go & check it in the tomcat server – manage app – it
will show the output of the project

You might also like