...
With Ubuntu you can have mod_jk almost automatically install for you via,
Code Block | ||
---|---|---|
| ||
sudo apt-get install libapache2-mod-jk |
...
mod_jk may be installed but it still needs to be configured. Create the file /etc/apache2/mods-available/jk.conf using sudo with the following contents,
Code Block | ||
---|---|---|
| ||
<IfModule mod_jk.c> JkWorkersFile "/etc/libapache2-mod-jk/workers.properties" JkLogFile "/var/log/apache2/mod_jk.log" # Use debug mode if you have trouble # JkLogLevel debug JkLogLevel info </IfModule> |
...
Manually Installing mod_jk
I often have to do this on Solaris or alternative operating systems so the manual process of installing mod_jk is good to have handy
...
In Ubuntu it is very easy to enable a module,
Code Block | ||
---|---|---|
| ||
sudo a2enmod jk |
This basically creates symbolic links for you in the /etc/apache2/mods-enabled directory. The two symbolic links will be,
...
You can verify that the module loaded properly,
Code Block | ||
---|---|---|
| ||
sudo apache2ctl -l Compiled in modules: core.c mod_log_config.c mod_logio.c worker.c http_core.c mod_so.c |
...
Edit or create (in the case of a manual setup) /etc/libapache2-mod-jk/workers.properties which defines how Apache will pass the traffic to Tomcat.
Code Block | ||
---|---|---|
| ||
# Define workers using ajp13 worker.list=tomcat_a_worker # Set properties for worker worker.tomcat_a_worker.type=ajp13 worker.tomcat_a_worker.host=localhost worker.tomcat_a_worker.port=8009 worker.tomcat_a_worker.lbfactor=1 |
...
To keep the example simple I have not added load balancer support yet. If you want load do load balancing a simple configuration would look like this,
Code Block | ||
---|---|---|
| ||
# Define workers using ajp13 worker.list=loadbalancer # Set properties for worker worker.tomcat_a_worker.type=ajp13 worker.tomcat_a_worker.host=localhost worker.tomcat_a_worker.port=9009 worker.tomcat_a_worker.lbfactor=1 # Set properties for worker worker.tomcat_b_worker.type=ajp13 worker.tomcat_b_worker.host=localhost worker.tomcat_b_worker.port=8109 worker.tomcat_b_worker.lbfactor=1 # Set up load balancer using ajp13 workers work.loadbalancer.type=lb work.loadbalancer.balance_workers=tomcat_a_worker,tomcat_b_worker |
...
In our examples we will be using virtual hosts. Once you get virtual hosts working, add this entry to your virtual host file.
Code Block | ||
---|---|---|
| ||
JkMount /examples tomcat_a_worker JkMount /examples/* tomcat_a_worker |
...
Finally you must restart Apache for the changes to take effect.
Code Block | ||
---|---|---|
| ||
sudo /etc/init.d/apache2 restart |
...