Kmaiti

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 16 April 2012

How to configure apache-tomcat on linux box?

Posted on 23:10 by Unknown
Environment : RHEL 5.8
Package version : JDk 1.7.0_03
Apache tomcat : 6.0.35

Reference : http://www.puschitz.com/InstallingTomcat.html

JDK setup :

pwd
/jdk1.7.0_03

[root@vm13 jdk1.7.0_03]# export JAVA_HOME=/jdk1.7.0_03
[root@vm13 jdk1.7.0_03]# export PATH=$JAVA_HOME/bin:$PATH
[root@vm13 jdk1.7.0_03]# which java
/jdk1.7.0_03/bin/java
[root@vm13 jdk1.7.0_03]# java -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)
[root@vm13 jdk1.7.0_03]#


Apache Tomcat setup :

[root@vm13 src]# rm -rf /var/spool/mail/root
[root@vm13 src]# groupadd tomcat
[root@vm13 src]# useradd -g tomcat -s /usr/sbin/nologin -m -d /home/tomcat tomcat
[root@vm13 src]# cd /var/lib
[root@vm13 lib]# tar zxvf /usr/local/src/apache-tomcat-6.0.35.tar.gz
[root@vm13 lib]# chown -R tomcat.tomcat /var/lib/apache-tomcat-6.0.35


/var/lib/apache-tomcat-6.0.35/bin/version.sh
Using CATALINA_BASE: /var/lib/apache-tomcat-6.0.35
Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /var/lib/apache-tomcat-6.0.35/temp
Using JRE_HOME: /jdk1.7.0_03
Using CLASSPATH: /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar
Server version: Apache Tomcat/6.0.35
Server built: Nov 28 2011 11:20:06
Server number: 6.0.35.0
OS Name: Linux
OS Version: 2.6.18-308.el5
Architecture: amd64
JVM Version: 1.7.0_03-b04
JVM Vendor: Oracle Corporation


Starting/Stopping Tomcat:

export CATALINA_HOME=/var/lib/apache-tomcat-6.0.35
You have new mail in /var/spool/mail/root
[root@vm13 lib]# export CATALINA_BASE=/var/lib/apache-tomcat-6.0.35
[root@vm13 lib]# su -p -s /bin/sh tomcat $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE: /var/lib/apache-tomcat-6.0.35
Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /var/lib/apache-tomcat-6.0.35/temp
Using JRE_HOME: /jdk1.7.0_03
Using CLASSPATH: /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar
[root@vm13 lib]#

$ps aux |grep java
tomcat 10711 9.4 10.1 463404 51696 pts/1 Sl 18:58 0:02 /jdk1.7.0_03/bin/java -Djava.util.logging.config.file=/var/lib/apache-tomcat-6.0.35/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/var/lib/apache-tomcat-6.0.35/endorsed -classpath /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar -Dcatalina.base=/var/lib/apache-tomcat-6.0.35 -Dcatalina.home=/var/lib/apache-tomcat-6.0.35 -Djava.io.tmpdir=/var/lib/apache-tomcat-6.0.35/temp org.apache.catalina.startup.Bootstrap start
root 10730 0.0 0.1 61232 724 pts/1 R+ 18:58 0:00 grep java
[root@vm13 lib]#


Stopping :

[root@vm13 lib]# su -p -s /bin/sh tomcat $CATALINA_HOME/bin/shutdown.sh
Using CATALINA_BASE: /var/lib/apache-tomcat-6.0.35
Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /var/lib/apache-tomcat-6.0.35/temp
Using JRE_HOME: /jdk1.7.0_03
Using CLASSPATH: /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar
You have new mail in /var/spool/mail/root
[root@vm13 lib]# ps aux |grep java
root 10763 0.0 0.1 61232 724 pts/1 R+ 18:59 0:00 grep java
[root@vm13 lib]#


Switching to Tomcat User Account :

[root@vm13 lib]# su - -s /bin/sh tomcat
-sh-3.2$ id
uid=502(tomcat) gid=503(tomcat) groups=503(tomcat) context=root:system_r:unconfined_t:SystemLow-SystemHigh
-sh-3.2$

Control+D to exit from tomcat shell


Setting Up First Tomcat JVM Instance :

[root@vm13 opt]# mkdir -p /opt/tomcat-instance/sales.example.com
[root@vm13 opt]# cd /opt/tomcat-instance/sales.example.com
[root@vm13 sales.example.com]# cp -a /var/lib/apache-tomcat-6.0.35/conf .
[root@vm13 sales.example.com]# ll
total 8
drwxr-xr-x 3 tomcat tomcat 4096 Apr 17 18:58 conf
[root@vm13 sales.example.com]# less conf/
Catalina/ catalina.properties logging.properties tomcat-users.xml
catalina.policy context.xml server.xml web.xml
[root@vm13 sales.example.com]# less conf/server.xml
[root@vm13 sales.example.com]# mkdir common logs temp server shared webapps work
You have new mail in /var/spool/mail/root
[root@vm13 sales.example.com]# chown -R tomcat.tomcat /opt/tomcat-instance
[root@vm13 sales.example.com]#

Most of the remaining steps are executed as the tomcat user. So make sure you switch from root to tomcat:

# su - -s /bin/sh tomcat
$ id
uid=1001(tomcat) gid=1001(tomcat) groups=1001(tomcat)
$

[root@vm13 sales.example.com]# su - -s /bin/sh tomcat
-sh-3.2$ pwd
/home/tomcat
-sh-3.2$ whoami
tomcat
-sh-3.2$ cat > /opt/tomcat-instance/sales.env << EOF
> export JAVA_HOME=/jdk1.7.0_03
> export PATH=\$JAVA_HOME/bin:\$PATH
> export CATALINA_HOME=/var/lib/apache-tomcat-6.0.35
> export CATALINA_BASE=/opt/tomcat-instance/sales.example.com
> EOF
-sh-3.2$ cat /opt/tomcat-instance/sales.env
export JAVA_HOME=/jdk1.7.0_03
export PATH=$JAVA_HOME/bin:$PATH
export CATALINA_HOME=/var/lib/apache-tomcat-6.0.35
export CATALINA_BASE=/opt/tomcat-instance/sales.example.com
-sh-3.2$

Configuring Tomcat Network Ports :

Since this is the first Tomcat instance that's being created here, the default port numbers can be left unchanged in $CATALINA_BASE/conf/server.xml (/opt/tomcat-instance/sales.example.com/conf/server.xml):



connectionTimeout="20000"
redirectPort="8443" />



Starting First Tomcat Instance :

sh-3.2$ source /opt/tomcat-instance/sales.env
-sh-3.2$ $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE: /opt/tomcat-instance/sales.example.com
Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /opt/tomcat-instance/sales.example.com/temp
Using JRE_HOME: /jdk1.7.0_03
Using CLASSPATH: /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar
-sh-3.2$

I have seen empty page : http://10.65.211.13:8080/

Relaying HTTP Port 80 Connections to Tomcat Port 8080 : that means if someone access http://10.65.211.13/ or http://10.65.211.13:80/, he'll get op of http://10.65.211.13:8080/

[root@vm13 sales.example.com]# iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
[root@vm13 sales.example.com]# iptables -t nat -I OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 8080
[root@vm13 sales.example.com]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080
[root@vm13 sales.example.com]


Remove iptables rules : iptables -t nat -F

Setting Up a Web Application for First Tomcat JVM Instance :

-sh-3.2$ vi $CATALINA_BASE/conf/server.xml :

unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">



And the docBase attribute is set to mysales which stands for the application name within the URL, i.e. "http://10.65.211.13/mysales" or "http://10.65.211.13:8080/mysales".


Home Page for Web Application :

cat > $CATALINA_BASE/webapps/sales/index.html < > > "http://www.w3.org/TR/html4/loose.dtd">
>
>
>
>

Apache Tomcat Sales Home Page

>
>
> EOF
-sh-3.2$
Restarting First Tomcat Instance :

-sh-3.2$ source /opt/tomcat-instance/sales.env
-sh-3.2$ $CATALINA_HOME/bin/shutdown.sh
Using CATALINA_BASE: /opt/tomcat-instance/sales.example.com
Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /opt/tomcat-instance/sales.example.com/temp
Using JRE_HOME: /jdk1.7.0_03
Using CLASSPATH: /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar
-sh-3.2$ $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE: /opt/tomcat-instance/sales.example.com
Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /opt/tomcat-instance/sales.example.com/temp
Using JRE_HOME: /jdk1.7.0_03
Using CLASSPATH: /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar
-sh-3.2$

now access http://10.65.211.13/mysales/ , you'll see "Apache Tomcat Sales Home Page".

Deploying Java Servlet for Web Application in First Tomcat JVM Instance :

1. Setting up Java Servlet Layout :

-sh-3.2$ mkdir -p $CATALINA_BASE/webapps/sales/WEB-INF/classes
JAR Files :
-sh-3.2$ mkdir $CATALINA_BASE/webapps/sales/WEB-INF/lib

Creating a Java Servlet :

vi $CATALINA_BASE/webapps/sales/WEB-INF/classes/Sales.java

-sh-3.2$ cat $CATALINA_BASE/webapps/sales/WEB-INF/classes/Sales.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Sales extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("Sales Page");
out.println("");
out.println("");
out.println("

Executing Sales ...

");
out.println("");
out.println("");
}
}

-sh-3.2$
The following command should now compile the Java servlet without errors:
-sh-3.2$ cd $CATALINA_BASE/webapps/sales/WEB-INF/classes
-sh-3.2$ javac -classpath "$CATALINA_HOME/lib/*" Sales.java
-sh-3.2$ ls
Sales.class Sales.java
-sh-3.2$

Configuring the Java Servlet :

-sh-3.2$ cat $CATALINA_BASE/webapps/sales/WEB-INF/web.xml


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">


servlet_sales
Sales



servlet_sales
/execute





-sh-3.2$

Modify index.html :

-sh-3.2$ cat $CATALINA_BASE/webapps/sales/index.html
"http://www.w3.org/TR/html4/loose.dtd">



Apache Tomcat Sales Home Page

Execute Sales


-sh-3.2$

Testing and Executing the Java Servlet :

-sh-3.2$ source /opt/tomcat-instance/sales.env
-sh-3.2$ $CATALINA_HOME/bin/shutdown.sh
Using CATALINA_BASE: /opt/tomcat-instance/sales.example.com
Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /opt/tomcat-instance/sales.example.com/temp
Using JRE_HOME: /jdk1.7.0_03
Using CLASSPATH: /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar
-sh-3.2$ $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE: /opt/tomcat-instance/sales.example.com
Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /opt/tomcat-instance/sales.example.com/temp
Using JRE_HOME: /jdk1.7.0_03
Using CLASSPATH: /var/lib/apache-tomcat-6.0.35/bin/bootstrap.jar
-sh-3.2$

OP : If you access : http://10.65.211.13/mysales/ , you'll see following :

Apache Tomcat Sales Home Page
Execute Sales

Now click on "Execute Sales", you'll see following :

Executing Sales ...

Disclaimer : I have referred above link and I have successfully setup it. In case you face any problem, please take a look at the link mentioned. I am not responsible for changing anything in above link. Use the commands at your own risk.

Read More
Posted in | No comments
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • unable connect to socket: No route to host (113)
    Guys, This error message usually comes when you try to access remote linux desktop using vncviewer. Please check the firewall in the linux s...
  • NDMP communication failure error
    Guys, Issue : Netbackup server sends alert NDMP communication failure once everyday. But there is no issue to run scheduled backup jobs. Env...
  • what does it mean by "cman expected_votes="1" two_node="1" in cluster.conf ?
    For two node clusters ordinarily, the loss of quorum after one out of two nodes fails will prevent the remaining node from continuing (if bo...
  • How to make bridge over VLAN?
    How to make bridge over VLAN? Bridging over VLAN's : By constructing a bridge between a "normal" and a "VLAN" ethern...
  • How to verify UDP packet communication between two linux system?
    Guys, Today, I had to check UDP packet communication between linux and a windows system. Main purpose of the windows system was to capturing...
  • How to install pdo_mysql module with php on 64 bit linux machine?
    Guys, The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver ...
  • configure: error: C preprocessor "/lib/cpp" fails sanity check + Resolved
    Guys, I got that error messages when I was going to configure any software on the linux server. I was unable to execute easyapache or ./conf...
  • configure: error: could not find library containing RSA_new
    Guys, It seems you have enabled the SSL option during configuring the package. Please either resolve that dependency or disable the SSL opti...
  • Cannot find config.m4 + phpize +Resolved
    Guys, I got the same error messages and sorted out it. Here is the error that I got. ===== root@server [/home/cpeasyapache/src/php-5.2.9/ext...
  • How to redirect output of script to a file(Need to save log in a file and file should be menioned in the script itself?
    Expectation : @subject Steps : 1. Create a bash script. 2. add line : exec > >(tee /var/log/my_logfile.txt) That's it. All output ...

Categories

  • ACL
  • ESX
  • Linux
  • Storage
  • UCS

Blog Archive

  • ►  2013 (5)
    • ►  May (1)
    • ►  April (3)
    • ►  February (1)
  • ▼  2012 (10)
    • ►  July (1)
    • ►  June (1)
    • ▼  April (1)
      • How to configure apache-tomcat on linux box?
    • ►  March (3)
    • ►  February (3)
    • ►  January (1)
  • ►  2011 (86)
    • ►  December (3)
    • ►  November (2)
    • ►  September (19)
    • ►  August (9)
    • ►  July (5)
    • ►  June (9)
    • ►  May (12)
    • ►  April (3)
    • ►  March (4)
    • ►  February (5)
    • ►  January (15)
  • ►  2010 (152)
    • ►  December (9)
    • ►  November (34)
    • ►  October (20)
    • ►  September (14)
    • ►  August (24)
    • ►  July (19)
    • ►  June (3)
    • ►  May (25)
    • ►  April (3)
    • ►  January (1)
Powered by Blogger.