Introduction

Apache Tomcat is a free and open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language, and WebSocket technologies. Tomcat provides a “pure Java” HTTP web server environment in which Java code can run.

Tomcat was originally written as a fork of the Apache Jakarta Project by Joshua Chase Blose, Bill Burke, and Jim Jagielski, though Tomcat has evolved considerably since its initial release.

Tomcat was later ported to many other operating systems in addition to Linux, including Mac OS X, Solaris, and HP-UX. Windows support was added with version 3.0. The final Tomcat 6 release (the first Cactus release) was released on December 20, 2006.

If the Tomcat instance needs to be used for applications that require a lot of I/O,

it may be advantageous to allocate a large sum of memory (using the -Xmx JVM parameter) and have either lots of CPUs or a faster CPU.

If enough memory is allocated, this may reduce the number of file system calls (which are often expensive) an application makes. This in turn will allow Tomcat to process more requests per second for these types of applications.

 

Requirement

Case Uses

Installation

#install zip and wget if you don't have already
apt update && apt upgrade -y
 
apt install unzip wget 
#download tomcat from there official website
cd /tmp
wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.6/bin/apache-tomcat-10.0.6.zip
unzip apache-tomcat-10.0.6.zip
sudo mkdir -p /opt/tomcat
mv apache-tomcat-10.0.6 /opt/tomcat
cd /opt/tomcat
cd apache-tomcat-10.0.6
mv * ..
# search for connector and change the port to 8070
nano conf/server.xml
#change file permission for excute
cd /opt/tomcat/bin
chmod +x *
#start tomcat
/opt/tomcat/bin/startup.sh 
# now to go to your browser
localhost:8070
#config to connect with Jenkins
nano /opt/tomcat/conf/nano tomcat-users.xml
#add the code at the bottom 
  <role rolename="manager-script"/>
  <role rolename="manager-gui"/>
  <user username="tomcat" password="Abcd#4321" roles="manager-gui"/>
#restart tomcat
/opt/tomcat/bin/shutdown.sh 
/opt/tomcat/bin/startup.sh 
#if you see 503 access denied then follow this steps 
cd /opt/tomcat/webapps/manager/META-INF
nano context.xml 
# command out this line
<!--
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
-->
# again restast
/opt/tomcat/bin/shutdown.sh 
/opt/tomcat/bin/startup.sh 
# now can access your manager page 
http://yourmachineip:8070/manager/html
# now config tomcat for production
cd /opt/tomcat 
ls 
# you will see 
apache-tomcat-version 
#shutdown tomcat
/opt/tomcat/apache-tomcat-10.0.6/bin/shutdown.sh 
#copy to same place for prodcution
cp /opt/tomcat/apache-tomcat-10.0.6 /opt/tomcat/apache-tomcat-10.0.6-prod -r
# change the port 
nano /opt/tomcat/apache-tomcat-10.0.6-prod/confi/server.xml 
#find connector and port 8005
# change connecter to new port and 8005 to 8006 
 <Connector port="8071" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
# and 
<Server port="8006" shutdown="SHUTDOWN">
# save file 
# restart both 
/opt/tomcat/apache-tomcat-10.0.6/bin/startup.sh
/opt/tomcat/apache-tomcat-10.0.6-prod/bin/startup.sh
# access staging and production server 
localhost:9070
localhost:9071 
# check the log if you need
 tail -f apache-tomcat-10.0.6-prod/logs/catalina.out