Tuesday, September 09, 2014

Tomcat 7 Linux CentOS installation


Tomcat 7 Linux CentOS installation


# get app
Get Tomcat7
wget http://www.eu.apache.org/dist/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz

# check md5
md5sum apache-tomcat-7.0.55.tar.gz
xmd5sum=3c46fc0f608c1280dcd65100a983f285
echo -n Checking md5 ...' '
if [ "`md5sum apache-tomcat-7.0.55.tar.gz | awk '{print $1}'`" != "$xmd5sum" ] ; then echo INCORRECT md5! Exiting. ; exit 1 ; else echo md5 OK ; fi

# add user
echo Adding users
groupadd tomcat7
useradd -s /bin/bash -g tomcat7 tomcat7

# unpack
echo Unpacking Tomcat
tar -zxf apache-tomcat-7.0.55.tar.gz
mv apache-tomcat-7.0.55 /opt/
ln -s apache-tomcat-7.0.55 /opt/tomcat7
chown -Rf tomcat7.tomcat7 /opt/apache-tomcat-7.0.55



# create init script
echo Creating init script

cat > /etc/init.d/tomcat7 <<EOF
#!/bin/bash
#
# Tomcat 7
#
# chkconfig: 234 80 20
# description:  Start up the Tomcat servlet engine.
# Source function library.
. /etc/init.d/functions
RETVAL=$?
CATALINA_HOME="/opt/tomcat7"
# export JAVA_HOME=/usr/java/latest
case "$1" in
 start)
  if [ -f $CATALINA_HOME/bin/startup.sh ];
   then
    echo $"Starting Tomcat"
    /bin/su -s /bin/bash tomcat7 $CATALINA_HOME/bin/startup.sh
  fi
  ;;
 stop)
  if [ -f $CATALINA_HOME/bin/shutdown.sh ];
   then
    echo $"Stopping Tomcat"
     /bin/su -s /bin/bash tomcat7 $CATALINA_HOME/bin/shutdown.sh
  fi
  ;;
 *)
  echo $"Usage: $0 {start|stop}"
  exit 1
  ;;
esac
exit $RETVAL
EOF
# end of init script



# register init script
chmod a+x /etc/init.d/tomcat7
chmod 755 /etc/init.d/tomcat7

# register init script
echo Registering Tomcat7 to run on system startup
chkconfig --level 234 jboss off
chkconfig --add tomcat7
chkconfig --level 234 tomcat7 on

# Final message
echo
echo Installation DONE
echo
echo To start Tomcat7 service, type:
echo service tomcat7 start
echo
echo To stop Tomcat7 service, type:
echo service tomcat7 stop
echo

# make tomcat users
# source http://tecadmin.net/steps-to-install-tomcat-server-on-centos-rhel/
cat > /opt/tomcat7/conf/tomcat-users-example.xml <<EOF
<!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="manager" password="manager_password" roles="manager-gui" />
<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="admin" password="admin_password" roles="manager-gui,admin-gui" />
EOF


No comments: