Tomcat使用小技巧

  1. 设置 tomcat 启动后的占用内存大小

    1
    2
    3
    4
    5
    # vim /tomcats/bin/catalina.sh
    # 修改配置参数,大约是第251行:原始:JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS"
    # 修改为:
    # 其中的数值可以根据需要修改
    JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Xms200m -Xmx200m"
  2. 脚本新建新的 tomcat 目录

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    # 执行脚本:
    # ./new_server.sh server_tomcat git_repo nu

    server_tomcat=$1 # server_tomcat 比如:12001_topgear-test
    git_repo=$2 # git_repo 比如:topgear
    nu=$3 # nu 比如:01

    tar -xvf apache-tomcat-9.0.4.tar.gz
    mv apache-tomcat-9.0.4 ${server_tomcat}
    cp 12001_topgear-test/deploy.sh ${server_tomcat}
    cp 12001_topgear-test/conf/server.xml ${server_tomcat}/conf/server.xml

    # 使用sed命令时,如果
    sed -ig "s/11001/110${nu}/g" ./${server_tomcat}/conf/server.xml
    sed -ig "s/12001/120${nu}/g" ./${server_tomcat}/conf/server.xml
    sed -ig "s/13001/130${nu}/g" ./${server_tomcat}/conf/server.xml
    sed -ig "s/14001/140${nu}/g" ./${server_tomcat}/conf/server.xml
    sed -ig "s/15001/150${nu}/g" ./${server_tomcat}/conf/server.xml

    sed -ig "s/topgear\"/${git_repo}\"/g" ./${server_tomcat}/deploy.sh
    sed -ig "s/12001_topgear-test/${server_tomcat}/g" ./${server_tomcat}/deploy.sh
    sed -ig "s/topgear-web/${git_repo}-web/g" ./${server_tomcat}/deploy.sh
    sed -ig 's/mvn config:load/# mvn config:load/g' ./${server_tomcat}/deploy.sh

Sed后面的表达式一般用单引号引起来',当需要使用变量时就换用双引号"

3.