Installing Tomcat 7 on CentOS 5.8

Download and Install

  • Download Tomcat 7.0.x:

    wget http://tux.rainside.sk/apache/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.zip
    
  • Unzip:

    unzip apache-tomcat-7.0.35.zip
    
  • Copy to /opt:

    cp -t /opt apache-tomcat-7.0.35 -R 
    
  • Create a softlink to the latest version:

    ln -s /opt/apache-tomcat-7.0.35 /opt/tomcat
    

Configure tomcat user

  • Create an user and a group:

    useradd tomcat
    groupadd tomcat
    useradd -G tomcat tomcat
    

    Some variants of useradd may create a group along with user. In that case, you will see a warning and the useradd -G tomcat tomcat is not necessary.

    groupadd: group 'tomcat' already exists
    
  • Check whether it’s working:

    id tomcat
    

    Output should be something along:

    uid=501(tomcat) gid=501(tomcat) groups=501(tomcat) context=root:system_r:unconfined_t:SystemLow-SystemHigh
    

Change ownerships

  • Change the ownership of /opt/tomcat...

    chown -Rf tomcat:tomcat /opt/apache-tomcat-7.0.35
    

Configure init script

  • Create and edit the init script:

    nano /etc/init.d/tomcat
    
  • Add contents:

    #!/bin/sh
    #
    # Startup script for the Tomcat Java Servlets and JSP server
    #
    # chkconfig: 234 85 15
    # description: Tomcat Java Servlets and JSP server
    # processname: tomcat
    # pidfile: /var/run/tomcat.pid
    # config:
    
    CATALINA_HOME=/opt/tomcat; export CATALINA_HOME
    TOMCAT_OWNER=tomcat; export TOMCAT_OWNER
    JAVA_OPTS="-Xms128M -Xmx512M"; export JAVA_OPTS
    
    start() {
      echo -n "Starting Tomcat:  "
      su $TOMCAT_OWNER -c $CATALINA_HOME/bin/startup.sh
    
    }
    stop() {
       echo -n "Stopping Tomcat: "
       su $TOMCAT_OWNER -c $CATALINA_HOME/bin/shutdown.sh
    }
    
    ##
    
    case "$1" in
    start)
      start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    *)
       echo $"Usage: tomcat {start|stop|restart}"
       exit
    esac
    
  • Set executable permission:

    chmod +x /etc/init.d/tomcat
    
  • Add to chkconfig

    chkconfig --add tomcat  
    chkconfig --level 234 tomcat on  
    
  • Verify that the chkconfig went successfully.

    chkconfig --list tomcat 
    

    You will see:

    tomcat          0:off   1:off   2:on    3:on    4:on    5:off   6:off
    

Configure firewall

  • Use system configuration GUI (text-based) to add 8080 and 8443 ports to iptables firewall.

    system-config-firewall-tui
    

Run the Tomcat

service tomcat start        

Optional Tasks

Symlink logs to /var/log

ln -s /opt/tomcat/logs /var/log/tomcat7

Disable unnecessary default web-apps

mkdir /opt/tomcat/webapps-disabled

cp -R -t /opt/tomcat/webapps-disabled /opt/tomcat/webapps/*
rm -rf /opt/tomcat/webapps/* 

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *