Techiehints contrinues to cover interesting topic, now on Server instances using tomcat webservers. Hope you will benefit of reading this post.
Here is the one of the technique explored to run 2 different instances in tomcat.
Lets download latest stable tomcat latest version ( as of today 8.5.24 )
1. Download tomcat
wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz tar -xzvf apache-tomcat-8.5.24.tar.gz mv apache-tomcat-8.5.24 tomcat/adminserver
2. Create instances copy
copy unzipped file into instance1 & instance2
cp -R tomcat/adminserver tomcat/instance1 cp -R tomcat/adminserver tomcat/instance2
3. Configure instances
3-a)Clean up binary files in instances
#remove all existing executable files in bin folder rm instance1/bin/* rm instance2/bin/* #remove lib files from the instances rm -r instance1/lib rm -r instance2/lib # Verify the instance(s) directory should list as below ll instance1/ | grep "d" # should display only these in both instances created. bin conf logs temp webapps work
3-b) set jvm parameters in each of the instances
vi instance1/bin/setenv.sh export CATALINA_OPTS="$CATALINA_OPTS -Xms256m" export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m" export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=512m"
vi instance2/bin/setenv.sh export CATALINA_OPTS="$CATALINA_OPTS -Xms256m" export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m" export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=512m"
3-c) Configure the port numbers uniquely each instance.
Ensure following ports are uniquely used in both instance
1. Http Connector Port <Connector port="****" protocol="HTTP/1.1" ... /> 2. Ajp Connector Port <Connector port="****" protocol="AJP/1.3" ... /> 3. Shutdown Server Port <Server port="8006" shutdown="SHUTDOWN"> 4. Redirect Port <... protocol="HTTP/1.1" redirectPort="****" /> <... protocol="AJP/1.3" redirectPort="****" />
Example:
Instance 1 settings: vi instance1/conf/server.xml Edit below lines <Server port="8006" shutdown="SHUTDOWN"> ..... <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8143" /> ..... <Connector port="8109" protocol="AJP/1.3" redirectPort="8143" /> Instance 2 settings: vi instance2/conf/server.xml Edit below lines <Server port="8007" shutdown="SHUTDOWN"> .... <Connector port="8082" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8243" /> .... <Connector port="8209" protocol="AJP/1.3" redirectPort="8243" />
after the unique port configuration step port numbers for both the instances are uniquely maintained
4. Configure Admin Server
4-a) clean up conf, logs, temp, webapps, work directory from the admin sever.
rm -r adminserver/conf rm -r adminserver/logs rm -r adminserver/temp rm -r adminserver/webapps rm -r adminserver/work
4-b) Create Startup & Shutdown Controller in admin server for the instances.
#Create new folder in admin server for controller mkdir adminserver/controller
startup.sh
app_instance=$1; BASE_TOMCAT=/location-to-tomcat-parent-directory export CATALINA_HOME=$BASE_TOMCAT/adminserver export CATALINA_BASE=$BASE_TOMCAT/$app_instance $CATALINA_HOME/bin/startup.sh
app_instance=$1; BASE_TOMCAT=/location-to-tomcat-parent-directory export CATALINA_HOME=$BASE_TOMCAT/adminserver export CATALINA_BASE=$BASE_TOMCAT/$app_instance $CATALINA_HOME/bin/shutdown.sh
5. Run the each instance using script
sh adminserver/controller/startup.sh instance1 sh adminserver/controller/startup.sh instance2
Access url: <Ip-Addr>:8081 <Ip-Addr>:8082
You can deploy the application in both the servers now.
6. Similarly the each instance can be stopped as below
sh adminserver/controller/shutdown.sh instance1 sh adminserver/controller/shutdown.sh instance2
Thats All, You can configure the lb urls accordingly for the application access using common url mostly called as LB ( Load Balancing URL ).
Hope you got the benefit of reading post, Thanks for referring Techiehints.

Leave a comment