A-A+
批量修改tomcat配置
shell功能概述:
使用svn管理tomcat版本,然后根据指定tomcat版本号、tomcat端口号、tomcat进程同时添加utf-8编码,生成对应的压缩包版本tomcat;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
#!/bin/bash #$1 tomcat_version $2 tomcat_JAVA_HOME #调用当前shell时需要传入的参数 第一个tomcat版本 这里配置的是7 和8版本,第二个参数是JAVA_HOME set -e #出错即停止 #update_tomcat() $1=$WD $2=$TOMCAT_V #这个方法需要传的参数 #copy_tomcat() $1=$WD $2=$TOMCAT_V $3=TOMCAT_PROC_PORT #TOMCAT_PROC_PORT => 对应关系: process_name shutdown_port http1.1_port AJP_port WORKDIR=/tmp/soft if [ $# -gt 0 ];then n=$1 else read -p "tomcat 大版本号[7\8]:" n fi JAVA_HOME="$2" JRE_HOME="$3" DATE=$(date -I) WD=$WORKDIR/$DATE #svn 的用户名密码,为方便tomcat原始版本管理,我把原始版本的tomcat放在svn上。 USER=admin PASSWD=123456 TOMCAT_DIR=$WORKDIR/$DATE #TOMCAT_NAME=`ls $TOMCAT_DIR` REPOS=/repos TOMCAT_REPOS=/repos/tomcat$n COMMON_OPTS="JAVA_OPTS='-Xms1024M -Xmx1024m -XX:MaxNewSize=128m -XX:MaxPermSize=256m -XX:PermSize=128M'" MEM_ORDER_ERP_OPTS="JAVA_OPTS='-Xms2048M -Xmx2048m -XX:MaxNewSize=128m -XX:MaxPermSize=256m -XX:PermSize=128M'" SHOP_OPTS="JAVA_OPTS='-Xms512M -Xmx512m -XX:MaxNewSize=128m -XX:MaxPermSize=256m -XX:PermSize=128M'" #TOMCAT_PROC_PORT=(base erp ext mem order pos sys wd) 下面我定义了一个数组,解释下 例如base-8100-8101-8183 这个就是一个tomcat的进程以及三个端口的参数,后面会用awk截取出来 TOMCAT_PROC_PORT=(base-8100-8101-8183 erp-8102-8103-8186 mem-8106-8107-8187 order-8108-8109-8185 pos-8110-8111-8188 sys-8112-8113-8181 wd-8114-8115-8190 shop-8116-8117-8189 vm-8118-8119-8182 extdata-8120-8121-8184) update_tomcat() { cd $1 tar -zxf apache-tomcat-$2.tar.gz rm -rf $1/apache-tomcat-$2/{LICENSE,NOTICE,RELEASE-NOTES,RUNNING.txt} rm -rf apache-tomcat-$2/webapps/* rm -rf ./*.tar.gz } copy_tomcat() { cd $1 local array=$3 for i in ${array[*]} do proc=`echo $i |awk -F"-" '{print $1}'` shut_port=`echo $i |awk -F"-" '{print $2}'` http_port=`echo $i |awk -F"-" '{print $4}'` ajp_port=`echo $i |awk -F"-" '{print $3}'` cp -rf apache-tomcat-$2 $proc-tomcat #update process sed -i "s/java$/$proc-tomcat/" $proc-tomcat/bin/setclasspath.sh #update port 更新tomcat端口 三个端口 ajp端口 http端口 shutdown端口 sed -i "s/8005/$shut_port/g" $proc-tomcat/conf/server.xml sed -i "s/8009/$ajp_port/g" $proc-tomcat/conf/server.xml sed -i "s/8080/$http_port/g" $proc-tomcat/conf/server.xml sed -i "1aexport $JAVA_HOME" $proc-tomcat/bin/setclasspath.sh sed -i "2aexport $JRE_HOME" $proc-tomcat/bin/setclasspath.sh #update charset 编码设置 if [ $n -eq 7 ];then sed -i "73s#/>#URIEncoding=\"UTF-8\" &#g" $proc-tomcat/conf/server.xml elif [ $n -eq 8 ];then sed -i "71s#/>#URIEncoding=\"UTF-8\" &#g" $proc-tomcat/conf/server.xml #update JAVA_OPS 更新jvm内存配置 if [ $proc = 'erp' -o $proc = 'mem' -o $proc = 'order' ];then echo "mem-tomcat/erp-tomcat/order-tomcat set JAVA_OPTS is 2048M:"$MEM_ORDER_ERP_OPTS sed -i "279a$MEM_ORDER_ERP_OPTS" $proc-tomcat/bin/catalina.sh elif [[ $proc = 'shop' ]];then echo "shop-tomcat set JAVA_OPTS is 512M:==>"$SHOP_OPTS sed -i "279a$SHOP_OPTS" $proc-tomcat/bin/catalina.sh else echo "other app mem:"$COMMON_OPTS sed -i "279a$COMMON_OPTS" $proc-tomcat/bin/catalina.sh fi else sed -i "71,73s#/>#URIEncoding=\"UTF-8\" &#g" $proc-tomcat/conf/server.xml fi done rm -rf apache-tomcat-$2* } old_copy_tomcat() { cd $1 local a=($3) for tomcat in ${a[*]} do awk -F"-" SUBTPP=${tomcat//-/,} OLD_IFS="," IFS="," arr=($SUBTPP) cp -rf apache-tomcat-$2 ${arr[0]}-tomcat #update process 更新tomcat进程 sed -i "s/java$/${arr[0]}-tomcat/" ${arr[0]}-tomcat/bin/setclasspath.sh #update port 更新端口号 sed -i "s/8005/${arr[1]}/g" ${arr[0]}-tomcat/conf/server.xml sed -i "s/8009/${arr[2]}/g" ${arr[0]}-tomcat/conf/server.xml sed -i "s/8080/${arr[3]}/g" ${arr[0]}-tomcat/conf/server.xml done } tar_tomcat() { cd $TOMCAT_DIR for tar_tomcat in $(ls ./) do tar -zcf $tar_tomcat.tar.gz $tar_tomcat rm -rf $tar_tomcat done #tar -zcf $tar_tomcat.tar.gz $tar_tomcat &>/dev/null } if [ ! -d $TOMCAT_REPOS ];then mkdir -p $TOMCAT_REPOS fi echo $DATE if [ ! -d $WORKDIR ];then mkdir -p $WORKDIR fi cd $WORKDIR if [ ! -d $DATE ];then mkdir $DATE echo $DATE > $WORKDIR/record fi TOMCAT_NAME=`ls $TOMCAT_DIR` cd $REPOS if [ $(ls -al $TOMCAT_REPOS|grep svn|wc -l) -eq 0 ];then svn co http://192.168.0.91/repos/soft/tomcat$n --username=$USER --password=$PASSWD else #svn update http://192.168.0.91/repos/soft/tomcat$n --username=$USER --password=$PASSWD cd tomcat$n svn update fi if [ $? -eq 0 ];then cd $WORKDIR/$DATE line=`ls $TOMCAT_REPOS|sed 's/.tar.gz//'` TOMCAT_V=${line:14:6} rm -rf apache-tomcat-* cp -f $TOMCAT_REPOS/apache-tomcat-$TOMCAT_V.tar.gz $WD update_tomcat $WD $TOMCAT_V copy_tomcat $WD $TOMCAT_V "${TOMCAT_PROC_PORT[*]}" tar_tomcat $WD fi cd $WORKDIR rm -rf latest cp -Rf $DATE latest #sh /tmp/shell/test.sh |