제가 직접 작성한 것은 아니고 최근 이 분야에 새로 스터디를 하고 계신 분들께서 작성한 스크립트를 전달받아 공유합니다.

거친 부분도 있지만 단기간에 작성한 스크립트치고는 완성도가 굉장히 높다고 할 수 있습니다.

첫 번째 예제입니다. 기본 http 포트는 8180 입니다.

 

#! /bin/bash

iHOME=/home/studentA
PORT=8180
FILE=$iHOME/.bashrc #where home_paths will be saved
TOM_VER="7.0.55" #tomcat_version
LINK=http://apache.mirror.cdnetworks.com/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz  #Download link of Tomcat
CAT_PATH1="export CATALINA_HOME=$iHOME/apache-tomcat-$TOM_VER"
CAT_PATH2='export PATH=$PATH:$CATALINA_HOME/bin'
APR_DIR=$APACHE_HOME/bin/apr-1-config
DEF_PORT=8080
let PORT_DIF=$PORT-$DEF_PORT
let AJP_PORT=8009+$PORT_DIF
let SER_PORT=8005+$PORT_DIF

#move to local directory
cd $iHOME

#download apache-tomcat from the link
wget $LINK

#extract the folder
tar -xzvf apache-tomcat-$TOM_VER.tar.gz

#extract the "native connector"
tar -xzvf $CATALINA_HOME/bin/tomcat-native.tar.gz

#set home directories
grep "$CAT_PATH1" $FILE || echo "$CAT_PATH1" >> $FILE
grep "$CAT_PATH2" $FILE || echo "$CAT_PATH2" >> $FILE

#configure
cd /home/studentA/tomcat-native-*/jni/native

#configure cont
./configure --prefix=$CATALINA_HOME --with-apr=$APR_DIR --with-java-home=$JAVA_HOME --with-ssl=yes

#make
make

#make install
make install

#move to bin directory
cd /home/studentA/apache-tomcat-$TOM_VER/bin

#LD Library Path
if [ -e "setenv.sh" ]
    then
        echo file exists
    else
        echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/studentA/apache-tomcat-7.0.55/lib" > setenv.sh
fi

#chaning directory
cd home/studentA/apache-tomcat-7.0.55/conf

#change directory source from webapps to mainWebApp.war
perl -pi -e 's/appBase="webapps"/appBase="mainWebApp.war"/g' server.xml
perl -pi -e 's/autoDeploy="true">/autoDeploy="true"\ xmlValidation="false"\ xmlNamespaceAware="false">\n<Context path=""\ docBase="."\ reloadable="yes"\/>/g' server.xml

#connector Port input from the argument
perl -pi -e "s/<Connector port=\"8080\"\ protocol=\"HTTP\/1.1\"/<Connector port=\"$PORT\" protocol=\"HTTP\/1.1\"/g" server.xml

#port increment

#replacing AJP PORT, Server PORT
perl -pi -e "s/<Connector port=\"8009\"\ protocol=\"AJP\/1.3\"/<Connector port=\"$AJP_PORT\"\ protocol=\"AJP\/1.3\"/g" server.xml
perl -pi -e "s/<Server port=\"8005\"\ shutdown=\"SHUTDOWN\">/<Server port=\"$SER_PORT\"\ shutdown=\"SHUTDOWN\">/g" server.xml