Pages

Wednesday, August 20, 2014

Configure Multiple Instances of Apache (HTTPD) on Same Server

There are many cases where I need to work with multiple instances of Apache Server. This article tells you on how to configure multiple instances of Apache on the same server.

1. Duplicate the Http Configuration File
    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd1.conf

2. Duplicate the conf.d location
    cp -pr /etc/httpd/conf/conf.d/  /etc/httpd/conf/conf.d2/

3. Change the PID file Name, Listen port number and include the conf.d2 location
    Change PidFile run/httpd.pid to run/httpd.pid2
    Listen 80 to Listen 81
    Include conf.d2/*.conf

4. Start the Second Instance using
    httpd -f /etc/httpd/conf/httpd1.conf -k start

5. Start the First Instance using
     Start httpd start

We can confirm using “netstat –tulpn | grep 80|81” Or we can access the localhost:80 , localhost:81


More to come, happy learning J
Read More

Oracle HTTP Server

Oracle HTTP Server is the Web server component of Oracle Application Server. It is based on the Apache HTTP Server. Oracle HTTP Server is pre-configured with many modules that
Servers Static and Dynamic Content
Supports Content Generation in many languages
Integrated with oracle web logic server using mod_wl_ohs
Can be used a Proxy Server both Reverse and Forward
Integrated with oracle Web Cache
Supports Oracle Implementation of mod_ssl
Many other Apache modules are bundled

Advantages over Apache
Oracle HTTP server provides more better functionality than Apache Server like,
Better Process management by integrating to OPMN ( Oracle Process manager and Notification Server)
Provides Death Detection and auto-restart
Process are created as,















Both parent and Child Process are treated as one unit , the Parent process is terminated when child process are hung
Integration with Dynamic Monitoring Service which provides performance metrics
Better logging mechanism
Provides integration with Oracle Access Manager
Can Integrate non-oracle Provided modules just like Apache
Oracle PL/SQL ToolKit (mod_plsql) - Execute PL/SQL on DB and return HTML to browsers. Oracle Servlet Engine (mode_ose) - Call Servlets stored in an Oracle DB

Installation
ORACLE_HOME and ORACLE_INSTANCE are 2 important Variables that need to be set. Oracle_Home  location contains the binaries and files that are created at install time and are never changed or updated
Oracle_instances location contains a collection of system components that are managed by OPMN. These are the files that are changed and updated.

Here is the Sequence of steps for the installation
1. Donwload the latest Web Tier Utilities for oracle Downloads ( ofm_webtier_linux_11.1.1.7.0 is the version that iam using)
2. Add Oracle user and oinstall group
[root@localhost ~]# groupadd oinstall
[root@localhost ~]# useradd -g oinstall oracle

[root@localhost ~]# cat /etc/passwd | grep oracle
oracle:x:501:502::/home/oracle:/bin/bash

[root@localhost ~]# cat /etc/group | grep oinstall
oinstall:x:502:

3. Set Limits for Oracle user

vi /etc/security/limits.conf and add

oracle soft nofile 16384
oracle hard nofile 65536

4. Provide the permissions to oracle user where you are installing
chown -R oracle:oinstall /test/u01/app/oracle ( provide your location here )

5. Login as Oracle user , Unzip and execute the “runInstaller” from Disk1 location.
6. It checks for Temp , Swap and Monitor display and once they are passed , it gives us the GUI Console for installing Oracle HTTP Server.
7. Select “Install and Configure” in the “Install and Configure” tab
8. It checks for the Pre-requisites. Make sure all Operating System modules that are necessary are installed like compat-libcap1,libaio-devel etc.
9. Enter the Oracle Middle Ware home and Oracle Home Directory.
10. In the Configure Components, Select “Oracle HTTP Server” and un-check others
11. Provide the Instance Home Location, Instance Name and OHS Component Name
12. Select the Auto Port Configuration.
13. In the next screen it shows all the Configuration information, save the response file for further reference

Once the Installation is complete, add the Env variables as
ORACLE_HOME=/test/u01/app/oracle/middleware/ohs; export ORACLE_HOME
ORACLE_INSTANCE=/test/u01/app/oracle/middleware/ohs/instances/instance1;export ORACLE_INSTANCE

Make sure you provide the location that you installed.

[oracle@localhost bin]$ =/test/u01/app/oracle/middleware/ohs/opmn/bin/opmnctl status
Processes in Instance: instance1
---------------------------------+--------------------+---------+---------
ias-component                    | process-type       |     pid  | status
---------------------------------+--------------------+---------+---------
ohs1                                   | OHS                  |    8201 | Alive

We can use URLs
Oracle HTTP Server URL : http://localhost:7777
Oracle HTTP Server SSL URL : https://localhost:4443

And check whether they are accessible are not.

Issues Faced – While configuring Oracle HTTP server, the pre-requisite check will check for the Monitor

Some times it will fail giving
Checking monitor: must be configured to display at least 256 colors. Actual unknown. <<FAILED

Then make sure you login to root and
DISPLAY=<my ip>:0.0 ; export DISPLAY
root@server [~]# echo $DISPLAY
<my ip>:0.0

Run the xhost command as

[root@localhost ~]# xhost +
access control disabled, clients can connect from any host 

Now login to oracle user and run the installer again.

More to Come, Happy learning :-)
Read More

Thursday, August 7, 2014

Apache Load Balancer Module with Tomcat

Load Balancing is one of the important Aspect when running production servers. Load balancing provides many additional benefits in the production environment. In this article we will see how we can configure Apache Http Server to load balance requests that are going to the back end Tomcat server. For the demo purpose I will have multiple tomcat instances with the same application running on the context and configure apache to load balance requests for the application from Apache server.


1. Make sure to load mod_balancer_proxy.so module ion the httpd.conf file like
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

2. Now Configure the Balancer for the Apache Http server like,

<IfModule proxy_module>
ProxyRequests Off
ProxyPass /myApp balancer://mycluster stickysession=JSESSIONID
ProxyPassReverse /myApp balancer://mycluster stickysession=JSESSIONID

<Proxy balancer://mycluster>
BalancerMember http://localhost:8080/myApp route=jvm1
BalancerMember http://localhost:18080/myApp route=jvm2
</Proxy>

</IfModule>

In the above configuration we have defined our web heads and declaring how they will be balanced. The BalancerMember is how we declare our web heads,

All of this will be wrapped in <Proxy> tags which is how apache knows to send it to mod_proxy, the "balancer://mycluster" identifier is only an identifier, you could technically call it what you want as long as you put the "balancer://" prefix

3. Configure the Back end Tomcat instances. Since we have to test the load balancing, I have configured 2 tomcat instances with port: 8080 and 18080. We also need to change the JVM route to jvm1 and jvm2 respectively.

Deploy the application on both tomcat instances. In the above case I deployed a sample application with the context “myApp”.

Once the configuration is done, restart Apache Http server and the backend Tomcat instances.

We can access the application using https://localhost/myApp

Access the application multiple times and check the access logs in the tomcat instances  and we can see

Tomcat 1
0:0:0:0:0:0:0:1 - - [07/Aug/2014:17:45:46 +0530] "GET /myApp/ HTTP/1.1" 200 415

Tomcat 2
0:0:0:0:0:0:0:1 - - [07/Aug/2014:17:45:04 +0530] "GET /myApp/ HTTP/1.1" 200 41

We can see from the above access logs ,that the request is being processed by both tomcat instances

Optional Step

This is a tool packaged with the mod_proxy_balancer tool, and allows you to make configurations from a gui tool through the web browser. Viewable at "http://domain.com/balancer-manager", keep in mind that these changes die after you restart apache. I won't go over how to use this tool, but it is available to you.For this to work we need to add the below statements to http.conf file

<Location /balancer-manager>
   SetHandler balancer-manager
</Location>


More to Come ,Happy Learning
Read More

Apache Server Status – mod_status module

In a production environment we will be maintaining many number of Apache instances for processing the user requests. It is hard for a administrator to manage these multiple instances of the apache servers.

Apache provide various numbers of modules for various operations. There is one module called mod_status.so which provides out-of-the-box functionality for monitoring the performance of Apache installations. In this article we will see how we can configure the mod_status module and how we can read the status.

1. Make sure the mod_status module is loaded like
LoadModule status_module modules/mod_status.so

2.Configure Apache configuration like

ExtendedStatus On

<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from localhost 172.16.101.228
</Location>

3. Now we can access http://localhost/server-status which will give various information regarding the Apache instances like,

We can also use http://localhost/server-status?refresh=15 which will make the status page refresh for every 15 seconds.

The header contains basic information about the Apache installation like

Server Version: Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3
Server Built: Apr 9 2011 08:58:28


There is a status summary containing basic status information like,

Current Time: Thursday, 07-Aug-2014 17:15:35 IST
Restart Time: Thursday, 07-Aug-2014 16:57:40 IST
Parent Server Generation: 0
Server uptime: 17 minutes 55 seconds
Total accesses: 10 - Total Traffic: 34 kB
CPU Usage: u0 s0 cu0 cs0
.0093 requests/sec - 32 B/second - 3481 B/request
1 requests currently being processed, 7 idle workers

__W_____........................................................
.......................................................................
.......................................................................
.......................................................................


The bottom of the status page contains information about current requests like,

Srv   PID   Acc     M      CPU   SS Req Conn  Child  Slot Client VHost Request
0-0 19126 0/2/2 _ 0.00 45     0   0.0  0.01   0.01 localhost localhost.localdomain GET /server-status?refresh=15 HTTP/1.1

The mod_status module helps us to obtain various information about the Apache Installations.

More to Come, happy Learning :-)
Read More

Tuesday, August 5, 2014

Reverse Proxy with apache Web Server and Tomcat

A proxy is a piece of software that supports sending and receiving data on behalf of another application. It’s an intermediate layer on your network that receives requests from within the networks, forwards them to the appropriate host, reads the response, and sends the response back to the requesting host or application within the network.

There are 2 types of proxy available,
  • A forward proxy is an Internet-facing proxy used to retrieve from a wide range of sources.
  • reverse proxy is usually an Internet-facing proxy used as a front-end to control and protect access to a server on a private network. A reverse proxy commonly also performs tasks such as load-balancing, authentication, decryption or caching.

In this article we will see how we can configure Apache as a Proxy server that will connect to the back end Tomcat Servers. For the demo purpose I have deployed 2 applications in the back end Tomcat server.

1. Build Apache server with Proxy modules

Download the Apache HTTP server source
$ tar -xzvf httpd-2.0.36.tar.gz
$ cd /httpd
$ ./configure –enable-module=proxy
If you’re using Apache 2.0, you should use this instead:
$ ./configure –enable-proxy –enable-proxy-ftp –enable-proxy-http –enable-cache –enable-disk-cache
Once the source tree has been prepped, you can compile and install Apache with a quick
$ make
$ make install

2. Add Configurations to the Apache http.conf
a. make sure the LoadModule for the mod_proxy.so is added like

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so


b. add the virtual host element

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    ServerName dummy-host.example.com
    ErrorLog logs/dummy-host.example.com-error_log
    CustomLog logs/dummy-host.example.com-access_log common
    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy *>
     Order deny,allow
     Allow from all   
</Proxy>

  ProxyPass /application1 http://localhost:8080/myApp/
  ProxyPass /application2 http://localhost:8080/Sample-app/test.html
  ProxyPassReverse /application1/ http://localhost:8080/myApp/
  ProxyPassReverse /application2/ http://localhost:8080/Sample-app/test.html
</VirtualHost>

ProxyRequest  and ProxyPassReverse are the 2 elements that make the Reverse Proxy work.

# Disable forward proxy requests
ProxyRequests Off

# Configure reverse proxy requests for myApp
ProxyPass /application1 http://localhost:8080/myApp/
ProxyPassReverse /application1/ http://localhost:8080/myApp/

So now we have configured /application1 in Web server and when we access
http://localhost/application1 the web server will send the requests to
http://localhost:8080/myApp/ which is running in back end Tomcat.

ProxyPass allows you to is basically take a request for a URL, and forward it to another(Usually backend) server. Then it forwards the response back to the client .The last ProxyPassReverse directive captures the responses from the Tomcat server and masks the URL as it would be directly responded by the Apache HTTPd hiding the identity/location of the Tomcat server.


More to Come , Happy Learning J
Read More

Apache Server Integration with Weblogic Cluster

In this article we will see how we can configure Apache server with a weblogic Cluster and access a application deployed in the weblogic cluster.

1. Configure weblogic Cluster with the below nodes as below
MS1:17003
MS2:17004

2. Once the Configuration of the Servers is completed, add them to a cluster and deploy a sample application to the cluster (in this case I deployed a sample application which will print the session ID on the screen)

3. Configure the Apache server as
a. Make sure the mod_wl weblogic .so file is added as
LoadModule weblogic_module modules/mod_wl_22.so
b.Make sure the Location element is added as
<Location />
SetHandler weblogic-handler
</Location>

C. Configure the <IfModule> element with the necessary information as
<IfModule mod_weblogic.c>
WeblogicCluster localhost:17003,localhost:17004
Debug ON
WLLogFile /tmp/wlproxy.log
WLTempDir /tmp
MatchExpression /*
DebugConfigInfo ON
KeepAliveSecs 15
DynamicServerList ON
</IfModule>

We have added the localhost:17003 and localhost:17004 which are the cluster address that we configured.

Now access the application that we deployed in the cluster using apache server URL.

More to Come , Happy learning J

Read More

Monday, August 4, 2014

Apache Server Basic Authentication with Weblogic

In this article we will see how to configure basic Authentication in Apache server which will allow to ask for a user name and password.

1. Create a file in a location like myuser.txt. add the contents
testuser:testuser

This the user name and password combination

2. Now once the file is created we need to encrypt the password using using the htpasswd command like

[root@localhost conf]# htpasswd -b myuser.txt testuser testuser
Updating password for user testuser

Now check the file and we can see the encrypted password as
[root@localhost conf]# cat myuser.txt
testuser:PtNHnFwOxljvM

3. Configure the httpd.conf file with the basic Authentication as

<Location />
SetHandler weblogic-handler
AuthUserFile /etc/httpd/conf/myuser.txt
AuthName "This is a Protected Area"
AuthType Basic
Require valid-user
</Location>

<IfModule mod_weblogic.c>
#WebLogicCluster 172.16.101.241:7003,172.16.101.241:7004
WeblogicCluster localhost:17003,localhost:17004
#WebLogicCluster MS1:17003,MS2:17004
Debug ON
WLLogFile /tmp/wlproxy.log
WLTempDir /tmp
MatchExpression /*
DebugConfigInfo ON
KeepAliveSecs 15
DynamicServerList ON

</IfModule>

The four parameters in the <Location> element are the one that allow apache to ask for a User Name and Password combination. Once the user name and password are provided the request is passed to the backed weblogic but we need to add a parameter in the weblogic config.xml. The parameter needs to be added Otherwise Weblogic Server will try to validate the BASIC authentication Header. The problem is that if there is some request to your application with "Authorization" header the request will be intercepted by Weblogic itself and will not be passed to your application. Weblogic will try to make authentication itself.


Happy learning, More to Come
Read More