Showing posts with label Tomcat Setup. Show all posts
Showing posts with label Tomcat Setup. Show all posts

Wednesday, June 9, 2010

Apcache-Tomcat integration

Bellow are the steps for Apcache-Tomcat integration :
An AJP Connector is used for integration of Tomcat with Apache. The AJP connector will provide faster performance than proxied HTTP. AJP clustering is the most efficient from Tomcat perspective.
The native connectors supported with this Tomcat release are:
o JK Connector 1.2.x with any of the supported servers.

Configuring Tomcat
o Add the following Connector tag in the $CATALINAHOME/conf/server.xml file.


Configuring Apache
o Define the following properties in the $APACHE_HOME/conf/workers.properties file.
worker.list=ServicesPortal
worker.ServicesPortal.port=8009
worker.ServicesPortal.host=
worker.ServicesPortal.socket_keepalive=600000
worker.ServicesPortal.type=ajp13

o Add the following directives in “$APACHE_HOME/conf/httpd.conf.proxy” to configure mod_jk connector
LoadModule jk_module  libexec/mod_jk.so
AddModule mod_jk.c
JkWorkersFile $APACHE_HOME/conf/workers.properties
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

o Add the following directive in “$APACHE_HOME/conf/httpd.conf.proxy” to re-direct all the requests for Services Portal to Tomcat worker called ServicesPortal
JkMount /ServicesPortal/* ServicesPortal

o Add the following rewrite rule in $APACHE_HOME/conf/httpd.conf.proxy file.
RewriteRule ^/ServicesPortal/.* - [L,PT]

o Add the following directive in “$APACHE_HOME/conf/httpd.conf.proxy” to provide RSA authentication for Insite customer


                   AuthType      "SecurID"
                       require  valid-user


Tomcat installation on Linux

Following are the steps related to tomcat installation on Linux box :

Note:

JAVA must be installed before installing tomcat and JAVA_HOME must be setup.

Downloads :

Install Tomcat on linux machine  (Refer this link for JAVA and Tomcat installation : http://www.meritonlinesystems.com/docs/apache_tomcat_redhat.html)
download java from : http://java.sun.com/javase/downloads/index_jdk5.jsp

Download the latest release binary build from http://www.apache.org/dist/jakarta/tomcat-5/. Since Tomcat runs directly on top of a standard JDK
I chose the gnu zipped tar file (jakarta-tomcat-5.0.28.tar.gz).

Steps :

1.Unzip Tomcat by issuing the following command from your download directory: (Currently we have jakarta-tomcat-5.0.28.tar.gz inside /usr/local directory)
tar xvzf jakarta-tomcat-5.0.28.tar.gz

2.The directory where Tomcat is installed is referred to as CATALINA_HOME in the Tomcat documentation.
In this installation CATALINA_HOME=/usr/local/jakarta-tomcat-5.0.28.

add CATALINA_HOME=/usr/local/jakarta-tomcat-5.0.28 in /etc/profile file

it will look like

/******* /etc/profile *************/
 CATALINA_HOME=/usr/local/jakarta-tomcat-5.0.28
/*******************************/



Optional : following are the optional steps

1.I recommend setting up a symbolic link to point to your current Tomcat version. This will save you from having to make changes to startup and shutdown scripts each time
you upgrade Tomcat. It also allows you to keep several versions of Tomcat on your system and easily switch amongst them.
Here is the command I issued from inside /usr/local to create a symbolic link called /usr/local/jakarta-tomcat that points
to /usr/local/jakarta-tomcat-5.0.28:

ln -s jakarta-tomcat-5.0.28 jakarta-tomcat

2.Change the group and owner of the /usr/local/jakarta-tomcat and /usr/local/jakarta-tomcat-5.0.28 directories to tomcat:

chown tomcat.tomcat /usr/local/jakarta-tomcat
chown -R tomcat.tomcat /usr/local/jakarta-tomcat-5.0.28

Setting Up SSL on Tomcat

Setting Up SSL on Tomcat


Step 1. Generating the KeyStore file

i) Go to bin directory of jdk
cd %JAVA_HOME%/bin on Windows
cd $JAVA_HOME/bin on Linuxkeytool -genkey -alias techtracer -keypass ttadmin -keystore techtracer.bin -storepass ttadmin

ii)execute following command
keytool -genkey -alias -keypass -keystore -storepass

please note that the values in angle  brackets i.e. inside <> can be changed as per ur choice.
but make sure keypass and storepass passwords should be the same.
The .bin file is actually your keystore file

When you enter it will ask you some questions.Look below for a reference as to what to answer for the questions.

What is your first and last name?
[Unknown]: yogita Sananse
What is the name of your organizational unit?
[Unknown]: home
What is the name of your organization?
[Unknown]: mycert
What is the name of your City or Locality?
[Unknown]: pune
What is the name of your State or Province?
[Unknown]: maharashtra
What is the two-letter country code for this unit?
[Unknown]: IN
Is CN=nitin pai, OU=home, O=techtracer, L=mumbai, ST=maharashtra, C=IN correct?
[no]: yes

The command would then conclude. It would make a .bin file with the name you had provided inside the bin directory itself.
In this case it is mycert.bin which will located in

C:\Program Files\Java\jdk1.6.0_02\bin\
Note : if you do not find it in bin directory please check c:\Documents and Settings\yogita.sananse\ folder it may be created here

iii) Put the .bin file in the webapps directory of Tomcat.
This is required to avoid the need to give an absolute path of the file in the next step.


Step 2.Configuring Tomcat for using the Keystore file

i) Modify server.xml :
Open the file server.xml which can be found at: /conf/server.xml

Now you have to modify it. Find the Connector element which has port=”8443″ and uncomment it if already not done. Add two lines.
last two lines in bellow tag are newly added ones.

maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="true" disableUploadTimeout="true"
acceptCount="100″ debug=”0″ scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="../webapps/techtracer.bin"
keystorePass="ttadmin" />


Now all you have to do is start your server and check the working of SSL by pointing your browser to the URL to:

https://localhost:8443/
Note : Now that you have your tomcat running in the SSL mode you are ready to deploy an application to test its working. You must note that still your tomcat can run in normal mode too at the same time i.e on port 8080 with http. So it is but obvious that any application deployed to the server will be running on http and https at the same time. This is something that we don’t want. We want our application to run only in the secured mode.
Step 3 : Configuring your web application to work with SSL

Modify web.xml of your application which you want to make https enabled only and want to disable http access for it .
(In order to do this for our test, take any application which has already been deployed successfully in Tomcat and first access it through http and https to see if it works fine.)

If yes, then open the web.xml of that application and just add this XML fragment before web-app ends i.e 



securedapp
/*


CONFIDENTIAL

The term CONFIDENTIAL is the term which tells the server to make the application work on SSL. If you want to turn the SSL mode for this application off then just turn don’t delete the fragment. Just put the value as NONE instead ofCONFIDENTIAL. That’s it!