Install Apache Tomcat Native

Steps to install apache tomcat native and its dependencies

If you are using Apache Tomcat in production then it would be good to install Apache Tomcat native library as it has some optimizations for production use. Below are the steps to install it. The steps were performed on an AWS EC2 instance (Amazon Linux), but should work on most of the linux systems.

  • If you are on an amazon box then login as root and change directory to /opt. This is where we will install the tomcat instance. For everyone else, use whatever user you want the tomcat to run as.
    sudo su -
    cd /opt
  • Download and Install Apache Tomcat

    Download apache tomcat. We will use using the 8.5.16 version. Extract it. The native source code is in the bin directory. Extract it as well.

    wget http://mirror.intergrid.com.au/apache/tomcat/tomcat-8/v8.5.16/bin/apache-tomcat-8.5.16.tar.gz
    tar -xvf apache-tomcat-8.5.16.tar.gz
    cd apache-tomcat-8.5.16/bin/
    tar -xvf tomcat-native.tar.gz
    
  • The native library requires openssl and APR (Apache portable runtime). Lets install those. we will install them in a directory called /opt/softwares. You can install it in any directory that you like.

    cd /opt
    mkdir softwares
    cd softwares
    
  • Install Java (JDK) [/h2]

    cd /opt
    wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.rpm
    sudo yum install -y jdk-8u141-linux-x64.rpm
    

  • Install the development tools for building the various libraries

     
    yum groupinstall "Development Tools"
  • Download and install openssl

    cd /opt/softwares
    wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
    tar -xvf openssl-1.0.2l.tar.gz
    cd openssl-1.0.2l
    ./config -fPIC --prefix=/opt/software/ --openssldir=/opt/software/
    make
    make install
    
  • Install APR (Apache Portable Runtime)

    cd /opt/softwares/
    wget http://apache.mirror.amaze.com.au//apr/apr-1.6.2.tar.gz
    tar -xvf apr-1.6.2.tar.gz
    cd apr-1.6.2
    ./configure --prefix=/opt/software/
    make 
    make install
    
  • Install Tomcat Native

    cd /opt/apache-tomcat-8.5.16/bin/tomcat-native-1.2.12-src/native/
    ./configure --with-apr=/opt/software/ --with-java-home=/usr/java/jdk1.8.0_141/  --with-ssl=/opt/software/  --prefix=/opt/apache-tomcat-8.5.16
    make
    make install
    
  • The last step is to set up the environment so that apache tomcat runtime can find the native libraries.
    Add the entries below into the setenv.sh file. A new file will be created if not present already.

    vi /opt/apache-tomcat-8.5.16/bin/setenv.sh
    export JAVA_HOME=/usr/lib/jvm/java-1.8.0
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
    export LD_LIBRARY_PATH
    

    Lets start the bean and see how it looks

    /opt/apache-tomcat-8.5.16/bin/startup.sh
    

    If all goes well, you should be able to see this in the output

    cat  /opt/apache-tomcat-8.5.16/logs/catalina.out | more
    ......
    09-Aug-2017 00:45:44.312 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.12] using APR version [1.6.2].
    09-Aug-2017 00:45:44.313 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
    09-Aug-2017 00:45:44.313 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
    09-Aug-2017 00:45:44.320 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2l  25 May 2017]
    

1 thought on “Install Apache Tomcat Native”

Leave a Comment