Total Pageviews
Wednesday, 21 May 2014
Tuesday, 20 May 2014
How to run multiple Tomcat instances on single Linux server?
If you are a developer then you will find yourself in a situation where you have to run multiple instances of Tomcat server on a single machine. The information available on the internet may not be precise and hence I have listed down the step-by-step guide to achieve it.
The configuration used for the illustration is Linux CentOS-6.X server.
- /bin : This directory contains the startup and shutdown scripts for both Windows and Linux.
- /conf : This directory contains the main configuration files for Tomcat. The two most important are the server.xml and the global web.xml .
- /server : This directory contains the Tomcat Java Archive files.
- /lib : This directory contains Java Archive files that Tomcat is dependent upon.
- /logs : This directory contains Tomcat’s log files.
- /src : This directory contains the source code used by the Tomcat server. Once Tomcat is released, it will probably contain interfaces and abstract classes only.
- /webapps : All web applications are deployed in this directory; it contains the WAR file.
- /work : This is the directory in which Tomcat will place all servlets that are generated from JSPs. If you want to see exactly how a particular JSP is interpreted, look in this directory.
Tomcat server ports
Having a good understanding of tomcat ports is essential to manage the multiple instances of the same server installation. These ports are used by tomcat for start-up, deployment and shut-down operations. The detail of each port is as:
- Connector Port : This is the port where Apache Tomcat listen for the HTTP requests.
- Shutdown Port : This port is used when we try to shutdown the Apache Tomcat Server.
- AJP (Apache JServ Protocol) Connector Port : The Apache JServ Protocol (AJP) is a binary protocol that can conduct inbound requests from a web server through to an application server that sits behind the web server.
- Redirect Port : Any redirection happening inside Apache Tomcat will happen through this port. In Apache TOMCAT there are two instance where redirectPort is mentioned. First one is for the Apache TOMCAT server and other one is for the AJP port.
- Step 1:
Download Tomcat from http://tomcat.apache.org/download-60.cgi - Step 2:
Extract it into two different folders, let’s say/opt/tomcat1
and/opt/tomcat2
- Step 3:
Keep tomcat1 instance as is and change following things in tomcat2 instance
Edit/opt/tomcat2/conf/server.xml
and change port number<server port="8105" shutdown="SHUTDOWN">
.....
<Connector port="8181" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
.....
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" /> - Step 4:
Create following two scripts to run Tomcat as a service- Create
/etc/init.d/tomcat1
with following instructions
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/lib/jvm/jre-openjdk
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/opt/tomcat1case $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 - Create
/etc/init.d/tomcat2
with following instructions
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/lib/jvm/jre-openjdk
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/opt/tomcat2case $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
- Create
- Step 5:
Start/Stop Tomcat serviceService tomcat1 start/stop/restart
Service tomcat2 start/stop/restart - Step 6:
Add Tomcat service in startupchkconfig tomcat1 on
chkconfig tomcat2 on
This will enable you to use two instances of Tomcat on a single machine.
Monday, 19 May 2014
To Emulate network traffic we will be using this command
To Emulate network traffic we will be using this command
tc qdisc change dev eth0 root netem loss 0%
if above command output will show
RTNETLINK answers:
No such file or directory
Then
we have to use this command to add the same .
tc qdisc add
dev eth0 root netem loss 0%.
Examples:
[root@revplus2 ~]# tc qdisc change dev eth0 root netem
loss 0%
[root@revplus2 ~]# ping 172.19.1.1
PING 172.19.1.1 (172.19.1.1) 56(84) bytes of data.
64 bytes from 172.19.1.1: icmp_seq=1 ttl=255 time=2.81
ms
64 bytes from 172.19.1.1: icmp_seq=2 ttl=255 time=0.586
ms
64 bytes from 172.19.1.1: icmp_seq=3 ttl=255 time=1.35
ms
^C
--- 172.19.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2990ms
rtt min/avg/max/mdev = 0.586/1.583/2.810/0.922 ms
[root@revplus2 ~]#
How to implement ip forwarding in Linux
IP forwarding is a concept to make
Linux machine to send data from one network to other, this is same as a router(A router is a device to send packets from one
point to other point depending on the packet destination/rules etc).
Why
we need IP forwarding on a Linux machine?
Ans
: We need IP forwarding on a Linux machine because to
make it as a router or proxy server to share one internet connection to many
client machines.
Let
me explain how this will work with small example.
You have 2 machines which are in
different network(PC1
in 10.0.0.0/255.0.0.0network and PC2 in 192.168.0.0/255.255.255.0 network) and
connected with a Linux machine(which is having two network interfaces). The IP
address is as follows..
PC1:
192.168.0.1/255.255.255.0 default gateway:192.168.0.2
PC2:
10.0.0.1/255.0.0.0 default gateway:10.0.0.2
Linuxbox
eth0 : 192.168.0.2/255.255.255.0
eth1
: 10.0.0.2/255.0.0.0
and Linuxbox is having two LAN cards
which are connected to both the machines as shown below
So
do you think PC1 is capable of communicating with PC2?
Ans : The answer to this question is No.
Ans : The answer to this question is No.
How
to make PC1 to communicate with PC2?
Ans : The answer is enable ip forwarding on Linux machine. Some times this is known as bridging two networks.
Ans : The answer is enable ip forwarding on Linux machine. Some times this is known as bridging two networks.
To make IP forwarding we have to edit /etc/sysctl.conf as shown below. Opensysctl.conf and
change the value of “net.ipv4.ip_forward” from 0 to 1 and save the file
#vi
/etc/sysctl.conf
net.ipv4.ip_forward
= 0
to
net.ipv4.ip_forward
= 1
Once its done still you are not able
to ping from PC1 to PC2. We have to restart the linuxbox to take this update to
kernel.
Why
to restart if it's a production machine try below command to make your linuxbox
aware of IP forwarding without a restart.
echo
1 > /proc/sys/net/ipv4/ip_forward
Now try to ping from PC1 to PC2 which
will ping successfully.
Subscribe to:
Posts (Atom)