批量创建Tomcat(多实例)脚本

2018-01-0217:58:55 1 1,583

此篇文章主要介绍为批量创建Tomcat(多实例)脚本,有需要的朋友可以参考一下。

脚本内容如下:

[root@localhost ~]# vim auto_deploy_tomcat.sh

#!/bin/bash
#2017-10-10 10:10:10
#by author yangxz
#Auto batch deploy tomcat

NUM=$1
TOMCAT_DIR=/usr/local

if [ -z $1 ];then
    echo -e "\033[32m --------------------- \033[0m"
    echo -e "\033[32m Usage: sh $0 1|2|3|10 \033[0m"
    exit 0
fi
VAR=`ls $TOMCAT_DIR/ |grep -c "tomcat*"`
if [ $VAR -eq 0 ];then
yum -y install wget
wget -c http://mirrors.yangxingzhen.com/jdk/jdk-8u144-linux-x64.gz
tar xf jdk-8u144-linux-x64.gz
mv jdk1.8.0_144 $TOMCAT_DIR
cat >>/etc/profile <<EOF
export JAVA_HOME=/usr/local/jdk1.8.0_144
export CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib
export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH:\$HOME/bin
EOF
source /etc/profile
wget -c http://mirrors.yangxingzhen.com/tomcat/apache-tomcat-8.0.48.tar.gz
tar zxf apache-tomcat-8.0.48.tar.gz
mv apache-tomcat-8.0.48 $TOMCAT_DIR/tomcat_1
sed -i 's/8080/1001/g' $TOMCAT_DIR/tomcat_1/conf/server.xml
sed -i 's/8005/2001/g' $TOMCAT_DIR/tomcat_1/conf/server.xml
sed -i 's/8009/3001/g' $TOMCAT_DIR/tomcat_1/conf/server.xml
exit 0
fi
NUM1=`ls $TOMCAT_DIR/ | grep "tomcat*" | awk -F_ '{print $NF}' | tail -1`
if [ -z $NUM1 ];then
    NUM1=0
fi
NUM2=`expr $NUM + $NUM1`
NUM3=`expr $NUM1 + 1`
for i in `seq $NUM3 $NUM2`
do
    PORT1=`expr 1001 + $i - 1`
    PORT2=`expr 2001 + $i - 1`
    PORT3=`expr 3001 + $i - 1`
    cp -a $TOMCAT_DIR/tomcat_1 $TOMCAT_DIR/tomcat_$i
    sed -i "s/1001/$PORT1/g" $TOMCAT_DIR/tomcat_$i/conf/server.xml
    sed -i "s/2001/$PORT2/g" $TOMCAT_DIR/tomcat_$i/conf/server.xml
    sed -i "s/3001/$PORT3/g" $TOMCAT_DIR/tomcat_$i/conf/server.xml
done
  • 微信号
  • 微信扫一扫加我~~
  • weinxin
  • 微信公众号
  • 微信扫一扫关注我吧~~
  • weinxin
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:1   其中:访客  1   博主  0

    • avatar 运维老司机

      亲测,写的不错,感谢博主 :razz: