1.Software Prerequisites:
- Apache tomcat server latest version 9.0.27 should be downloaded from apache foundation Website https://tomcat.apache.org/download-90.cgi
- This Document explain how to configure Application application in tomcat Web server in RHEL server version Red Hat Enterprise Linux Server release 7.4 (Maipo)
2.Login as Oracle Account and Create Apache installation Directory:
[oracle@idalcore2 ~]$ id
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[oracle@idalcore2 oracle]$ mkdir Tomcat_9.0.27
[oracle@idalcore2 Tomcat_9.0.27]$ pwd
/oracle/Tomcat_9.0.27
3.Copy/Transfer the Downloaded Apache tomcat Zip archive in Installation Directory:
[oracle@idalcore2 Tomcat_9.0.27]$ pwd
/oracle/Tomcat_9.0.27
[oracle@idalcore2 Tomcat_9.0.27]$
[oracle@idalcore2 Tomcat_9.0.27]$
[oracle@idalcore2 Tomcat_9.0.27]$ ls -lrth
total 317M
-rw-r–r–. 1 oracle oinstall 317M Oct 21 14:45 apache-tomcat-9.0.27.zip
[oracle@idalcore2 Tomcat_9.0.27]$
4.Unzip the apache-tomcat-9.0.27.zip in same working Directory:
Archive: apache-tomcat-9.0.27.zip
creating: apache-tomcat-9.0.27/
inflating: apache-tomcat-9.0.27/BUILDING.txt
creating: apache-tomcat-9.0.27/work/
creating: apache-tomcat-9.0.27/work/Catalina/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/ROOT/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/ROOT/org/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/ROOT/org/apache/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/ROOT/org/apache/jsp/
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.class
creating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/apache/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/apache/jsp/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/apache/jsp/WEB_002dINF/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/apache/jsp/WEB_002dINF/jsp/
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/apache/jsp/WEB_002dINF/jsp/_403_jsp.class
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/apache/jsp/WEB_002dINF/jsp/_403_jsp.java
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/apache/jsp/WEB_002dINF/jsp/_401_jsp.class
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/host-manager/org/apache/jsp/WEB_002dINF/jsp/_401_jsp.java
creating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/apache/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/apache/jsp/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/apache/jsp/WEB_002dINF/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/apache/jsp/WEB_002dINF/jsp/
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/apache/jsp/WEB_002dINF/jsp/_403_jsp.class
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/apache/jsp/WEB_002dINF/jsp/_403_jsp.java
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/apache/jsp/WEB_002dINF/jsp/_401_jsp.class
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/manager/org/apache/jsp/WEB_002dINF/jsp/_401_jsp.java
creating: apache-tomcat-9.0.27/work/Catalina/localhost/examples/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/apache/
creating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/apache/jsp/
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/apache/jsp/login_jsp.java
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/apache/jsp/wrkFlwBtn_jsp.class
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/apache/jsp/HelpSrc_jsp.class
creating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/apache/jsp/CM/
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/apache/jsp/CM/acmnauth_jsp.class
inflating: apache-tomcat-9.0.27/work/Catalina/localhost/Application/org/apache/jsp/CM/mactypes_jsp.class
………………………………..
Finally unzipped Archive extracted in the same Directory should look like this.
[oracle@idalcore2 Tomcat_9.0.27]$ ls -lrth
total 317M
drwxr-xr-x. 9 oracle oinstall 220 Oct 18 12:31 apache-tomcat-9.0.27
-rw-r–r–. 1 oracle oinstall 317M Oct 21 14:45 apache-tomcat-9.0.27.zip
5.Datasource configuration to connect Oracle 19C (19.3) version from Tomcat:
Here we used Oracle Database 19c (Version 19.3.0.0.0) to test Application Core Deployment.
Go to apache catalina home ex: /oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/conf and open the server.xml file and add the Below <Resource name > content between GlobalNamingResources
Parameter’s
<GlobalNamingResources>
<!– Editable user database that can also be used by
UserDatabaseRealm to authenticate users
–>
<Resource name=”java/OracleDS”
global=”java/OracleDS”
auth=”Container”
type=”javax.sql.DataSource”
factory=”org.apache.tomcat.jdbc.pool.DataSourceFactory”
username=”ApplicationCORETOM”
password=”ApplicationCORETOM”
driverClassName=”oracle.jdbc.OracleDriver”
url=”jdbc:oracle:thin:@localhost:1521:ORCL”
initialSize=”34″
maxActive=”377″
maxIdle=”233″
minIdle=”89″
timeBetweenEvictionRunsMillis=”34000″
minEvictableIdleTimeMillis=”55000″
validationQuery=”SELECT * FROM USERS”
validationInterval=”34000″
testOnBorrow=”true”
removeAbandoned=”true”
defaultAutoCommit=”true”
removeAbandonedTimeout=”50″ />
<Resource name=”UserDatabase” auth=”Container”
type=”org.apache.catalina.UserDatabase”
description=”User database that can be updated and saved”
factory=”org.apache.catalina.users.MemoryUserDatabaseFactory”
pathname=”conf/tomcat-users.xml” />
</GlobalNamingResources>
Sizing the conection pool :
- initialSize = 34 – the initial number of connections that are created when the pool is started
- maxActive = 377 – the maximum number of active connections that can be allocated from this pool at the same time. This attribute is used to limit the number of connections a pool can have open so that capacity planning can be done on the database side – in my.cnf MySql configuration file max_connections = 610 (maxActive+maxIdle)
- maxIdle = 233 – the maximum number of idle connections that should be kept in the pool at all times. Idle connections are checked periodically (if enabled) and connections that have been idle for longer than minEvictableIdleTimeMillis will be released
- minIdle= 89 – the minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail.
- timeBetweenEvictionRunsMillis = 34000 – the number of milliseconds to sleep between runs of the idle connection validation/cleaner thread. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connections.
- minEvictableIdleTimeMillis = 55000 – the minimum amount of time an object may sit idle in the pool before it is eligible for eviction.
Validate connections:
At first I avoided to configure connection validation, as I thought it would have an impact on performance. But several problems forced me to activate that. With the following configuration, connections are validated, but no more than every 34 seconds:
- testOnBorrow = true – by setting this, the objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. NOTE – for a true value to have any effect, the validationQuery parameter must be set to a non-null string.
- validationInterval = 34000 – used to avoid excess validation, only run validation at most at this frequency – time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The larger the value, the better the performance, but you increase the chance of a stale connection being presented to your application.
- validationQuery= “SELECT * FROM USERS” – Oracle SQL query used to validate connections from the pool before returning them to the caller
Connection leaks:
There are several configuration settings to help detect connection leaks:
- removeAbandoned = true – Flag to remove abandoned connections if they exceed the removeAbandonedTimeout. A connection is considered abandoned and eligible for removal if it has been in use longer than the removeAbandonedTimeout. This way db connections can be recovered from applications that fail to close a connection.
- removeAbandonedTimeout = 54 – timeout in seconds before an abandoned(in use) connection can be removed. The value should be set to the longest running query your applications might have.
- validationQuery= “SELECT * FROM USERS” – Oracle SQL query used to validate connections from the pool before returning them to the caller
The validation/cleaner thread:
- timeBetweenEvictionRunsMillis > 0 AND removeAbandoned=true AND removeAbandonedTimeout > 0 means the pool sweeper is enabled.
- The pool sweeper is the background thread that can test idle connections and resize the pool while the pool is active.
- The sweeper is also responsible for the detection of connection leaks. In this case the number of idle connections can grow beyond maxIdle, but can shrink down to minIdle if the connection has been idle for longer than minEvictableIdleTimeMilis.
6 . Install Oracle/RHEL Java JVM version JDK1.8 :
Apache tomcat required JVM version 1.8 or higher to start Webserver.Download the Java from oracle/RHEL site and install the same in Linux server where Tomcat installed.
JVM Version installed in RHEL :
[oracle@idalcore2 ~]$ java -version
openjdk version “1.8.0_181”
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
[oracle@idalcore2 ~]$
7.Start Apache Tomcat server 9.0.27:
- After setting JAVA_HOME environment variable, you need restart your dos window or shell window to make the settings take effect.
- Then you can start it up use startup.bat or startup.sh command in it’s Catalina bin folder.
- Open a shell window in Linux or a dos window in windows. Type following command to change current directory to your tomcat bin directory.
cd /oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/bin
- Type startup.bat in windows or startup.sh in Linux and click Enter key. Then Java console window popup and displaying the log information generated by Tomcat process.
- When you see the message like “Server startup in 1000 ms” in java console, that means it has been started successfully and is ready to process client request.
[oracle@idalcore2 bin]$ pwd
/oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/bin
[oracle@idalcore2 bin]$
[oracle@idalcore2 bin]$ nohup ./startup.sh >Tomcat.log &
Open the Tomcat console log to check whether the server started successfully.
[oracle@idalcore2 ~]$ cd /oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/logs
[oracle@idalcore2 logs]$
[oracle@idalcore2 logs]$
[oracle@idalcore2 logs]$
[oracle@idalcore2 logs]$ pwd
/oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/logs
[oracle@idalcore2 logs]$ tail -100f catalina.out
22-Oct-2019 10:50:41.579 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
22-Oct-2019 10:50:41.581 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/webapps/manager] has finished in [137] ms
22-Oct-2019 10:50:41.581 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/webapps/examples]
22-Oct-2019 10:50:41.856 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
22-Oct-2019 10:50:41.891 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/webapps/examples] has finished in [310] ms
22-Oct-2019 10:50:41.900 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/webapps/docs]
22-Oct-2019 10:50:41.997 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
22-Oct-2019 10:50:41.999 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/webapps/docs] has finished in [99] ms
22-Oct-2019 10:50:42.002 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [“http-nio-10062”]
22-Oct-2019 10:50:42.012 INFO [main] org.apache.coyote.AbstractProtocol.start Starting
ProtocolHandler [“ajp-nio-8009”]
22-Oct-2019 10:50:42.018 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [16,478] milliseconds
- Put url http://localhost:8080/in Windows (http://172.19.49.250:10062/in Linux – URL for Apache installed in Linux. Change the IP address in case different hostname)in your favorite web browser’s url address input box and click Enter key. Then you will see below page, if not then your Tomcat may not start correctly, you need to review previous steps carefully.
Apache Tomcat/9.0.27 Console :
8.Deploy a Web Application Using the Apache Tomcat:
- To deploy a web application to Apache Tomcat, you can copy a Application application WAR file to the application base directory.
- This operation of course presupposes we know the application base directory.
- We could consult server.xml and look up the Host element to determine the directory name. A more straightforward approach, though, is to use the Tomcat manager web application.
Default Host – Manager element declared in server.xml:
<Host name=”localhost” appBase=”webapps”
unpackWARs=”true” autoDeploy=”true”>
[oracle@idalcore2 ~]$ cd /oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/webapps
[oracle@idalcore2 webapps]$ pwd
/oracle/Tomcat_9.0.27/apache-tomcat-9.0.27/webapps
[oracle@idalcore2 webapps]$
[oracle@idalcore2 webapps]$
[oracle@idalcore2 webapps]$ ls -lrth
-rw-rw-r–. 1 oracle oinstall 145M Oct 18 15:09 Application.war
[oracle@idalcore2 webapps]$
once copied Tomcat will extract the WAR file into the same directory and start to deploying Web application.
[oracle@idalcore2 webapps]$ ls -lrth
-rw-rw-r–. 1 oracle oinstall 145M Oct 18 15:09 Application.war
drwxr-x—. 58 oracle oinstall 4.0K Oct 18 15:09 Application
[oracle@idalcore2 webapps]$
- In a separate tab in your browser, type http://localhost:8080/Application.jsp and submit that address to the browser.
- The web page will be displayed verifying successful deployment: