#!/bin/sh #this shell will be installed tomcat*.tar.gz #by wangjiulong #global variables tomcat_pkg=`cat $tmp_tomcat` tomcat_tar=`cat $tmp_tomcat | awk -F.tar.gz '{print $1}'` tomcat_path=/usr/local/tomcat datef(){ date "+%Y/%m/%d %H:%M" ; } #custom log print_log(){ if [[ -d $log_dir ]];then echo "[$(datef)] $1" >> $log else echo "[$(datef)] log path does not exist,created first" >>$log mkdir -p $log_dir echo "[$(datef)] $1" >> $log fi } #檢查本機是否安裝了jdk,若是已經安裝了,則繼續安裝tomcat,否則先安裝jdk,再去安裝tomcat check_jdk_install(){ jdk_local_path=/data/java jdk_local_version=`java -version > /dev/null 2>&1;echo $?` if [ $jdk_local_version -eq 0 ];then print_log "本機jdk已經安裝,能夠安裝繼續安裝tomcat" install_tomcat else #無論是否以前安裝了jdk,默認安裝jdk1.7的 echo "jdk-1.7.0_17.tar.gz" > $tmp_jdk source ./install_jdk.sh fi } #定義tomcat安裝函數 install_tomcat(){ cd $tar_dir tar -zxf $tomcat_pkg -C /usr/local cd /usr/local unlink tomcat ln -s $tomcat_tar tomcat #這裏咱們對tomcat作了優化,如下是替換一些配置文件。 cp -fv $file_dir/server.xml $tomcat_path/conf/server.xml cp -fv $file_dir/logging.properties $tomcat_path/conf/logging.properties cp -fv $file_dir/tomcat /etc/init.d/tomcat cp -fv $file_dir/catalina.sh $tomcat_path/bin/catalina.sh cp -fv $file_dir/cronolog /usr/local/sbin/cronolog chkconfig --add tomcat chmod 755 /etc/init.d/tomcat [ ! -d /data/log/tomcat ] && mkdir -m755 -p /data/log/tomcat echo ' ' >> /etc/profile echo 'export JAVA_HOME=/data/java/jdk' >> /etc/profile echo 'export CALSSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >> /etc/profile echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile add_user } #定義tomcat用戶組函數 add_user(){ print_log "**************** Begin change www user mode *********************" if ! grep "^www" /etc/passwd then groupadd www useradd -g www -s /bin/bash -d /data/www www fi [[ -d /usr/local/tomcat ]] && chown -R www:www /usr/local/tomcat print_log "*************** End change www user mode ************************" finished } #定義安裝成功後的函數 finished(){ # install complete print_log "" print_log "###########################################################" print_log "# [$(datef)] congratulagions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" print_log "# [$(datef)] don't forget to modify configuration files!!!" print_log "# [$(datef)] based on your system resources like mem size " print_log "###########################################################" print_log "" } check_jdk_install
tomcat的安裝相對比較容易,要注意的就是,根據本身業務的實際狀況相應的修改下tomcat配置文件的參數便可。 java