2019년 7월 1일 월요일

centos tomcat multi instance 구성 준비 (shell script)


리눅스(centos 기준)서버 한대에 tomcat 인스턴스를 여러개 구성이 필요할 경우
이를 tomcat multi instances(?)라고 하는 것 같다.

tomcat을 multi instances 구성을 하려면 디렉토리도 생성해줘야 하고 scripts, xml 파일 등등 복사해와야 한다.

수작업이 시간이 오래 걸리고 error도 많기 때문에 스크립트로 만들어봤다.

#!/bin/bash

# -----------------------------------------------------------------
# Make Directory (필수 디렉토리 생성)
# -----------------------------------------------------------------
if [ ! -d ./bin ]
    then
    echo "create bin directory."
    mkdir -p ./bin;
fi

if [ ! -d ./conf ]
    then
    echo "create conf directory."
    mkdir -p ./conf;
fi

if [ ! -d ./lib ]
    then
    echo "create lib directory."
    mkdir -p ./lib;
fi


if [ ! -d ./temp ]
    then
    echo "create temp directory."
    mkdir -p ./temp;
fi

if [ ! -d ./webapps ]
    then
    echo "create webapps directory."
    mkdir -p ./webapps;
fi

if [ ! -d ./work ]
    then
    echo "create work directory."
    mkdir -p ./work;
fi

# -----------------------------------------------------------------
# XML Copy (CATALINA_HOME 톰캣엔진에서 xml을 copy)
# -----------------------------------------------------------------
# catalina.sh 파일은 tomcat을 실행하기 위한 필요한 스크립트이기 때문에 이 script 기준으로 설정
value=`find ../../ -type f -name "catalina.sh" 2>/dev/null | wc -l`
#echo $value

if [ ${value} -ne 1 ];
    then
        echo "Can not Found Tomcat Engine"
    else

    if [ ! -d $CATALINA_HOME ]
        then
            echo "Can not find CATALINA_HOME"
        else
        CATALINA_HOME=$(find ../../ -type d -name "*8.5*" 2>/dev/null -exec readlink -f {} \;)
            cp -r $CATALINA_HOME/conf/* ./conf;

        fi

fi

# 기존 port 또는 기본 port 와의 충돌을 피하기 위해서 system properties로 넘길 것 (JAVA_OPTS -D option)
# -----------------------------------------------------------------
# PORT Translation
# -----------------------------------------------------------------
find . -type f -name "server.xml" -exec sed -i "s/8005/\$\{shutdown.port\}/" {} \;
find . -type f -name "server.xml" -exec sed -i "s/8080/\$\{http.port\}/" {} \;
find . -type f -name "server.xml" -exec sed -i "s/8009/\$\{ajp.port\}/" {} \;
find . -type f -name "server.xml" -exec sed -i "s/8443/\$\{ssl.port\}/" {} \;

# -----------------------------------------------------------------
# jvmRoute
# -----------------------------------------------------------------
find . -type f -name "server.xml" -exec sed -i "s/defaultHost=\"localhost\"/defaultHost=\"localhost\" jvmRoute=\"\$\{server\}\"/" {} \;

댓글 없음:

댓글 쓰기