Apache Tomcat
Application Servers
i) JBoss or Wildfly
From 1.x to 7.x called JBoss and from 8.x called Wildfly
ii) Tomcat
iii) WAS (WebSphere Application Server)
iv) Weblogic
Tomcat Directory Structure
i) bin
startup.sh
startup.bat
shutdown.sh
shutdown.bat
catalina.sh start/stop
catalina.bat
version.sh
version.bat
ii) conf
tomcat-users.xml
server.xml
iii)lib
jar files
iv)logs
catalina.out
v)webapps
It stores 5 default applications. However, you can deploy any number of applications.
vi)work
After deploying the applications, it will store some application-related files which will use.
vii)temp
Temporary directory
Tomcat Server installation
The pre-requisite is java to be installed
download link for tomcat zip file
Step-1: Download and install java
Step-2: Download and install tomcat
# wget https://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.zip
# ls -lrt apache-tomcat-9.0.41.zip
-rw-r--r--. 1 root root 11983597 Dec 3 12:42 apache-tomcat-9.0.41.zip
Step-3: unzip the zip file
# unzip apache-tomcat-9.0.41.zip
# ls -lrt apache-tomcat-9.0.41
total 136
-rw-r--r--. 1 root root 16984 Dec 3 11:45 RUNNING.txt
-rw-r--r--. 1 root root 7072 Dec 3 11:45 RELEASE-NOTES
-rw-r--r--. 1 root root 3336 Dec 3 11:45 README.md
-rw-r--r--. 1 root root 2401 Dec 3 11:45 NOTICE
-rw-r--r--. 1 root root 58153 Dec 3 11:45 LICENSE
-rw-r--r--. 1 root root 5545 Dec 3 11:45 CONTRIBUTING.md
-rw-r--r--. 1 root root 19540 Dec 3 11:45 BUILDING.txt
drwxr-xr-x. 2 root root 4096 Dec 3 11:45 lib
drwxr-xr-x. 7 root root 81 Dec 3 11:45 webapps
drwxr-xr-x. 2 root root 30 Dec 3 11:45 temp
drwxr-xr-x. 2 root root 4096 Dec 3 11:46 bin
drwxr-xr-x. 3 root root 22 Dec 14 03:05 work
drwxr-xr-x. 3 root root 254 Dec 14 03:29 conf
drwxr-xr-x. 2 root root 4096 Dec 15 10:45 logs
Step-4: Check the installed tomcat version
# sh version.sh
Using CATALINA_BASE: /opt/apache-tomcat-9.0.41
Using CATALINA_HOME: /opt/apache-tomcat-9.0.41
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.41/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-9.0.41/bin/bootstrap.jar:/opt/apache-tomcat-9.0.41/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Server version: Apache Tomcat/9.0.41
Server built: Dec 3 2020 11:43:00 UTC
Server number: 9.0.41.0
OS Name: Linux
OS Version: 4.18.0-240.1.1.el8_3.x86_64
Architecture: amd64
JVM Version: 1.8.0_131-b11
JVM Vendor: Oracle Corporation
Step-5: Create a soft link for easy maintenance of tomcat
# ln -s /opt/apache-tomcat-9.0.41/bin/startup.sh /usr/bin/startTomcat
# ln -s /opt/apache-tomcat-9.0.41/bin/shutdown.sh /usr/bin/stopTomcat
# ls -rlt /usr/bin/startTomcat
lrwxrwxrwx. 1 root root 40 Dec 14 03:04 /usr/bin/startTomcat -> /opt/apache-tomcat-9.0.41/bin/startup.sh
# ls -lrt /usr/bin/stopTomcat
lrwxrwxrwx. 1 root root 41 Dec 14 03:05 /usr/bin/stopTomcat -> /opt/apache-tomcat-9.0.41/bin/shutdown.sh
to startup -> startTomcat
to shutdown/stop -> stopTomcat
Commands:
1. Startup Tomcat
]# startTomcat
Using CATALINA_BASE: /opt/apache-tomcat-9.0.41
Using CATALINA_HOME: /opt/apache-tomcat-9.0.41
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.41/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-9.0.41/bin/bootstrap.jar:/opt/apache-tomcat-9.0.41/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
OR
# sh startup.sh
Using CATALINA_BASE: /opt/apache-tomcat-9.0.41
Using CATALINA_HOME: /opt/apache-tomcat-9.0.41
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.41/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-9.0.41/bin/bootstrap.jar:/opt/apache-tomcat-9.0.41/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
OR
# sh catalina.sh start
Using CATALINA_BASE: /opt/apache-tomcat-9.0.41
Using CATALINA_HOME: /opt/apache-tomcat-9.0.41
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.41/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-9.0.41/bin/bootstrap.jar:/opt/apache-tomcat-9.0.41/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
# ps -ef |grep tomcat
root 2927 1 3 19:45 pts/0 00:00:03 /usr/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-9.0.41/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /opt/apache-tomcat-9.0.41/bin/bootstrap.jar:/opt/apache tomcat-9.0.41/bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-tomcat-9.0.41 -Dcatalina.home=/opt/apache-tomcat-9.0.41 -Djava.io.tmpdir=/opt/apache-tomcat-9.0.41/temp org.apache.catalina.startup.Bootstrap start
root 2973 2243 0 19:46 pts/0 00:00:00 grep --color=auto tomcat
2. Shutdown/Stop Tomcat
# stopTomcat
Using CATALINA_BASE: /opt/apache-tomcat-9.0.41
Using CATALINA_HOME: /opt/apache-tomcat-9.0.41
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.41/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-9.0.41/bin/bootstrap.jar:/opt/apache-tomcat-9.0.41/bin/tomcat-juli.jar
Using CATALINA_OPTS:
OR
# sh shutdown.sh
Using CATALINA_BASE: /opt/apache-tomcat-9.0.41
Using CATALINA_HOME: /opt/apache-tomcat-9.0.41
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.41/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-9.0.41/bin/bootstrap.jar:/opt/apache-tomcat-9.0.41/bin/tomcat-juli.jar
Using CATALINA_OPTS:
OR
# sh catalina.sh stop
Using CATALINA_BASE: /opt/apache-tomcat-9.0.41
Using CATALINA_HOME: /opt/apache-tomcat-9.0.41
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.41/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-9.0.41/bin/bootstrap.jar:/opt/apache-tomcat-9.0.41/bin/tomcat-juli.jar
Using CATALINA_OPTS:
# ps -ef |grep tomcat
root 3044 2243 0 19:47 pts/0 00:00:00 grep --color=auto tomcat
Steps to access tomcat server from Remote location or Desktop
Step-1: Go to Security tab and select Security group and click on Launch Wizard named and click on Add Rule in AWS console and enable the port 8080
Security -> Security Group -> Launch Wizard -> Edit Inbout Rules -> Add Rules -> add you port numbers
Step-2: Use server host and port to launch tomcat portal
http://<Server_ip_address>:<port_number>
Example: http://13.127.218.70:8080
Types of Log files in the log directory:
localhost
manager
host-manger
catalina.out
# ls -rlt
total 20
-rw-r-----. 1 root root 0 Jan 11 04:32 manager.2021-01-11.log
-rw-r-----. 1 root root 0 Jan 11 04:32 host-manager.2021-01-11.log
-rw-r-----. 1 root root 0 Jan 11 04:32 localhost_access_log.2021-01-11.txt
-rw-r-----. 1 root root 408 Jan 11 04:32 localhost.2021-01-11.log
-rw-r-----. 1 root root 5814 Jan 11 04:32 catalina.out
-rw-r-----. 1 root root 5814 Jan 11 04:32 catalina.2021-01-11.log
Steps to create users in the tomcat
Step-1: We can add users using the "tomcat-users.xml" file in the Tomcat "conf" directory
Tomcat home -> conf -> tomcat-users.xml
# pwd
/opt/apache-tomcat-9.0.41/conf
# ls -rlt
total 236
-rw-r--r--. 1 root root 177096 Dec 3 11:45 web.xml
-rw-r--r--. 1 root root 2617 Dec 3 11:45 tomcat-users.xsd
-rw-r--r--. 1 root root 7759 Dec 3 11:45 server.xml
-rw-r--r--. 1 root root 4223 Dec 3 11:45 logging.properties
-rw-r--r--. 1 root root 2365 Dec 3 11:45 jaspic-providers.xsd
-rw-r--r--. 1 root root 1172 Dec 3 11:45 jaspic-providers.xml
-rw-r--r--. 1 root root 1431 Dec 3 11:45 context.xml
-rw-r--r--. 1 root root 7468 Dec 3 11:45 catalina.properties
-rw-r--r--. 1 root root 13132 Dec 3 11:45 catalina.policy
drwxr-x---. 3 root root 23 Dec 14 03:05 Catalina
-rw-r--r--. 1 root root 2289 Dec 14 03:15 tomcat-users.xml
Add these below lines into "tomcat-users.xml" file.
Extracts lines from "tomcat-users.xml" :
<tomcat-users>
<user username="user_name" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>
Step-2: Comment out the value className from the context.xml file in the manager folder
Tomcat home -> webapps -> manager -> META-INF -> context.xml
Comment out the below line in "context.xml" file. If you don't comment out you may see "Access Denied" Or Forbidden Error.
Extract lines from context.xml file:
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
Step-3: Comment out the value className from the context.xml file in the host-manager
Tomcat home -> webapps -> host-manager -> META-INF -> context.xml
Extract lines from context.xml file:
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
When to restart the tomcat server?
only if we do any changes in the server.xml file
What are the default applications with tomcat?
/
/docs
/examples
/host-manager
/manager
Tomcat Roles
manager-gui --- able to access manager app and server status
admin-gui ---- able to access host manager
manager-script
Reserve Ports:
22 - SSH
25: SMTP
8080: Http
443: HTTPS
Note: Jboss/Wildfly/tomcat/jenkins default port is 8080
How to change the default Tomcat port (8080)
Step-1: Change the port from tomcat home location in "server.xml" file.
update your required port number in the place of 8080 port:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Make sure to modify the correct port since there would be multiple entires for 8080 port.
Note: Since you have modified "server.xml" file you must restart the tomcat server to take effect the new changes.
Step-2: Restart the tomcat server
sh shutdown.sh
sh startup.sh
# ls -lrt
total 236
-rw-r--r--. 1 root root 177096 Dec 3 11:45 web.xml
-rw-r--r--. 1 root root 2617 Dec 3 11:45 tomcat-users.xsd
-rw-r--r--. 1 root root 7759 Dec 3 11:45 server.xml
-rw-r--r--. 1 root root 4223 Dec 3 11:45 logging.properties
-rw-r--r--. 1 root root 2365 Dec 3 11:45 jaspic-providers.xsd
-rw-r--r--. 1 root root 1172 Dec 3 11:45 jaspic-providers.xml
-rw-r--r--. 1 root root 1431 Dec 3 11:45 context.xml
-rw-r--r--. 1 root root 7468 Dec 3 11:45 catalina.properties
-rw-r--r--. 1 root root 13132 Dec 3 11:45 catalina.policy
drwxr-x---. 3 root root 23 Dec 14 03:05 Catalina
-rw-r--r--. 1 root root 2289 Dec 14 03:15 tomcat-users.xml
Deployment
Tomat page Manager -> Deploy -> 2 Options => Deploy using WAR file located on server OR WAR file to deploy.
The deployment files would be available at "webapps" directory in the tomcat software home location
Before:
# pwd
/opt/apache-tomcat-9.0.41/webapps
# ls -rlt
total 4
drwxr-xr-x. 3 root root 223 Dec 3 11:45 ROOT
drwxr-xr-x. 15 root root 4096 Dec 3 11:45 docs
drwxr-xr-x. 6 root root 114 Dec 3 11:45 manager
drwxr-xr-x. 6 root root 79 Dec 3 11:45 host-manager
drwxr-xr-x. 7 root root 99 Dec 3 11:45 examples
Post deployment:
[root@ip-172-31-34-208 webapps]# ls -rlt
total 5216
drwxr-xr-x. 3 root root 223 Dec 3 11:45 ROOT
drwxr-xr-x. 15 root root 4096 Dec 3 11:45 docs
drwxr-xr-x. 6 root root 114 Dec 3 11:45 manager
drwxr-xr-x. 6 root root 79 Dec 3 11:45 host-manager
drwxr-xr-x. 7 root root 99 Dec 3 11:45 examples
-rw-r-----. 1 root root 5335645 Jan 11 06:45 maven-web-application.war
drwxr-x---. 6 root root 63 Jan 11 06:45 maven-web-application ---------- deployed (default)
# ls -rlt
total 5216
drwxr-xr-x. 3 root root 223 Dec 3 11:45 ROOT
drwxr-xr-x. 15 root root 4096 Dec 3 11:45 docs
drwxr-xr-x. 6 root root 114 Dec 3 11:45 manager
drwxr-xr-x. 6 root root 79 Dec 3 11:45 host-manager
drwxr-xr-x. 7 root root 99 Dec 3 11:45 examples
-rw-r-----. 1 root root 5335645 Jan 11 07:58 fin_proj1.war
drwxr-x---. 6 root root 63 Jan 11 07:58 fin_proj1 ---------- deployed (Custom)
How to access deployed applications?
With the help of the context path and by default, the context path is the war file name. However, you could define your own context pathname.
Example:
Default:
http://13.126.233.74:9743/maven-web-application
Customize: http://13.126.233.74:9743/fin_proj1
Deployment Options:
Default => WAR file to deploy.
Custom => Deploy using WAR file located on the server
Types of Deployment
Normal Deployment
Hot Fixes/Hot Deployment
Configure service as systemctl
Difference between Tomcat and JBoss
Web Servers
Apatch Https Server
Naginx (Read as Engine X)
IHS (IBM Http Server)
Oracle IPlanet
Apps Server vs Web Server
Application Server:
Application server process the business logic. Like War, Ear files
Web server:
It can be used to host Static contents. Like, html, css, js and images)
It is used for load balancing
What file used to configure all the load balancing URLs.
httpd.conf
By default, it follows a round-robin algorithm. We could modify the request by setting the parameter "load factor".
What are the dedicated load balancing servers?
HAProxy (Open source)
F5 (It's a CISCO product and it requires a license)
Comments
Post a Comment