Showing posts with label apache web server. Show all posts
Showing posts with label apache web server. Show all posts

Friday, October 30, 2015

How to configure sticky sessions between Apache web server and Tomcat application server

Why sticky sessions?

Imagine you have a Apache server which load balances between two tomcat servers(tomcat1 and tomcat2) in the backend, With the use of sticky sessions, When the user sends the first request, If apache routes it to tomcat1, It will keep on sending the other requests made by the same user to the same server. If the tomcat1 is down, Then the user will be forwared to tomcat2 and will be asked to login again as the session information is lost in the tomcat1.

When you use sticky session with session replication, This issue will be solved. Considering the above scenario, When the tomcat1 is down, The session will be carried over to the tomcat2 and the user will still be able to continue the work with out any disruption.

Implementation :

Sticky sessions can be implemented in many ways, out of which I am listing the configuration with proxy and configuration with worker.properties.

Configuration with mod_proxy:

After the installation of apache, Open the http.conf file, Enable the mod_proxy.so, mod_proxy_http.so and proxy_balancer_module.

LoadModule proxy_module mod_proxy.so
LoadModule proxy_http_module mod_proxy_http.so
LoadModule proxy_balancer_module 

<IfModule mod_proxy_balancer.c>
    ProxyPass /context balancer://tomcatcluster/context stickysession=JSESSIONID|jsessionid
    <Proxy balancer://tomcatcluster>
        BalancerMember http://tomcatlocalhost:9080 route=tomcatroute1
        BalancerMember http://tomcatlocalhost:9081 route=tomcatroute2
    </Proxy>
</IfModule>


Once this configuration is done in apache, Save the httpd.conf and restart the server.

After tomcat server installation, open the server.xml and ensure http connector port is same as the port that is defined in the cluster properties of apache configuration file. For sticky sessions, Ensure that the jvm route value is same as the route value in the httpd.conf file.


tomcatroute1 worker:


<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcatroute1">
</Engine>
<Connector port="9080" protocol="org.apache.coyote.http11.Http11Protocol" ... />

tomcatroute2 worker:


<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcatroute2">

</Engine>
<Connector port="9081" protocol="org.apache.coyote.http11.Http11Protocol" ... />


Save the configuration, Now the sticky sessions are configured.

Configuration with worker.properties:

The tomcat configuration will be same as above, Only the apache configuration would differ.

add the following configuration in httpd.conf.

LoadModule jk_module mod_jk.so
<IfModule mod_jk.c>
JkLogFile logs/mod_jk.log
JkLogLevel debug
JkShmFile logs/jk-runtime-status
JkWorkersFile conf/workers.properties

JkMount /context loadbalancer
JkMount /context/* loadbalancer
</IfModule>

In the worker.properties file, Add the following configuration:

worker.list=loadbalancerworker.tomcatroute1.port=9080worker.tomcatroute1.host=localhostworker.tomcatroute1.type=ajp13worker.tomcatroute1.lbfactor=1worker.tomcatroute2.port=9081worker.tomcatroute2.host=localhostworker.tomcatroute2.type=ajp13worker.tomcatroute2.lbfactor=1worker.loadbalancer.type=lbworker.loadbalancer.balanced_workers=tomcatroute1,tomcatroute2

Monday, January 05, 2015

make_sock: could not bind to address 0.0.0.0:443 no listening sockets available

The following error is displayed when you are trying to start the IHS webserver.

Error :



(98)Address already in use: make_sock: could not bind to address [::]:443
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443
no listening sockets available, shutting down
Unable to open logs



Root Cause :

This error will be displayed when you are trying to start the webserver on 443 port when it is already listening. First you need to check if 443 is listening with the httpd processes running.

If 443 port is listening and you don't see httpd processes running, Then use the following script to check which pid is still listening on 443 and kill the pid. This should free the port.

http://serversideposts.blogspot.in/2014/04/admu3028i-conflict-detected-on-port.html

If 443 port is not listening and you don't see httpd process running. The most probable cause is that you have defined the listen 443 directive twice in httpd.conf file. Check the httpd.conf file for all the 443 port declarations. There has to be only one 443 declaration. Incase if you declared it twice the server will initially start the process on 443 with the first line and will try to start the process again on the second line of 443 declaration. Hence the server will fail as it is already listening and will bring down the server.

Thursday, October 30, 2014

httpd: Could not reliably determine the server's fully qualified domain name


Error:  
httpd: Could not reliably determine the server's fully qualified domain name, using <IP address> for ServerName


Solution:  Add the ServerName parameter in the httpd.conf file as shown below and restart the server.

ServerName <hostname>:80


Configure qslog with Apache (2.2.24)


Description:

The qslog tool, which is part of the support utilities of mod_qos, may be used to gather request statistics from Apache's access log data. This includes data such as the number of denied requests or new VIP session creations per minute but also total requests per second and other data.

These support utilities will be available in the src folder of mod_qos installable.

ex:  /softwares/mod_qos-10.29/tools/src contains qslog,qslog.c,qslog.o

Installation and configuration of qslog:

In case, If you have not configured mod_qos.so module with Apache, then click on steps to install and configure mod_qos with Apache 2.2.24.

Following are the steps to install and configure the qslog with apache: 
  
export LD_LIBRARY_PATH=/usr/lib:/usr/sfw/lib
export LD_LIBRARY_PATH_64=/usr/lib/64:/usr/sfw/lib/64
export CC=gcc
export CFLAGS='-m64 -O3'
export CPP_FLAGS='-m64 -O3'
export LDFLAGS="-L/usr/sfw/lib -R/usr/sfw/lib"

./configure --prefix=/apache_path --with-apr=/apr-1.4.6 --with-apr-util=/apr-util-1.4.1 --with-pcre=/pcre

make

make install

After the completion of make install the qslog script will be created in bin folder of the apache.

Making install in src
test -z "/opt/web/apache_fp/apache/bin" || .././install-sh -c -d "/apache/bin"
  .././install-sh -c qsfilter2 qslog qspng qsrotate qssign qstail qsgrep qsexec qscheck qsgeo qslogger qshead 'apache/bin'

Configuration in the httpd.conf log:

LogFormat "%t %h \"%r\" %>s %b \"%{User-Agent}i\" %T"
TransferLog "|/apache/bin/qslog -f ..IRSB.T -o /apache/logs/stat_log"

Errors:

Incase if the following error is seen in the logs after installing the apache

piped log program 'apache/bin/qslog -f ..IRSB.T -o /apache/logs/stat_log' failed unexpectedly
ld.so.1: qslog: fatal: libapr-1.so.0: open failed: No such file or directory
Killed

Add the APR and APR lib folder path to the LD_LIBRARY_PATH variable.


                                                                         (: Happy learning :)






Wednesday, September 24, 2014

How to create service for apache webserver in windows manually


Incase if you have not chosen "Add as a service" option during the Apache or IHS installation, Then you will have to add the Apache service manually to the windows services. This would start and stop the webserver automatically during the windows reboot.

Following steps will guide you to manually create a service for apache webserver in windows.

Commands:

To create a service:

Syntax:  sc <server> create [service name] [binPath= ] <option1> <option2> ..

sc.exe create "servicename" binPath= "E:\bin\httpd -k runservice" DisplayName= "somename" start= auto

ex: sc.exe create apacheservice binPath= "E:\bin\httpd -k runservice" DisplayName= "Apacheservice" start= auto

Following message will indicate a successful service creation.

[SC] CreateService SUCCESS

NOTE: Ensure that there is a space after the "=" symbol or else the command will fail. Following message will be displayed in case of wrong syntax.


To Delete a service:  

sc.exe delete apacheservice 

[SC] DeleteService SUCCESS 

Testing:

go to run prompt, type service.msc. The newly created service will be visible. You can right click and change the properties, start and stop the service.

This similar exercise can be used for other services as well, Only the command will differ. 

                                 (: Happy learning :)


Wednesday, April 16, 2014

Boot level script for apache webserver

Following steps will guide you setup the run level scritps to start and stop the Apache web server during the OS reboot.

Prepare a script to start and stop the server with "start" and "stop" as the input parameters to the script.

You can edit the following and customize it with your own paths.

#!/bin/sh

case "$1" in
'start')
        /apache/bin/httpd -k start
        ;;
'stop')
        /apache/bin/httpd -k stop
        ;;
*)
        echo "Usage: /etc/init.d/apache_start { start | stop }"
        ;;
esac

Name the above script as apache_start.

Place the apache_start in /etc/init.d folder

The run level scripts for apache have to be placed under rc0.d and rc3.d.

To get to know which run level is configured in your OS type the following command.

Who -r


This screen shot shows that 3 and 0 are the run levels for the OS.

Hence the /etc/rc3.d has to contain the startup script and /etc/rc0.d has to contain the stop script.

Navigate to /etc/rc3.d and create a softlink to the script in /etc/init.d, Repeat the same for /etc/rc0.d

Choose a sequence ex: for the start script S18apachestart and stop script K18apachestop.

Now, When ever the OS reboots, The apache will stop and start automatically.

Feel free to comment if you need any further help.

                                 (: Happy learning :)

Tuesday, February 25, 2014

Invalid command "*", perhaps misspelled or defined by a module not included in the server configuration - apache on solaris

Following errors are displayed while starting the Apache server if the appropriate modules are not loaded in the configuration file:

 Invalid command 'User', perhaps misspelled or defined by a module not included in the server configuration - load module mod_unixd
LoadModule unixd_module modules/mod_unixd.so

Invalid command 'AddType', perhaps misspelled or defined by a module not included in the server configuration - load module mod_mime
LoadModule mime_module modules/mod_mime.so

Invalid command 'DirectoryIndex', perhaps misspelled or defined by a module not included in the server configuration - load module mod_dir
LoadModule dir_module modules/mod_dir.so

Invalid command 'DirectoryIndex', perhaps misspelled or defined by a module not included in the server configuration - load module mod_access_compat.so
LoadModule unixd_module modules/mod_unixd.so

Invalid command 'ProxyTimeout', perhaps misspelled or defined by a module not included in the server configuration - load module mod_proxy.so
LoadModule proxy_module modules/mod_proxy.so

ProxyPass Can't find 'byrequests' lb method - load module mod_lbmethod_byrequests.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so

ProxySet: unknown lbmethod lbmethod=bybusyness; balancer://cluster - load module mod_lbmethod_bybusyness.so
LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so

Invalid command 'LogFormat', perhaps misspelled or defined by a module not included in the server configuration -load module mod_log_config.so
LoadModule log_config_module modules/mod_log_config.so

Invalid command 'ScriptLog', perhaps misspelled or defined by a module not included in the server configuration - load module mod_cgid.so
LoadModule cgid_module modules/mod_cgid.so

Invalid command 'Alias', perhaps misspelled or defined by a module not included in the server configuration - load module mod_alias.so
LoadModule alias_module modules/mod_alias.so

Configuration error: couldn't check user: /path - load module mod_authz_core.so
LoadModule authz_core_module modules/mod_authz_core.so