The following tutorial will show setting up mod_jk with apache to serve tomcat with mod_jk

For making it work with the tomcat7 we need to add the following sources:

vi /etc/apt/sources.list

deb http://de.archive.ubuntu.com/ubuntu precise main restricted universe multiverse
#deb-src http://de.archive.ubuntu.com/ubuntu precise main restricted universe multiverse

deb http://de.archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse
#deb-src http://de.archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse

deb http://de.archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse
#deb-src http://de.archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse

deb http://de.archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse
#deb-src http://de.archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse

Perform the installation process:

apt-get update
apt-get install tomcat7 tomcat7-examples tomcat7-docs default-jdk libapache2-mod-jk tomcat7-admin

Add the tomcat users in the following file with the roles to access the web based admin panel:

vi /etc/tomcat7/tomcat-users.xml

<role rolename=”manager-gui”/>
<role rolename=”admin-gui”/>
<user username=”tomcat” password=”s3cret” roles=”manager-gui,admin-gui”/>

Export the variables:

export CATALINA_HOME=/usr/share/tomcat7/
export JAVA_HOME=/usr/lib/jvm/default-java

Create the workers file for mod_jk

vi /etc/apache2/workers.properties

workers.tomcat_home=/usr/share/tomcat7         <- path of CATALINA_HOME
workers.java_home=/usr/lib/jvm/default-java     <- path of JAVA_HOME
ps=/
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

Change the path of the worker.properties file accordingly

vi /etc/apache2/mods-enabled/jk.conf

JkWorkersFile /etc/apache2/workers.properties

Create apache virtual host

vi /etc/apache2/sites-available/java

<VirtualHost *:80>
JkMount /* default
ServerName farhan.com
DocumentRoot /var/www/java/
ErrorLog /var/www/java/logs/error.log
CustomLog /var/www/java/logs/access.log combined
<Directory /var/www/java>
Options -Indexes
</Directory>
</VirtualHost>

Enable the site and create the required directories

a2ensite java
mkdir /var/www/java/
mkdir /var/www/java/htdocs
mkdir /var/www/java/logs
cp /etc/tomcat7/Catalina/localhost/* /etc/tomcat7/Catalina/farhan.com/

Create the host setting for the tomcat

vi /etc/tomcat7/server.xml

Un-Comment the following

<Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />

and

Add a host at the end of the file
</Host>
<Host name=”farhan.com” appBase=”/var/www/java” unpackWARs=”true” autoDeploy=”true”>
<Context path=”” docBase=”htdocs” debug=”1″ reloadable=”true”/>
<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”/var/www/java/logs”  prefix=”tomcat_access_” suffix=”.log” pattern=”common” resolveHosts=”false”/>
</Host>

Restart services

/etc/init.d/tomcat7 restart
/etc/init.d/apache2 restart

Copy the welcome page from the default
cd /var/www/java/htdocs/
cp /var/lib/tomcat7/webapps/ROOT/index.html .

Create a host file and check the configurations

http://farhan.com/manager

Advertisements