Saturday, June 20, 2015

How To Install JAVA on Linux Platform


Installation of the 64-bit JDK on Linux Platforms

This procedure installs the Java Development Kit (JDK) for 64-bit Linux, using an archive binary file (.tar.gz).
These instructions use the following file:
jdk-8uversion-linux-x64.tar.gz
  1. Download the file.
    Before the file can be downloaded, you must accept the license agreement. The archive binary can be installed by anyone (not only root users), in any location that you can write to. However, only the root user can install the JDK into the system location.
  2. Change directory to the location where you would like the JDK to be installed, then move the .tar.gz archive binary to the current directory.
  3. Unpack the tarball and install the JDK.
    % tar zxvf jdk-8uversion-linux-x64.tar.gz
    
    The Java Development Kit files are installed in a directory called jdk1.8.0_version in the current directory.
  4. Delete the .tar.gz file if you want to save disk space.

Installation of the 64-bit JDK on RPM-based Linux Platforms

This procedure installs the Java Development Kit (JDK) for 64-bit RPM-based Linux platforms, such as Red Hat and SuSE, using an RPM binary file (.rpm) in the system location. You must be root to perform this installation.
These instructions use the following file:
jdk-8uversion-linux-x64.rpm
  1. Download the file.
    Before the file can be downloaded, you must accept the license agreement.
  2. Become root by running su and entering the super-user password.
  3. Uninstall any earlier installations of the JDK packages.
    # rpm -e package_name
    
  4. Install the package.
    # rpm -ivh jdk-8uversion-linux-x64.rpm
    
    To upgrade a package:
    # rpm -Uvh jdk-8uversion-linux-x64.rpm
    
  5. Delete the .rpm file if you want to save disk space.
  6. Exit the root shell. No need to reboot.
Starting with version 8u40, the JDK installation is integrated with the alternatives framework and after installation, the alternatives framework is updated to reflect the binaries from the recently installed JDK. Java commands such as javajavac,javadoc, and javap can be invoked from the command line.
Using the java -version command, users can confirm the default (recently installed) JDK version.
In addition, users can now check which specific RPM package provides the java files:
rpm -q --whatprovides java

Installation of the 32-bit JDK on Linux Platforms

This procedure installs the Java Development Kit (JDK) for 32-bit Linux, using an archive binary file (.tar.gz).
These instructions use the following file:
jdk-8uversion-linux-i586.tar.gz
  1. Download the file.
    Before the file can be downloaded, you must accept the license agreement. The archive binary can be installed by anyone (not only root users), in any location that you can write to. However, only the root user can install the JDK into the system location.
  2. Change directory to the location where you would like the JDK to be installed, then move the .tar.gz archive binary to the current directory.
  3. Unpack the tarball and install the JDK.
    % tar zxvf jdk-8uversion-linux-i586.tar.gz
    
    The Java Development Kit files are installed in a directory called jdk1.8.0_version in the current directory.
  4. Delete the .tar.gz file if you want to save disk space.

Installation of the 32-bit JDK on RPM-based Linux Platforms

This procedure installs the Java Development Kit (JDK) for 32-bit RPM-based Linux platforms, such as Red Hat and SuSE, using an RPM binary file (.rpm) in the system location. You must be root to perform this installation.
These instructions use the following file:
jdk-8uversion-linux-i586.rpm
  1. Download the file.
    Before the file can be downloaded, you must accept the license agreement.
  2. Become root by running su and entering the super-user password.
  3. 3. Uninstall any earlier installations of the JDK packages.
    # rpm -e package_name
    
  4. Install the package.
    # rpm -ivh jdk-8uversion-linux-i586.rpm
    
    To upgrade a package:
    # rpm -Uvh jdk-8uversion-linux-i586.rpm
    
  5. Exit the root shell. No need to reboot.
  6. 5. Delete the .rpm file if you want to save disk space.

Friday, June 12, 2015

How to install apache tomcat as daemon service in Linux environment

Open the terminal and type the below command.
sudo nano /etc/init.d/tomcat

Paste the below script and save the file.

#!/bin/bash
#
# Author : Sree Choudary
# Copyright (c) 2k15
#
# Make kill the tomcat process
#
TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-8.0.23
SHUTDOWN_WAIT=5

tomcat_pid() {
  echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
}

start() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ] 
  then
    echo "Tomcat is already running (pid: $pid)"
  else
    # Start tomcat
    echo "Starting tomcat"
    /bin/sh $TOMCAT_HOME/bin/startup.sh
  fi

  return 0
}

stop() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo "Stoping Tomcat"
    /bin/sh $TOMCAT_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
    count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
      echo -n -e "\nwaiting for processes to exit";
      sleep 1
      let count=$count+1;
    done

    if [ $count -gt $kwait ]; then
      echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
      kill -9 $pid
      echo  " \nprocess killed manually"
    fi
  else
    echo "Tomcat is not running"
  fi

  return 0
}
pid=$(tomcat_pid)

 if [ -n "$pid" ]
  then
    echo "Tomcat is running with pid: $pid"
    stop
  else
    echo "Tomcat is not running"
    start
  fi
exit 0

sudo chmod 755 /etc/init.d/tomcat
update-rc.d tomcat defaults

Finally you can start and stop tomcat using below commands.

service tomcat start
service tomcat stop