Search This Blog

Wednesday 3 February 2021

Tomcat 9 Installation and configuration on Linux (CentOS)

 Step 1) Download Java 8 from the following link

https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html#license-lightbox

Step 2) Extract JDK 8 and create a symlink

[osboxes@tomcathost products]$ mkdir -p /home/osboxes/products/jdk/

[osboxes@tomcathost ~]$ tar -zxvf jdk-8u281-linux-x64.tar.gz -C /home/osboxes/products/jdk

[osboxes@tomcathost ~]$ cd /home/osboxes/products/jdk

[osboxes@tomcathost jdk]$ ln -s jdk1.8.0_281 jdk_latest
[osboxes@tomcathost jdk]$ pwd
/home/osboxes/products/jdk
[osboxes@tomcathost jdk]$ ls -rtl
total 0
drwxr-xr-x. 8 osboxes osboxes 273 Dec  9 07:50 jdk1.8.0_281
lrwxrwxrwx. 1 osboxes osboxes  12 Feb  2 22:52 jdk_latest -> jdk1.8.0_281

Step 3) Setup JAVA_HOME 
 
[osboxes@tomcathost jdk]$ vi ~/.bash_profile

## add the following lines at the end of the file.
export JAVA_HOME=/home/osboxes/products/jdk/jdk_latest
export PATH=$JAVA_HOME/bin:$PATH

[osboxes@tomcathost jdk]$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
export JAVA_HOME=/home/osboxes/products/jdk/jdk_latest
export PATH=$JAVA_HOME/bin:$PATH


Step 4) Execute .bash_profile and verify the java version

[osboxes@tomcathost jdk]$ . ~/.bash_profile
[osboxes@tomcathost jdk]$ java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

Step 5) Download and extract the tomcat binaries.

[osboxes@tomcathost ~]$ wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.tar.gz
--2021-02-02 23:04:10--  https://downloads.apache.org/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 2a01:4f8:10a:201a::2, 88.99.95.219
Connecting to downloads.apache.org (downloads.apache.org)|2a01:4f8:10a:201a::2|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11442169 (11M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.41.tar.gz’

apache-tomcat-9.0.41.tar.gz             100%[============================================================================>]  10.91M  9.08MB/s    in 1.2s

2021-02-02 23:04:12 (9.08 MB/s) - ‘apache-tomcat-9.0.41.tar.gz’ saved [11442169/11442169]

[osboxes@tomcathost ~]$ mkdir -p /home/osboxes/products/tomcat

[osboxes@tomcathost ~]$ tar -zxvf apache-tomcat-9.0.41.tar.gz -C /home/osboxes/products/tomcat

Step 6) Create a symlink to the binary location for easy upgrades.

[osboxes@tomcathost tomcat]$ cd /home/osboxes/products/tomcat/; ln -s apache-tomcat-9.0.41 tomcat90

Step 7 ) Create a New tomcat instance 

[osboxes@tomcathost ~]$ mkdir -p /home/osboxes/instances/poc-tomcat-instance

[osboxes@tomcathost ~]$ cp -r /home/osboxes/products/tomcat/tomcat90/* /home/osboxes/instances/poc-tomcat-instance/

[osboxes@tomcathost ~]$ cd /home/osboxes/instances/poc-tomcat-instance/
[osboxes@tomcathost poc-tomcat-instance]$ ls -rlt
total 128
-rw-r-----. 1 osboxes osboxes 18982 Feb  2 23:19 BUILDING.txt
drwxr-x---. 2 osboxes osboxes  4096 Feb  2 23:19 bin
-rw-r-----. 1 osboxes osboxes  5409 Feb  2 23:19 CONTRIBUTING.md
drwx------. 2 osboxes osboxes   238 Feb  2 23:19 conf
-rw-r-----. 1 osboxes osboxes 57092 Feb  2 23:19 LICENSE
drwxr-x---. 2 osboxes osboxes  4096 Feb  2 23:19 lib
drwxr-x---. 2 osboxes osboxes    30 Feb  2 23:19 temp
-rw-r-----. 1 osboxes osboxes 16507 Feb  2 23:19 RUNNING.txt
-rw-r-----. 1 osboxes osboxes  6898 Feb  2 23:19 RELEASE-NOTES
-rw-r-----. 1 osboxes osboxes  3257 Feb  2 23:19 README.md
-rw-r-----. 1 osboxes osboxes  2333 Feb  2 23:19 NOTICE
drwxr-x---. 2 osboxes osboxes     6 Feb  2 23:19 logs
drwxr-x---. 7 osboxes osboxes    81 Feb  2 23:19 webapps
drwxr-x---. 2 osboxes osboxes     6 Feb  2 23:19 work

Step 8) create a log symlink to a different directory location

[osboxes@tomcathost poc-tomcat-instance]$ pwd
/home/osboxes/instances/poc-tomcat-instance
[osboxes@tomcathost poc-tomcat-instance]$ mkdir -p /home/osboxes/logs/poc-tomcat-instance; rm -rf logs; ln -s /home/osboxes/logs/poc-tomcat-instance logs


Step 9) Create setenv.sh properties for customization

[osboxes@tomcathost poc-tomcat-instance]$ cd bin/
[osboxes@tomcathost bin]$ pwd
/home/osboxes/instances/poc-tomcat-instance/bin

[osboxes@tomcathost bin]$ cat>setenv.sh

JAVA_HOME=/home/osboxes/products/jdk/jdk_latest
JRE_HOME=$JAVA_HOME/jre
CATALINA_HOME=/home/osboxes/products/tomcat/tomcat90
CATALINA_BASE=/home/osboxes/instances/poc-tomcat-instance
LOG_DIR=$CATALINA_BASE/logs

JAVA_OPTS="${JAVA_OPTS} -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
        -XX:+HeapDumpOnOutOfMemoryError -XX:+UseG1GC -Xloggc:/home/osboxes/logs/poc-tomcat-instance/GC.log"
LD_LIBRARY_PATH=$CATALINA_HOME/lib:$LD_LIBRARY_PATH:

export PATH=$JAVA_HOME/bin/$PATH

##JVM PID File
CATALINA_PID=/home/osboxes/logs/poc-tomcat-instance/jvm.pid

##JVM Memory Settings
JAVA_OPTS="$JAVA_OPTS -server -d64 -Xms1024m -Xmx1024m"

JAVA_OPTS="$JAVA_OPTS -Djava.library.path=$CATALINA_HOME/lib"

## umask settings for log permissions
umask 027



[osboxes@tomcathost bin]$ chmod u+x setenv.sh

Step 10) Start the tomcat instance

[osboxes@tomcathost bin]$ pwd
/home/osboxes/instances/poc-tomcat-instance/bin
[osboxes@tomcathost bin]$ ./startup.sh
Using CATALINA_BASE:   /home/osboxes/instances/poc-tomcat-instance
Using CATALINA_HOME:   /home/osboxes/products/tomcat/tomcat90
Using CATALINA_TMPDIR: /home/osboxes/instances/poc-tomcat-instance/temp
Using JRE_HOME:        /home/osboxes/products/jdk/jdk_latest/jre
Using CLASSPATH:       /home/osboxes/products/tomcat/tomcat90/bin/bootstrap.jar:/home/osboxes/instances/poc-tomcat-instance/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Using CATALINA_PID:    /home/osboxes/logs/poc-tomcat-instance/jvm.pid
Tomcat started.

Step 10) Verify the tomcat process status

[osboxes@tomcathost bin]$ ps -ef | grep java
osboxes     7351       1 54 23:52 pts/0    00:00:05 /home/osboxes/products/jdk/jdk_latest/jre/bin/java -Djava.util.logging.config.file=/home/osboxes/instances/poc-tomcat-instance/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParNewGC -Xloggc:/home/osboxes/logs/poc-tomcat-instance/GC.log -server -d64 -Xms1024m -Xmx1024m -Djava.library.path=/home/osboxes/products/tomcat/tomcat90/lib -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /home/osboxes/products/tomcat/tomcat90/bin/bootstrap.jar:/home/osboxes/instances/poc-tomcat-instance/bin/tomcat-juli.jar -Dcatalina.base=/home/osboxes/instances/poc-tomcat-instance -Dcatalina.home=/home/osboxes/products/tomcat/tomcat90 -Djava.io.tmpdir=/home/osboxes/instances/poc-tomcat-instance/temp org.apache.catalina.startup.Bootstrap start
osboxes     7389    1931  0 23:52 pts/0    00:00:00 grep --color=auto java


[osboxes@tomcathost bin]$ curl -Ik http://localhost:8080
HTTP/1.1 200
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 03 Feb 2021 04:54:42 GMT

Step 11) Verify tomcat logs and make sure there are no errors.

[osboxes@tomcathost bin]$ cat /home/osboxes/logs/poc-tomcat-instance/catalina.out

03-Feb-2021 00:16:31.311 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/9.0.41
03-Feb-2021 00:16:31.315 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Dec 3 2020 11:43:00 UTC
03-Feb-2021 00:16:31.315 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.41.0
03-Feb-2021 00:16:31.315 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
03-Feb-2021 00:16:31.315 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.18.0-193.el8.x86_64
03-Feb-2021 00:16:31.315 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
03-Feb-2021 00:16:31.316 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /home/osboxes/products/jdk/jdk1.8.0_281/jre
03-Feb-2021 00:16:31.316 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_281-b09
03-Feb-2021 00:16:31.316 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
03-Feb-2021 00:16:31.316 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /home/osboxes/instances/poc-tomcat-instance
03-Feb-2021 00:16:31.316 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /home/osboxes/products/tomcat/apache-tomcat-9.0.41
03-Feb-2021 00:16:31.334 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/home/osboxes/instances/poc-tomcat-instance/conf/logging.properties
03-Feb-2021 00:16:31.334 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
03-Feb-2021 00:16:31.334 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -verbose:gc
03-Feb-2021 00:16:31.335 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+PrintGCDetails
03-Feb-2021 00:16:31.335 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+PrintGCTimeStamps
03-Feb-2021 00:16:31.335 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+HeapDumpOnOutOfMemoryError
03-Feb-2021 00:16:31.335 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+UseG1GC
03-Feb-2021 00:16:31.335 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xloggc:/home/osboxes/logs/poc-tomcat-instance/GC.log
03-Feb-2021 00:16:31.336 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms1024m
03-Feb-2021 00:16:31.336 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx1024m
03-Feb-2021 00:16:31.336 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.library.path=/home/osboxes/products/tomcat/tomcat90/lib
03-Feb-2021 00:16:31.336 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
03-Feb-2021 00:16:31.336 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
03-Feb-2021 00:16:31.337 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
03-Feb-2021 00:16:31.337 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
03-Feb-2021 00:16:31.337 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/home/osboxes/instances/poc-tomcat-instance
03-Feb-2021 00:16:31.337 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/home/osboxes/products/tomcat/tomcat90
03-Feb-2021 00:16:31.337 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/home/osboxes/instances/poc-tomcat-instance/temp
03-Feb-2021 00:16:31.340 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/home/osboxes/products/tomcat/tomcat90/lib]
03-Feb-2021 00:16:33.282 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
03-Feb-2021 00:16:33.387 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [2809] milliseconds
03-Feb-2021 00:16:33.504 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
03-Feb-2021 00:16:33.505 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.41]
03-Feb-2021 00:16:33.559 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/docs]
03-Feb-2021 00:16:34.714 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/docs] has finished in [1,154] ms
03-Feb-2021 00:16:34.715 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/examples]
03-Feb-2021 00:16:35.629 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/examples] has finished in [913] ms
03-Feb-2021 00:16:35.629 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/host-manager]
03-Feb-2021 00:16:35.732 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/host-manager] has finished in [103] ms
03-Feb-2021 00:16:35.733 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/ROOT]
03-Feb-2021 00:16:35.803 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/ROOT] has finished in [71] ms
03-Feb-2021 00:16:35.803 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/manager]
03-Feb-2021 00:16:35.884 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/osboxes/instances/poc-tomcat-instance/webapps/manager] has finished in [81] ms
03-Feb-2021 00:16:35.911 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
03-Feb-2021 00:16:36.046 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [2643] milliseconds

No comments: