Friday, November 30, 2012

Tomcat Clustering - Apache WebServer

Hello There,

Today early morning I tried something new, which I never tried to do it but always wanted to, had a new assignment to learn tomcat (http://tomcat.apache.org) and clustering tomcat, finding and adding up a little to the statement - "pressure makes man perfect", I thought what is there to learn.?, bunch of configuration files and batch files, Google it and you will be settled to live with this guy.!, did the same and was able to see my tomcat running with hosted applications (example application) now I need to bring another exceptionally performing mini software to work with him called Apache (http://www.apache.org/) to work as frontend help desk for the processor behind. Let's see how are we able to establish this.!!

Steps To Follow
-------------------

1) Download and Install both Softwares

  • Apache - http://mirror.reverse.net/pub/apache/httpd/binaries/win32/httpd-2.0.64-win32-x86-no_ssl.msi
    • Or you can manually go the site http://httpd.apache.org/download.cgi and download desired versions from desired mirrors.
    • Need Admin Permission to Install.
    • I tried it on httpd-2.0.64-win32-x86-no_ssl.msi
    • I have used localhost for the hostname and admin@localhost as email id
  • Apache Tomcat - http://tomcat.apache.org/download-70.cgi
    • Download any version that suits your requirement
    • I tried it on apache-tomcat-7.0.32
    • Just Unzip file and you are done with installation.
  •  Verify the setup details and test the installation by testing the default application after starting them.
  • For More Information refer : 
    • http://httpd.apache.org/docs/2.0/platform/windows.html
    • http://tomcat.apache.org/tomcat-5.5-doc/setup.html#Windows
  •  Done

2) Configure Tomcat for Clustering - ( Vertical Clustering) 

For Clustering we need to have at least 2 instances of the server instances and within that we need to have load balancing established, for creating another instance of tomcat just copy the tomcat folder, paste in the same directory and rename it.

C:\SandBox\WebServers\TomcatCluster>dir
 Volume in drive C is OSDisk
 Volume Serial Number is E604-B574

 Directory of C:\SandBox\WebServers\TomcatCluster

23/11/2012  17:58    <DIR>          .
23/11/2012  17:58    <DIR>          ..
23/11/2012  17:58    <DIR>          apache-tomcat-1
23/11/2012  17:58    <DIR>          apache-tomcat-2
               0 File(s)              0 bytes
               4 Dir(s)  175,658,151,936 bytes free


few of the configurations we need to change to enable the tomcat to work for other server ( to establish cluster)

modify the server.xml file present in apache-tomcat-x/conf/ as below for both instances.

apache-tomcat-1
---------------------
1) Change the port number as below.

<Server port="8105" shutdown="SHUTDOWN">

2) Change the Port Number as below for HTTP Protocol.


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


3) Enable the AJP Protocol if it is disabled and change the port number 

<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />

4) Enable the Cluster feature for Tomcat by disabling the comments as below.

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

5) Open the Application for which you would like to test the Clustering Feature and add the <distributable/> within <web-app></web-app> tags..............

I have tested it for examples webapp under <CATALINA_HOME>/webapps/ (CATALINA_HOME) is another name for Tomcat Home - you need to specify this in system's environment variables.

Example : Go to C:\SandBox\WebServers\TomcatCluster\apache-tomcat-1\webapps\examples\WEB-INF


<servlet-mapping>
      <servlet-name>wsSnake</servlet-name>
      <url-pattern>/websocket/snake</url-pattern>
    </servlet-mapping>
    <distributable/>
</web-app>

Now repeat the steps for apache-tomcat-2 instance.

apache-tomcat-2


1) Change the port number as below.

<Server port="8205" shutdown="SHUTDOWN">

2) Change the Port Number as below for HTTP Protocol.


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


3) Enable the AJP Protocol if it is disabled and change the port number 

<Connector port="8209" protocol="AJP/1.3" redirectPort="8443" />

4) Enable the Cluster feature for Tomcat by disabling the comments as below.

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

5) Open the Application for which you would like to test the Clustering Feature and add the <distributable/> within <web-app></web-app> tags..............

I have tested it for examples webapp under <CATALINA_HOME>/webapps/ (CATALINA_HOME) is another name for Tomcat Home - you need to specify this in system's environment variables.

Example : Go to C:\SandBox\WebServers\TomcatCluster\apache-tomcat-2\webapps\examples\WEB-INF


<servlet-mapping>
      <servlet-name>wsSnake</servlet-name>
      <url-pattern>/websocket/snake</url-pattern>
    </servlet-mapping>
    <distributable/>
</web-app>



Restart both Tomcat Instances.

3) Configure Apache for Clustering with Tomcat

Hope you have already installed Apache WebServer and tested on http://localhost/

Configuring Apache Server involves below steps :


  • Downloading mod_jk library
    • Please download the mod_jk.so file from link
    • once you get the zip file, unzip it and copy the mod_jk.so file to Apache2/modules folder.
  • Configure mod_jk.so file in Apache Configuration
    • Create mod_jk.conf file with following entries
# Load mod_jk module

# Update this path to match your modules location
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
# Update this path to match your conf directory location
JkWorkersFile C:/SandBox/WebServers/apache2.0.64/Apache2/conf/workers.properties

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile C:/SandBox/WebServers/apache2.0.64/Apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# Send everything for context /examples to worker ajp13
JkMount /examples loadbalancer
JkMount /examples/* loadbalancer
    • Add following entry in httpd.conf file.
include C:/SandBox/WebServers/apache2.0.64/Apache2/conf/mod_jk.conf
  • Create worker.properties for handling requests from Apache and copy the below content to the file.
    • You can specify the tomcat home for first tomcat instance
# Define 1 real worker named ajp13
workers.tomcat_home=C:/SandBox/WebServers/TomcatCluster/apache-tomcat-1
workers.java_home=%JAVA_HOME%
worker.list=node1,node2,loadbalancer

# Set properties for worker named ajp13 to use ajp13 protocol,
# and run on port 8009

worker.node1.port=8109
worker.node1.host=localhost
worker.node1.type=ajp13
worker.node1.lbfactor=1

worker.node2.port=8209
worker.node2.host=localhost
worker.node2.type=ajp13
worker.node2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=node1,node2
worker.loadbalancer.sticky_session=1
  • Copy the file worker.properties file to Apache2/conf directory.
  • Restart Apache Server.
3) Access the URL : http://localhost/examples or deploy any session replication enabled application to test whether session is getting replicated or the clustering load balancer is working properly or not.














Additionally if you see the mod_jk.log file, following entries are noticed during this operation.


[Fri Nov 30 15:02:16 2012]loadbalancer localhost 2.102120
[Fri Nov 30 17:07:40 2012]loadbalancer localhost 0.442025
[Fri Nov 30 17:07:40 2012][8720:6044] [info] ajp_send_request::jk_ajp_common.c (1619): (node2) all endpoints are disconnected, detected by connect check (1), cping (0), send (0)
[Fri Nov 30 17:07:40 2012]loadbalancer localhost 0.235014
[Fri Nov 30 17:14:07 2012]loadbalancer localhost 0.101006


Hope I haven't missed anything yet.!!

Regards
Shailesh Dyade



Monday, November 26, 2012

Setting Up JBoss

Hello There,

Hope everyone is doing great, me too.!!

Been in new assignment from few days, so thought could give some work for my brain.. to refurbish my JBoss ideas..!!

Started with JBoss Installation and Starting Up..!!

You will find this very simple though, thought of sharing with you in case if you find this challenging.;)

Step 1. Download JBoss Package (.zip) file from http://www.jboss.org/jbossas/downloads/

I downloaded : http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.zip as it is latest.

Step 2 : Copy the file to desired location and Unzip it.

Step 3 : Installation is Completed.

Step 4 : To Sample Start up, go to Unzipped JBoss Directory and Open the Gates of bin Directory.

Step 5 : Copy the PATH till here and navigate to bin directory from Command Prompt ( => Start-> Run-> CMD) by command cd <PATH to bin directory)

Step 6 : Once in bin directory, execute standalone.bat or standalone.sh in case if you do not have Windows Box.

Step 7 : Hold On..!!, You Should Have JAVA Installed Before You Introduce Yourself with JBoss.

Step 8 : After you execute standalone.bat file, your eyes will witness following output.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\shailesh.dyade>cd C:\SandBox\AppServers\jboss-as-7.1.1.Final\bin


C:\SandBox\AppServers\jboss-as-7.1.1.Final\bin>standalone

Calling "C:\SandBox\AppServers\jboss-as-7.1.1.Final\bin\standalone.conf.bat"
===============================================================================

  JBoss Bootstrap Environment


  JBOSS_HOME: C:\SandBox\AppServers\jboss-as-7.1.1.Final


  JAVA: C:\Program Files\Java\jdk1.7.0_09\bin\java


  JAVA_OPTS: -XX:+TieredCompilation -Dprogram.name=standalone.bat -Xms64M -Xmx51

2M -XX:MaxPermSize=256M -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.se
rver.gcInterval=3600000 -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.war
ning=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djboss.server.default.c
onfig=standalone.xml

===============================================================================


15:09:26,732 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA

15:09:30,059 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
15:09:30,139 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" sta
rting
15:09:45,406 INFO  [org.xnio] XNIO Version 3.0.3.GA
15:09:45,406 INFO  [org.jboss.as.server] JBAS015888: Creating http management se
rvice using socket-binding (management-http)
15:09:45,440 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
15:09:45,546 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
15:09:45,658 INFO  [org.jboss.as.configadmin] JBAS016200: Activating ConfigAdmin
 Subsystem
15:09:45,665 INFO  [org.jboss.as.clustering.infinispan] JBAS010280: Activating I
nfinispan subsystem.
15:09:45,674 INFO  [org.jboss.as.osgi] JBAS011940: Activating OSGi Subsystem
15:09:45,676 INFO  [org.jboss.as.naming] JBAS011800: Activating Naming Subsystem

15:09:45,693 INFO  [org.jboss.as.security] JBAS013101: Activating Security Subsy

stem
15:09:45,694 INFO  [org.jboss.as.webservices] JBAS015537: Activating WebServices
 Extension
15:09:45,733 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log han
dlers
15:09:45,844 INFO  [org.jboss.as.security] (MSC service thread 1-4) JBAS013100:
Current PicketBox version=4.0.7.Final
15:09:45,880 INFO  [org.jboss.as.connector] (MSC service thread 1-7) JBAS010408:
 Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
15:09:47,481 INFO  [org.jboss.as.naming] (MSC service thread 1-6) JBAS011802: St
arting Naming Service
15:09:47,485 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-6) JBAS01
5400: Bound mail session [java:jboss/mail/Default]
15:09:48,981 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread
 1-3) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
15:09:49,160 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerServic
e Thread Pool -- 39) JBAS010403: Deploying JDBC-compliant driver class org.h2.Dr
iver (version 1.3)
15:09:49,699 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service
thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
15:09:51,878 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC se
rvice thread 1-5) JBoss Web Services - Stack CXF Server 4.0.2.GA
15:09:53,160 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread
1-5) JBAS015012: Started FileSystemDeploymentService for directory C:\SandBox\Ap
pServers\jboss-as-7.1.1.Final\standalone\deployments
15:09:53,199 INFO  [org.jboss.as.remoting] (MSC service thread 1-4) JBAS017100:
Listening on /127.0.0.1:9999
15:09:53,199 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100:
Listening on /127.0.0.1:4447
15:09:53,810 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin con
sole listening on http://127.0.0.1:9990
15:09:53,813 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS
7.1.1.Final "Brontes" started in 30795ms - Started 133 of 208 services (74 servi
ces are passive or on-demand)

Step 9 : As it says, Admin console Listening on http://127.0.0.1:9990/ go to this URL on your browser, do not try to click this URL right away, you have not installed the JBoss yet.!!


Here you can see the console of JBoss Application Server, which says to add user first then you will be able to see the complete console.

And to Add user we need to execute the add-user.bat script in bin directory, lets try that..!!

After you add, there will be a link to refresh the configuration - you got to click that.





C:\SandBox\AppServers\jboss-as-7.1.1.Final\bin>add-user.bat

What type of user do you wish to add?
 a) Management User (mgmt-users.properties)
 b) Application User (application-users.properties)

(a): a

Enter the details of the new user to add.
Realm (ManagementRealm) :
Username : shailesh
Password :
Re-enter Password :
About to add user 'shailesh' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'shailesh' to file 'C:\SandBox\AppServers\jboss-as-7.1.1.Final\standa
lone\configuration\mgmt-users.properties'
Added user 'shailesh' to file 'C:\SandBox\AppServers\jboss-as-7.1.1.Final\domain
\configuration\mgmt-users.properties'
Press any key to continue . . .




Enter your username and password created in above step, you can make your machine to remember the same till you brainwash him.

Once you login, you will be able to see the page, little familiar from last versions I have worked but very much different in looks, RedHat has changed the Application Server in whole, time to explore it..


Try dropping an application in the deployment folder of standalone profile and try to access.

Its your homework too, explore the same, do it and share your ideas here, you are very welcome to post comments, feedback's about the post and suggestions are very much welcome.

I will end the session here now, and will come back with more goodies of tips and technologies with all that tricks very soon in blog pages.

Take Care, 
Shailesh Dyade.



Tuesday, November 20, 2012

Web Based Link for Learning Java and Related Few Products

Hello There,

Recently found a link about learning Java Programming along with few technologies like, Tomcat, MySql, Unix, Windows, etc..

Link is : http://www3.ntu.edu.sg/home/ehchua/programming/index.html

Please go through this and share as much as this will be very helpful for Middleware Administrators.

Regards
Shailesh Dyade.