How to Install Tomcat 9 With Java 9 On CentOS/RHEL 6.X



Install Tomcat 9 With Java 9 On Centos/RHEL 6

Step 1: Stop the IPTables and Selinux, and Update the Date Time on the Server :

# service iptables stop
# chkconfig iptables off

# vi /etc/sysconfig/selinux

SELINUX=disabled ###(Change enabled to disabled)

--- save & quit (:wq) ---

# service ntpd restart
# ntpdate pool.ntp.org
# chkconfig ntpd on
# init 6

Step 2: Download & Install Java 9 :

# cd /opt
# wget http://download.java.net/java/jdk9/archive/104/binaries/jdk-9-ea+104_linux-x64_bin.tar.gz
# tar -zxvf jdk-9-ea+104_linux-x64_bin.tar.gz
# cd jdk-9/
# alternatives --install /usr/bin/java java /opt/jdk-9/bin/java 2
# alternatives --config java

There may Be more that 1 programs which provide 'java'. Select the version Which is downloaded.

Selection    Command
-----------------------------------------------
*  1           /opt/jdk1.7.0_71/bin/java
 + 2           /opt/jdk1.8.0_45/bin/java
   3           /opt/jdk1.8.0_66/bin/java
   4           /opt/jdk-9/bin/java
 
Enter to keep the current selection[+], or type selection number: 4

# alternatives --install /usr/bin/jar jar /opt/jdk-9/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk-9/bin/javac 2
# alternatives --set jar /opt/jdk-9/bin/jar
# alternatives --set javac /opt/jdk-9/bin/javac

# vi /etc/profile.d/java.sh

#!/bin/bash
JAVA_HOME=/opt/jdk-9/
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
export CLASSPATH=.

--- Save & Quit (:wq) ---

# chmod +x /etc/profile.d/java.sh
# source /etc/profile.d/java.sh
# export JAVA_HOME=/opt/jdk-9/
# export PATH=PATH:/opt/jdk-9/bin

* Check the installed Java Version:

# java -version

java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+104-2016-02-03-214959.javare.4385.nc)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+104-2016-02-03-214959.javare.4385.nc, mixed mode)

Step 3: Download and Install Tomcat 9 :

# cd /opt
# wget http://www.us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M3/bin/apache-tomcat-9.0.0.M3.tar.gz
# tar -zxvf apache-tomcat-9.0.0.M3.tar.gz
# mv apache-tomcat-9.0.0.M3 /usr/local/tomcat9

** Create a init script for run the Tomcat as a service:

# vi /etc/init.d/tomcat

#!/bin/bash
# description: Tomcat Start Stop Restart-SOM
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/opt/jdk-9
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/local/tomcat9

case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0

--- save & quit (:wq) ---

# chmod 755 /etc/init.d/tomcat

# vi /usr/local/tomcat9/conf/tomcat-users.xml

### Add these lines in between "<tomcat-users>" Tag. Change the Password and Username.

<role rolename="manager-gui" />
<user username="manager" password="redhat" roles="manager-gui" />

<role rolename="admin-gui" />
<user username="admin" password="redhat" roles="manager-gui,admin-gui" />

--- save & quit (:wq) ---

# service tomcat restart
# chkconfig tomcat on

*** Check on Browser: http://<IP_Address>:8080
Click on Manager App and Login with Manager Creds
Click on Host manager and Login with Admin Creds

Step 4: Configure Virtual Host on Tomcat 9 :

N.B: There is some problem with Apache Solr and Railo with Java 9. Seems Java 9 doesn't Work properly for Apache Solr & Railo. So for now Here doing with a sample war file Virtual Hosting. Virtual Host Name test.com (For Example).

# vi /etc/hosts

### add the virtual to hosts file

192.x.x.x test.com

--- save & quit (:wq) ---

## Download sample.war file

# cd /opt
# wget https://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/sample.war
# cd /usr/local/tomcat9
# cp -r webapps/ test.com
# mv test.com/ROOT test.com/ROOT.bak
# cp /opt/sample.war /usr/local/tomcat/test.com/ROOT.war

### Configure the server.xml file for virtual Hosting

# vi /usr/local/tomcat9/conf/server.xml

### add this line

<Host name="test.com"  appBase="test.com" unpackWARs="true" autoDeploy="true"/>

--- save & quit (:wq) ---

# service tomcat restart

*** Check on Browser: http://test.com:8080

Step 5: Apache Reverse Proxy for Tomcat Virtual Hosts :

# yum -y install httpd httpd-devel

# vi /etc/httpd/conf.d/test.com.conf

### Add these Lines

<VirtualHost *:80>
    ServerAdmin email-address
    ServerName test.com
    ServerAlias www.test.com


    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
       Order allow,deny
       Allow from all
    </Proxy>


    ProxyPass / http://test.com:8080/
    ProxyPassReverse / http://test.com:8080/


    ErrorLog /logs/test.com-error_log
    CustomLog /logs/test.com-access_log common

</VirtualHost>

--- save & quit (:wq) ---

# mkdir /logs
# service tomcat restart
# service httpd restart

*** Check on Browser: http://test.com

Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog.