Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Monday, June 29, 2015

Two instances of Apache HTTPD

This write up is about running multiple instances of Apache HTTPD on a Linux system. I tested by running two instances but I understand similar approach would work if more than two instances are required to run independently on a Linux system.

One can easily setup more than one instance by installing two or more HTTPD servers but this piece of writing is not about that rather it talks about how one can copy/modify an existing set of files from a running Apache HTTPD server and set up a completely independent HTTPD instance.

Here is how;
[ It assumed that one HTTPD server is installed by yum and is existing on the system. If not, then install it by yum as; yum install httpd. ]

1. Copy all the files /etc/httpd to a location of your choice. Provide a different name for the
         destination e.g. httpd2
# cp -a /etc/httpd /etc/httpd2

2. Copy the existing httpd init script as;
# cp /etc/init.d/httpd /etc/init.d/httpd2

3. Copy the existing sysconfig file for httpd as;
# cp /etc/sysconfig/httpd /etc/sysconfig/httpd2

4. Copy existing 'apachectl' as;
       cp -a /usr/sbin/apachectl /usr/sbin/apachectl2

5. Edit '/usr/sbin/apachectl2' as;
if [ -r /etc/sysconfig/httpd2 ]; then
    . /etc/sysconfig/httpd2
fi

6. Create soft link as;
# ln -s /usr/sbin/httpd /usr/sbin/httpd2

7. Edit the following  /etc/sysconfig/httpd2 as;
HTTPD=/usr/sbin/httpd2
OPTIONS="-f /etc/httpd2/conf/httpd.conf"
LOCKFILE=/var/lock/subsys/httpd2
PIDFILE=/var/run/httpd2/httpd2.pid

8. Edit /etc/init.d/httpd2 as;

if [ -f /etc/sysconfig/httpd2 ]; then
         . /etc/sysconfig/httpd2
fi

      And, also;
prog=httpd2

9. Edit the following in "/etc/httpd2/conf/httpd.conf" as;
a. Listen 90
b. ServerRoot "/etc/httpd2"
c. PidFile run/httpd2.pid
d. DocumentRoot "/opt/httpd2"
(Change this to your need)
e.


10. Do the following;
      a. # cd /etc/httpd2
b. # mkdir -p /var/run/httpd2
# chgrp apache /var/run/httpd2

      c. Remove the old link and create a new one with the current path;
# rm run
# ln -s /var/run/httpd2 run
d. # mkdir -p /var/log/httpd2
e. # rm logs
f. # ln -s /var/log/httpd2/ logs

11. Start the services;
[root@Fedora-14 httpd2]# service httpd start
Starting httpd:                                    [  OK  ]
[root@Fedora-14 httpd2]# service httpd2 start
Starting httpd2:                                   [  OK  ]

12. Check if the ports are listening;
[root@Fedora-14 httpd2]# netstat -apn | grep httpd
tcp        0      0 :::80        :::*       LISTEN      5390/httpd        
tcp        0      0 :::90        :::*       LISTEN      5413/httpd2

13. Check service status;
[root@Fedora-14 httpd2]# service httpd2 status
httpd2 (pid  5413) is running...
[root@Fedora-14 httpd2]# service httpd status
httpd (pid  5390) is running...

14. Stop the services;
[root@Fedora-14 httpd2]# service httpd stop
Stopping httpd:                                    [  OK  ]
[root@Fedora-14 httpd2]# service httpd2 stop
Stopping httpd2:                                   [  OK  ]

Friday, September 12, 2014

Installing Java-7 and Apache Tomcat/8.0.12 on CentOS-6.5


I. JAVA:

1. Search JDK in the yum repositories;

# yum search java | grep -i --color JDK
ldapjdk-javadoc.x86_64 : Javadoc for ldapjdk
icedtea-web.x86_64 : Additional Java components for OpenJDK - Java browser
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
ldapjdk.x86_64 : The Mozilla LDAP Java SDK

2. Once found, install the required version (if the search does yield any result then please download
         and install manually).

# yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel

3. Check if there are already installed versions of Java;

# alternatives --config java

There is 1 program that provides 'java'.

Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java

Enter to keep the current selection[+], or type selection number:

4. Set JAVA_HOME varaiable and include Java binaries in the system PATH;

# vi /etc/profile

## Set JAVA_HOME
JAVA_HOME="/usr/lib/jvm/jre-1.7.0-openjdk.x86_64"
export JAVA_HOME

## Set JAVA Path
PATH=$PATH:/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin

5. Execute the file so that the new changes are reflected on the system;
# source /etc/profile

6. Test Java:
A. # echo $JAVA_HOME
/usr/lib/jvm/jre-1.7.0-openjdk.x86_64

B. # cat > HelloWorld.java
  public class HelloWorld {
public static void main(String[] args) {
         System.out.println("Hello, World! ");
    }
  }

# javac HelloWorld.java
# java HelloWorld
Hello, World!

II. Apache Tomcat

1. Download Apache Tomcat/8.0.12:
# wget http://apache.mirrors.pair.com/tomcat/tomcat-8/v8.0.12/bin/apache-tomcat-8.0.12.tar.gz

2. Extract:
# tar -xvzf apache-tomcat-8.0.12.tar.gz

3. I moved the extracted directory under /usr/local;
# mv apache-tomcat-8.0.12 /usr/local/

4. # /usr/local/apache-tomcat-8.0.12/bin/startup.sh
Using CATALINA_BASE:   /usr/local/apache-tomcat-8.0.12
Using CATALINA_HOME:   /usr/local/apache-tomcat-8.0.12
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-8.0.12/temp
Using JRE_HOME:        /usr/lib/jvm/jre-1.7.0-openjdk.x86_64
Using CLASSPATH:       /usr/local/apache-tomcat-8.0.12/bin/bootstrap.jar:/usr/local/apache-
        tomcat-8.0.12/bin/tomcat-juli.jar
Tomcat started.