Escolar Documentos
Profissional Documentos
Cultura Documentos
Printing
Artland Communications, Lahore. September 2006
Published by
Pakistan Software Export Board
Disclaimer
This toolkit is published by the PSEB for members of the IT industry and the public-at-large.
The toolkit’s compilers, or the editor, are not responsible, in any way possible, for the
errors/omissions of this toolkit. The OSRC does not accept any liability for any direct and
consequential use of this toolkit or its contents. The contents of this toolkit may be distributed
only subject to the terms and conditions set forth in the Open Publication License v 1.0 or
later. The latest version is presently available at http://opencontent.org/openpub/
i
TABLE OF CONTENTS
INTRODUCTION...............................................................................................................................................1
JBOSS: AN INTRODUCTION..............................................................................................................2
1. JBOSS INSTALLATION..................................................................................................................................3
1.1. JDK Installation.............................................................................................................................3
1.2. Environment Variables..................................................................................................................3
1.3. JBoss jar installation.....................................................................................................................3
1.4. Uninstalling JBoss jar-installation................................................................................................4
1.5. Tar installation..............................................................................................................................5
2. JBOSS ADMINISTRATION..............................................................................................................................5
2.1. JBoss - initial directory structure .................................................................................................5
2.2. Starting and Stopping JBoss..........................................................................................................5
2.3. JDBC Datasources........................................................................................................................5
2.4. Creating mysql datasource............................................................................................................5
2.5. mysql-ds.xml .................................................................................................................................5
2.6. Web applications ..........................................................................................................................6
2.7. Getting datasource.........................................................................................................................6
2.8. Deploy web applications in JBoss.................................................................................................6
3. REFERENCES..............................................................................................................................................7
JBOSS –TOMCAT BUNDLE WITH APACHE INTEGRATION.....................................................8
1. INSTALL APACHE WEB SERVER.....................................................................................................................9
2. INSTALL JBOSS APPLICATION SERVER.............................................................................................................9
3. INTEGRATION WITH APACHE ALREADY INSTALLED............................................................................................9
4. CLUSTERING AND LOAD BALANCING.............................................................................................................12
4.1. Optional steps..............................................................................................................................15
5. REFERENCES............................................................................................................................................15
APACHE TOMCAT .............................................................................................................................16
1. INTRODUCTION TO TOMCAT........................................................................................................................17
2. INSTALLING TOMCAT................................................................................................................................17
3. TOMCAT DIRECTORIES AND FILES.................................................................................................................18
3.1. Directory Layout for Web Applications.......................................................................................18
4. EXAMPLE APPLICATION.............................................................................................................................18
4.1. Static Deployment........................................................................................................................18
5. APACHE WITH TOMCAT.............................................................................................................................19
5.1. Step-by-step Guide to Integrating Apache with Tomcat..............................................................19
5.1.1. Apache not already installed ............................................................................................................19
5.1.2. Already Installed Apache.................................................................................................................19
5.1.3. Installing mod_jk.............................................................................................................................19
5.1.4. Configuring mod_jk for Apache 2....................................................................................................20
5.1.5. Testing the configuration with an example setup..............................................................................20
6. REFERENCES............................................................................................................................................21
i
Introduction
This open source toolkit has been developed by the Open Source Resource Center (OSRC),
a project of the Ministry of Information Technology (MoIT). This toolkit contains step-by-step
manuals related to open source applications for databases, application servers, desktop
applications, office productivity suites, Enterprise Resource Planning (ERP) and Customer
Relationship Management (CRM) software, and open source desktop applications for the
Microsoft Windows platform. A set of CDs, including some Linux distributions and other
applications, forms an integral part of this open source toolkit.
I would like to thank the OSRC team, including Mr. Abubakar Shoaib, Mr. Iftikhar Ahmad, Mr.
Muhammad Hammmad, Mr. Muazzam Ali, Mr. Sher Shah Farooq, and Mr. Qandeel Aslam,
who have compiled this toolkit; and Miss Seema Javed Amin, who has edited it. The OSRC
would especially wish to thank PSEB’s Director (Projects) Mr. Nasir Khan Afridi, Former
Project Manger(OSRC) Mr. Osman Haq and Ministry of Information Technology's Member
(IT) Mr. M. Tariq Badsha for their generous moral support, without which this toolkit would
never have been completed.
This is the first edition of this toolkit, and the OSRC hopes to continue to improve it with the
help of your feedback and comments.
Sufyan Kakakhel
Open Source Resource Center,
Pakistan Software Export Board,
2nd Floor, ETC, Agha Khan Road, F-5,
Islamabad, Pakistan.
Ph: +92-51-9208748
Fax: +92-51-9204075
Email: skakakhel@pseb.org.pk
http://www.osrc.org.pk
JDK is a prerequisite for running JBoss and for .jar version installation. Ensure that the
JAVA_HOME variable is set in environment variables, and that you have installed the latest
version of JDK. JBoss 4.0.x and JDK 1.5.x versions have been selected for the purposes of
this tutorial. Download the latest versions from http://java.sun.com/ and http://www.jboss.org
respectively.
1. JBoss Installation
---------------------------------------------------
CLASSPATH=.
PATH=$PATH:/opt/jdk1.5.0_06/bin:/opt/apache-ant-1.6.5/bin:
export CLASSPATH PATH
JAVA_HOME=/opt/jdk1.5.0_06/
export JAVA_HOME
---------------------------------------------------
Save the profile file and load this file by using the following command:
$ source /etc/profile
After selecting the language, the installation folder options and JBoss default server
configuration options will appear. You have to select the default server and configuration for
JBoss jar installation for this tutorial.
2. JBoss Administration
jboss-4.0.3 JBOSS_HOME
/bin contains start and stop scripts
/client contains libriaries for client
/docs contains jboss documentation
/lib contains jboss library
/server contains all,default,minimal server configurations
/all all server configuration
/default default server configuration
/conf
/data
/deploy deployment directory for applications
/lib default server lib
/log
/tmp
/work
/minimal
2.5. mysql-ds.xml
Unique JNDI name
<jndi-name>MySqlDS</jndi-name>
Driver class
<driver-class> com.mysql.jdbc.Driver</driver-class>
Base directory/
.jsp (jpp file)
.html (html files)
WEB-INF/
Classes/
Lib/
Jboss-web.xml
Web.xml
3. References
• JBoss.ORG: http://www.jboss.org
• The Apache Software Foundation: http://www.apache.org/
1. Download the modjk module from the Apache website. Currently, the latest version is
2.1.5. Alternatively, you can download the old version 2.0.6 for Apache-Tomcat
integration only: jakarta-tomcat-connectors-jk-1.2.6-linux-fc2-i386-apache-2.0.50.so
The source code of version 2.1.5 has been used for the purposes of this tutorial.
2. Install the httpd-devel rpm package if it is not already installed. Check this package by
using the command rpm -qa | grep httpd-devel. This package contains the
development tools APXS of Apache httpd development, and is required for mod_jk
recompilation.
----------------------------------------------
$> cd native
$> ./configure --with-apxs=/usr/sbin/apxs (or wherever the apxs/apxs2 is)
$> make
$> su -c 'make install
-----------------------------------------------
/usr/lib/httpd/modules/
/etc/httpd/conf
Add the following lines at the end of the file to load module JK for Apache and JBoss-
Tomcat integration:
------------------------------------------------------
# Include mod-jk specific configuration file
Include conf/mod-jk.conf
------------------------------------------------------
7. Create file mod-jk.conf if it does not exist in the Apache conf directory
/etc/httpd/conf
8. There are two types of mod_jk configuration. The first is for the old mod_jk 2.0.6. The
second is for the new 2.1.15.
------------------------------------------------------
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
------------------------------------------------------
------------------------------------------------------
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
------------------------------------------------------
/etc/httpd/conf
------------------------------------------------------
# Define list of workers that will be used
# for mapping requests
worker.list=ajp13
# Define ajp13
# modify the host as your host IP or DNS name.
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
worker.ajp13.cachesize=10
------------------------------------------------------
------------------------------------------------------
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1
worker.loadbalancer.sticky_session=1
#worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status
------------------------------------------------------
jboss-service.xml
------------------------------------------------------
<attribute name="UseJK">false</attribute>
changed to
<attribute name="UseJK">true</attribute>
------------------------------------------------------
For more information regarding web applications, please see the guide to “JBoss Installation
and Administration”.
jboss -c all
The nodes in the cluster join in ClusterPartation Mbean in the deploy/cluster-service.xml. All
nodes that have the same ClusterPartation MBean configuration join the same cluster. If, for
example, you want to divide JBoss nodes in a network into two clusters, you can make two
different ClusterPartition MBean configurations, and each node will have one of the two
configurations, depending on which cluster it needs to join.
The primary purpose of clustering HTTP services is session state replication, which is
handled by JBoss itself when it starts the configuration. Load balancing, however, needs to be
implemented with different software.
/etc/httpd/conf
------------------------------------------------------
# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=node1.mydomain.com
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.cachesize=10
# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host= node2.mydomain.com
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.node2.cachesize=10
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1
#worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status
------------------------------------------------------
Now configure the JBoss node as well, so that they work with Apache mod_jk in a load
balancing environment.
In every clustered JBoss node, specify the node element according to workers.properties.
------------------------------------------------------
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node2">
... ...
</Engine>
------------------------------------------------------
[jboss-4.x]/server/default/deploy/jbossweb-tomcat55.sar/META-INF/index.jsp
jboss-service.xml
------------------------------------------------------
<attribute name="UseJK">true</attribute>
changed to
<attribute name="UseJK">false</attribute>
-----------------------------------------------------
[jboss-4.x]/server/all/deploy/jbossweb-tomcat55.sar/META-INF/
For more information regarding web applications, please see the guide to “JBoss Installation
and Administration”.
jboss-service.xml
------------------------------------------------------
<attribute name="UseJK">false</attribute>
changed to
<attribute name="UseJK">true</attribute>
------------------------------------------------------
In order to test the configurations, create an application with the same directory name. Add
example.war in both nodes [jboss-4.x]/server/all/deploy/ directory and create a test.jsp file in
both to display the following content:
test.jsp on node1
test.jsp on node2
<% out.print(“Node2”); %>
By accessing any node, you can see either Node 1 or Node 2 on the browser window,
confirming that the Apache load-balancing is working.
------------------------------------------------------
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<distributable/>
<!-- ... -->
</web-app>
------------------------------------------------------
Now you can further configure session replication by editing the jboss-web.xml file and use
the following replication-config tag:
------------------------------------------------------
<jboss-web>
<replication-config>
<replication-trigger>SET_AND_NON_PRIMITIVE_GET</replication-
trigger>
<replication-granularity>SESSION</replication-granularity>
</replication-config>
</jboss-web>
------------------------------------------------------
5. References
• JBoss: http://www.jboss.org/
• The Apache Software Foundation: http://www.apache.org/
2. Installing Tomcat
Tomcat can be compiled in both source and binary forms. This guide will only demonstrate
installation from the binary form. The Tomcat binary distribution comes in a variety of flavors
i.e. core, deployer, embedded, administration web application, and the JDK 1.4 computability
package. The core distribution is a superset of all others and will be used throughout this
guide.
• For Tomcat 5.5, Java 5.0 is the recommended version, which can be downloaded
from
http://192.18.108.216/ECom/EComTicketServlet/BEGIN5A43F36CC69A6135A09
EB2C09E7982E8/-
2147483648/1396678059/1/681986/681830/1396678059/2ts+/westCoastFSEND/
jdk-1.5.0_06-oth-JPR/jdk-1.5.0_06-oth-JPR:3/jdk-1_5_0_06-linux-i586-rpm.bin
• Make sure you have uninstalled other Java compilers such as gcj from the
system.
# rpm -qa |grep gcj
# rpm -qa |grep java
Use rpm -e package-name uninsall.
• Change permissions
# chmod 555 jdk-1_5_0_06-linux-i586-rpm.bin
• Run the installer
# jdk-1_5_0_06-linux-i586-rpm.bin
• Create an entry in /etc/profile so that you don’t have to write the full path
whenever Java is required.
# vi /etc/profiles
Add the following lines:
---------------------------------------
export JAVA_HOME=/usr/java/jdk1.5.0_06/bin
export PATH=$PATH:$JAVA_HOME/bin
---------------------------------------
Tomcat has now been installed. Run Tomcat by running the startup script in
$CATALINA_HOME/bin directory.
# ./startup.sh
Browse to http://localhost:8080.
Tomcat includes a username and password in a special file tomcat-users.xml under the conf
directory. In order to access the Tomcat manager and admin interface, you have to assign
these roles explicitly. Copy the following line and place it in tomcat-users.xml file in place of
tomcat user.
-------------------------------------------
<user username="tomcat" password="tomcat" roles="standard,tomcat,admin,manager"/>
-------------------------------------------
Restart Tomcat and browse to http://localhost:8080 and access the manager and admin
interface.
Each web application is typically deployed under a single directory known as the document
root. This directory contains HTML and JSP pages that define the startup interface of your
web application. Place your web application’s executable files in WAR format, which will be
run by Tomcat. This format is discussed below:
1. *.html, *.jsp, etc: These pages define the startup interface, and must therefore be
visible to the client and placed directly under document root.
2. /WEB-INF/web.xml: This XML file defines all the parameters and other information
about the application required to the server.
3. /WEB-INF/classes: This directory contains Java classes required by the application.
4. /WEB-INF/lib: Any jar file(s) required by the application.
4. Example Application
Web applications can be deployed either statically or dynamically. In the former, applications
can be placed in the Tomcat document root folder and the Tomcat instance is restarted to
take effect. In the latter, the Tomcat manager tool can be used to deploy applications
dynamically without restarting the server instance. In Tomcat, there are also other possible
ways to deploy web applications, such as the client deployer package. A detailed guide can
be found in the “References” section. The simplest way is to deploy applications statically.
1. Download the file from the above URL and move it to $CATALINE_HOME/webapps.
2. Restart Tomcat and browse to http://localhost:8080/sample
Apache is pre-installed on most of the Linux distributions, in which case skip to the next
section. If not, then:
In most cases, Apache is pre-installed with Linux distributions. In Fedora Core 2/3, for
example, Apache’s home location is /etc/httpd. We will refer to APACHE_HOME as its home
directory, which could be /usr/local/apache2 or /etc/httpd, depending on whether you built
Apache yourself, or used the pre-installed version.
In order to work around with the pre-installed Apache, you need to install the Apache
Extension Tool (APXS). “APXS is a tool for building and installing extension modules for the
Apache HyperText Transfer Protocol (HTTP) server.”
The following packages must be installed: httpd-devel, apr, apr-util, apr-devel, apr-util-devel
and pcre-devel. Download and install these packages from appropriate locations, possibly
httpd://rpmfind.net. Make sure that the httpd-devel matches exactly with the installed httpd.
mod_jk is a connector module for Apache that communicates with Tomcat. It is recommended
that you read the documentation for the connectors at http://tomcat.apache.org/connectors-
doc/index.html.
workers.tomcat_home=$CATALINA_HOME
workers.java_home=$JAVA_HOME
ps=/
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1
# Mod_jk settings
JkWorkersFile "conf/workers.properties"
JkLogFile "logs/mod_jk.log"
JkLogLevel error
JkMount /jsp-examples default
JkMount /jsp-examples/* default
# End of mod_jk settings
1) Run Tomcat
# CATALINA_HOME/bin/catalina.sh start
2) Start the Apache service after a 10 second gap. This is to ensure that Tomcat has been
started fully.
# service httpd start
3) Open your browser of choice and point to http://localhost and http://localhost:8080 to verify
that both Apache and Tomcat are running.
4) Open http://localhost/jsp-examples to execute any example on the page. Note that port
8080 has not been specified. Now Apache will automatically redirect the request to
Tomcat.
5) You can also create your own test application. Execute the following steps:
index.html
<HTML>
<HEAD>
<TITLE>Say Hello!</TITLE>
</HEAD>
<BODY>
<A HREF="hello.jsp">Hello World</A>
</BODY>
</HTML>
hello.jsp
<html>
<head>
<title>Hello World! </title>
</head>
<body>
<%@ page language="java" %>
<% out.println("Hello World"); %>
</body>
</html>
6) Open http://localhost/test
6. References
• Apache Tomcat by The Apache Software Foundation: http://tomcat.apache.org/