Shashikant shah

Saturday, 19 January 2013

Configuration of tomcat and java on CentOS-6

  Installation of JAVA. 


1.Install rpm.
# rpm -Uvh jdk-7-linux-x64.rpm

2.add at the last line.
# vi /etc/profile

export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

                           OR

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

JAVA_HOME=/usr/java/jdk1.7.0
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME
export PATH
3.Update profile.
# source /etc/profile

4.Check java.
# javac - -version

INSTALL TOMCAT

1.Download links:-

wget http://ftp.riken.jp/net/apache/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.tar.gz

2.Untar apache-tomcat .

# tar zxvf apache-tomcat-7.0.16.tar.gz

3.move to apache-tomcar this location.

# mv apache-tomcat-7.0.16 /usr/tomcat-7

4.Create user for tomcat

# useradd -d /usr/tomcat tomcat

5.Give to owner ship /usr/tomcat

# chown -R tomcat. /usr/tomcat

6.Create Script for tomcat

# vim /etc/rc.d/init.d/tomcat

#!/bin/bash

# Tomcat7: Start/Stop Tomcat 7
#
# chkconfig: - 90 10
# description: Tomcat is a Java application Server.

. /etc/init.d/functions
. /etc/sysconfig/network

CATALINA_HOME=/usr/tomcat-7
TOMCAT_USER=tomcat
LOCKFILE=/var/lock/subsys/tomcat

RETVAL=0
start(){
   echo "Starting Tomcat: "
   su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"
   RETVAL=$?
   echo
   [ $RETVAL -eq 0 ] && touch $LOCKFILE
   return $RETVAL
}

stop(){
   echo "Shutting down Tomcat: "
   $CATALINA_HOME/bin/shutdown.sh
   RETVAL=$?
   echo
   [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
   return $RETVAL
}

case "$1" in
   start)
      start
      ;;
   stop)
      stop
      ;;
   restart)
      stop
      start
      ;;
   status)
      status tomcat
      ;;
   *)
      echo $"Usage: $0 {start|stop|restart|status}"
      exit 1
      ;;
esac
exit $?
# save

# chmod 755 /etc/rc.d/init.d/tomcat

# /etc/rc.d/init.d/tomcat start
(output)

Starting Tomcat:
Using CATALINA_BASE:/usr/tomcat
Using CATALINA_HOME:/usr/tomcat
Using CATALINA_TMPDIR:/usr/tomcat/temp
Using JRE_HOME:/usr/java/default
Using CLASSPATH:/usr/tomcat/bin/bootstrap.jar:/usr/tomcat/bin/tomcat-juli.jar

# chkconf - -add tomcat

# chkconf - - level 2345 tomcat on

# check tomcat

URL:- shashi.example.com:8080


@@@@ How to change port 8080 @@@@

# cd /usr/tomcat-7/conf/

# vim server.xml

find following similar statement

<!-- Define a non-SSL HTTP/1.1 Connector on port 8180 -->
 <Connector port="8080" maxHttpHeaderSize="8192"
          maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
          enableLookups="false" redirectPort="8443" acceptCount="100"
          connectionTimeout="20000" disableUploadTimeout="true" />       

                                    OR

    
    <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

About Tomcat’s server.xml file cites it’s runs on port 8080. Change the Connector port=”8080″ port to any other port number.
Example:-

<Connector port="8181" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

Above statement instruct Tomcat server runs on port 8181.

URL:-shashi.example.com:8181











You have to run two tomcat :-

# cd /usr/tomcat-1/conf
# vim server.xml
 change the port number and shutdown port number.

#cd /usr/local/tomcat-2/conf
change the port number and shutdown port number.
  


1 comment:

  1. Hi,
    Thanks for the tuto.
    I want to ask if i cant change the url
    from : domain.com:8181
    to : domain.com(they also work with 8181)

    and if also when i run a application war
    from : domain.com:8181/name_application
    to : domain.com (they run by default with 8181 also and name_application)
    ?!
    thanks

    ReplyDelete