Not able to configure mod_JK in HTTPD.CONF file for load balancing - apache

I am not able to configure the apache load balancer with mod_jk. Each time I channge httpd.conf file apache server doesnot start.
Here is the scenario:
I have 2 apache tomcat instance, Tomcat and tomcat2 and both are running on different ports.
I would like to establish a load balancer for these two instances with apache mod_jk:
I have downloded mod_jk.so file and places in modules folder.
Below configuration I am trying to httpd.conf file:
LoadModule jk_module modules/mod_jk.so
AddModule mod_jk.c
JkWorkersFile conf/workers.properties
JkLogFile log/httpd/mod_jk.log
JkLogLevel info
mod_jk loadbalancer
JkMount /examples/* loadbalancer
Here is my workers.propertise file:
# Define list of workers that will be used
worker.list=loadbalancer
# Define Node1
worker.node1.port=8009
worker.node1.host=localhost
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.cachesize=10
# Define Node2
worker.node2.port=8010
worker.node2.host=localhost
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
# Status worker for managing load balancer
worker.status.type=status
I am not sure, what is wrong here. May be I am adding the mod_jk conf in httpd.conf file at wrong place.
Can anybody guide. Any sample working HTTPD.CONF file will be great.
Thanks you for the help.
-Santosh

Issue resolve:
I was using the mod_jk.so file compatible with apache version 2.0 and Apache webserver 2.2.
I have downloaded the mod_jk.so file compatible for 2.2 version and now everything is working fine.
You can check detailed error by option:
c:/your_apache_dir/bin> httpd.exe -D mod_jk
Thanks for your help.

JkWorkersFile "conf/workers.properties" this should be this way and also do check for the mod_jk compatibility.

Related

Wildfly, Tomcat, Apache and Subdomains

I have an Ubuntu server in AWS that is running multiple application servers -- a Wildfly serving up some pages and two Tomcats running a separate app.
I am trying to get subdomains working.
I have DNS's set up to point subdomain1.example.com, subdomain2.example.com. That works fine.
Wildfly is listening on port 80 (I think?), the Tomcats are listening on 8080 and 8090. The goal is to have www.example.com go to Wildfly, subdomain1.example.com go to Tomcat : 8080 and subdomain2.example.com go to Tomcat : 8090
I've found numerous posts that talk about setting up virtual hosts in Apache that should solve my problem. But I keep getting sent down rabbit holes. Some suggest adding to /opt/bitnami/apache2/bin/httpd.config and some suggest putting it in /opt/bitnami/apache2/sites-available/subdomain1.example.com.conf
My first issue: I don't think that Apache is even running. I was under the impression that Apache was baked into Wildfly, but when I execute:
service apache2 status
I get:
apache2.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
Running sudo service --status-all also doesn't show it running so I think that it is not. It seems to be installed (Bitnami stack) in /opt/bitnami/apache2
Do I have to turn Apache on as part of Wildfly (and how to turn it on)? If I do, then I would assume that Wildfly is no longer getting traffic.
Second - my research tells me I need i need to enable proxy and proxy_http using a2enmod and a2ensite but I don't have these. Research suggests that all Ubuntu's will have those scripts... do they get created if I turn on Apache?
Sorry for all the noob questions.... I'm a developer without a DevOps guy. This seems like it would so common it would be baked in or there would be a definite solution that I am probably missing.
For those looking for something similar, here is the solution that worked for me.
My server is a Wildfly-Apache2-MySQL AMI image on AWS. I did not need to use a2enmod nor a2ensite as my research suggested. It seems many of those modules are already enabled by the pre-built image.
NOTE THESE INSTRUCTIONS ARE BITNAMI AWI SPECIFIC - YOUR FLAVOR CONFIGURATION MAY BE SLIGHTLY DIFFERENT
To have a subdomain point to a simple Apache text site (yada.example.com):
Create a directory in ~/stack/apache2/htdocs called yada
Add an entry to the virtual hosts configuration file (sudo nano /opt/bitnami/apache2/conf/extra/httpd-vhosts.conf)
<VirtualHost *:80>
ServerAdmin info#example.com
DocumentRoot "/opt/bitnami/apache2/htdocs/yada"
ServerName yada.example.com
ErrorLog "logs/yada-subdomain-error-log"
CustomLog "logs/yada-subdomain-access-log" common
</VirtualHost>
Modify the Apache configuration file to include the virtual hosts. (sudo nano /opt/bitnami/apache2/conf/httpd.conf):
...snip...
# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.
...snip...
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# ADDED THE ABOVE LINE
...snip...
Restart Apache (sudo /opt/bitnami/ctlscript.sh restart apache)
To make it point to a Tomcat server, add this to the httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin info#example.com
ServerName yada.example.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
</VirtualHost>
Your port may differ.
FYI, I found this helpful: https://docs.bitnami.com/virtual-machine/components/apache/#how-to-configure-your-web-application-to-use-a-virtual-host
Good luck and shout out to #stdunbar for his guidance.

Two loadbalacer with apache 2.2(for jboss and apapche tomcat)

I have a apache server with loadbalancer(apache-2.2) and two tomcat nodes(clusters). To communicate with tomcat nodes I'm using mod_jk. I've defined two loadbalancer in apache(by changing httpd.conf and worker property files). Apache is running in port 80. The configuration as follows. iSencer is one of my application.
In httpd.conf
=============
Listen localhost:80
ServerName localhost
DocumentRoot "/home/xx/projects/apache/content" (I've created a seperate root directory as content)
JkMount /iSencer loadbalancer
JkMount /iSencer/ loadbalancer
JkMount /iSencer/* loadbalancer
In worker.properites
====================
worker.list=loadbalancer
#------------------------
# iSencer node 1 - tomcat
#------------------------
worker.iSencer1.type=ajp13
worker.iSencer1.host=localhost
worker.iSencer1.port=8109
#------------------------
# iSencer node 2 - tomcat
#------------------------
worker.iSencer2.type=ajp13
worker.iSencer2.host=localhost
worker.iSencer2.port=8010
# ------------------------
# Load Balancer for yard
# ------------------------
worker.loadbalancer.sticky_session=1
worker.loadbalancer.balanced_workers=iSencer1,iSencer2
worker.loadbalancer.type=lb
worker.loadbalancer.method=B
and there are some changes in tomcat server.xml.So, cluster is working properly.
Now I want to add a jboss server to same apache. But need to run in different loadbalancer. My changes as follows as in httpd.conf in apache.
JkMount /index.html loadbalancer2
JkMount /servlet/* loadbalancer2
worker property
===============
worker.list=loadbalancer, worker.list=loadbalancer2
#------------------------
# tracker node 1
#------------------------
worker.track.port=8009
worker.track.host=localhost
worker.track.type=ajp13
worker.track.lbfactor=1
worker.track.connection_pool_size=10
# ------------------------
# Load Balancer for tracker
# ------------------------
worker.loadbalancer2.sticky_session=1
worker.loadbalancer2.balanced_workers=track
worker.loadbalancer2.type=lb
worker.loadbalancer2.method=B
But after adding jboss to apache as a cluster my tomcat cluster is not working properly ? In browser it will show two JSESSIONIDs. When I remove jboss form apache configuration still not working. Browser still showing two JSESSIONIDs. After clearing cookies in browser cluster is working fine. so what is the reason not to work cluster with jboss ?

error starting apache 2.4 with mod_jk

For reference I used this guide to setup integration between tomcat 7 and apache 2.4, with the mod_jk. https://www3.ntu.edu.sg/home/ehchua/programming/howto/ApachePlusTomcat_HowTo.html
When opening cmd in windows and doing a: c:\Apache24\bin> httpd -k start I get the follow error
httpd: Syntax error on line 526 of C:/Apache24/conf/httpd.conf: Syntax error on line 1 of C:/Apache24/conf/mod_jk.conf: Cannot load modules/mod_jk.so into server: access denied.
Below is the two files which has syntax errors.
mod_jk.config
LoadModule jk_module modules/mod_jk.so
JkWorkersFile C:/Program Files/Apache Software Foundation/Tomcat
7.0/conf/workers.properties
JkLogFile C:/Program Files/Apache Software Foundation/Tomcat 7.0/logs
JkLogLevel info
JkOptions +ForwardkeySize +ForwardURICompat +ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /rehavoc ajp13 jkMount /rehavoc/* ajp13
httpd.config
include C:/Apache24/conf/mod_jk.conf
Tomcat 7 is properly setup(I hope) Since I can in tomcat manager, deploy a war file with a test servlet running and see it work on the localhost/url.
Apache 2.4 should also be working seeing my web site is live and can be accessed on the web(just a simple hello world html).
Operating system is vista.
Also, have I understood correctly that with these three 'services' will I be able to deploy a war file into apache htdocs, including jsp/servlets and it will have no trouble running on my site?
Any help is appreciated.
Solved it by not using apache 2.4 and mod_jk. Were better to just use tomcat 7 alone from the start.

Sticky Session in apache doesn't work

This is currently my environment setup.
Apache Tomcat: Apache-Tomacat-7.0.21
Apache HTTP Server: c. Apache HTTP Server 2.2.19
Tomcat Connector JK 1.2.32 for Apache HTTP Server 2, mod_jk
I'm trying to implement sticky session but i still can't get it to work. I'm able to load balance between 2 machines in a cluster. Please advise what else i have missed out!
Following is my workers.properties file
# Define 2 real workers using ajp13 & 1 balancer
worker.list=balancer
#
worker.balancer.type=lb
worker.balancer.balance_workers=worker1,worker2
worker.balancer.sticky_session=True
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.recycle_timeout=300
# Set properties for worker2 (ajp13)
worker.worker2.type=ajp13
worker.worker2.host=X.X.X.X
worker.worker2.port=8009
worker.worker2.lbfactor=50
worker.worker2.cachesize=10
worker.worker2.cache_timeout=600
worker.worker2.socket_keepalive=1
worker.worker2.recycle_timeout=300
I've also set the jvmRoute in server.xml to:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">

How to install mod_ssl for Apache httpd?

Ok
So I installed Apache httpd a while ago and have recently come back to it to try setup SSL and get it serving several different tomcat servers.
At the moment I have two completely separate Tomcat instances serving up to slightly different versions (one for dev and one for demo say) my web app to two different ports:
example.com:8081
example.com:8082
I've successfully (back in Jan) used mod_jk to get httpd to serve those same Tomcat instances to http://www.example.com:8090/dev and http://www.example.com:8090/demo (8090 cos I've got another app running on 8080 via Jetty at this stage) using the following code in httpd.conf:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel debug
<VirtualHost *:8090>
JkMount /devd* tomcatDev
JkMount /demo* tomcatDemo
</VirtualHost>
What I'm not trying to do is enable SSL.
I've added the following to httpd.conf:
Listen 443
<VirtualHost _default_:443>
JkMount /dev* tomcatDev
JkMount /demo* tomcatDemo
SSLEngine on
SSLCertificateFile "/opt/httpd/conf/localhost.crt"
SSLCertificateKeyFile "/opt/httpd/conf/keystore.key"
</VirtualHost>
But when I try to restart Apache with apachectl restart (yes after shutting down that other app I mentioned so it doesn't toy with https connections) I continuously get the error:
Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration. httpd not running, trying to start
I've looked in the httpd/modules dir and indeed there is no mod_ssl, only mod_jk.so and httpd.exp.
I've tried using yum to install mod_ssl, it says its already installed. Indeed I can locate mod_ssl.so in /usr/lib/httpd/modules but this is NOT the path to where I've installed httpd which is /opt/httpd and in fact /usr/lib/httpd contains nothing but the modules dir.
Can anyone tell me how to install mod_ssl properly for my installed location of httpd so I can get past this error?
I found I needed to enable the SSL module in Apache (obviously prefix commands with sudo if you are not running as root):
a2enmod ssl
then restart Apache:
/etc/init.d/apache2 restart
More details of SSL in Apache for Ubuntu / Debian here.
Are any other LoadModule commands referencing modules in the /usr/lib/httpd/modules folder? If so, you should be fine just adding LoadModule ssl_module /usr/lib/httpd/modules/mod_ssl.so to your conf file.
Otherwise, you'll want to copy the mod_ssl.so file to whatever directory the other modules are being loaded from and reference it there.
Try installing mod_ssl using following command:
yum install mod_ssl
and then reload and restart your Apache server using following commands:
systemctl reload httpd.service
systemctl restart httpd.service
This should work for most of the cases.
I used:
sudo yum install mod24_ssl
and it worked in my Amazon Linux AMI.
I don't know if it is still of interest and if things have changed ever since the thread has been posted, but the /etc/apache2/apache2.conf on my system says:
Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
directories contain particular configuration snippets which manage modules,
global configuration fragments, or virtual host configurations,
respectively.
They are activated by symlinking available configuration files from their
respective *-available/ counterparts. These should be managed by using our
helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
their respective man pages for detailed information.
And on my system the modules are installed in /usr/lib/apache2/modules.
I am running Ubuntu 20.04.2 LTS.