tomcat

Tomcat 설치 후 환경 설정

gregorio 2018. 6. 28. 12:43

Tomcat이 설치된 후 환경설정을 통해 최적화를 수행하여야 한다.


Tomcat7을 기준으로 환경을 최적화 하는 방법이다.


1. .bash_profile 설정


# .bash_profile


# Get the aliases and functions

if [ -f ~/.bashrc ]; then

    . ~/.bashrc

fi


# User specific environment and startup programs

JAVA_HOME=/engn001/jdk1.7.0_80

TOMCAT_HOME=/engn001/tomcat-7.0.88

LOG_HOME=/logs001/

SRC_HOME=/sorc001/


PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin


alias tomcat='cd $TOMCAT_HOME'

alias logs='cd $LOG_HOME/app'

alias src='cd $SRC_HOME'


alias applog='tail -f $LOG_HOME/app/dsc_app.log'


umask 022

export PATH JAVA_HOME


2. vi editor 설정


tomcat 계정 Home Directory에 .vimrc 파일 생성

colo evening

syntax on

set tabstop=4

set shiftwidth=4

set softtabstop=4

set expandtab



3. Tomcat catalina.sh 설정 변경


#################################################################

#  Set Java options start                                                                              #

#################################################################

DATE=`date +"%Y%m%d"`


CATALINA_OUT="/logs001/tomcat/catalina.out"


JAVA_OPTS=" $JAVA_OPTS -D$SERVER_NAME -server"

JAVA_OPTS=" $JAVA_OPTS -Xms1280m -Xmx1280m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 -XX:MaxDirectMemorySize=512m"

JAVA_OPTS=" $JAVA_OPTS -XX:+CMSClassUnloadingEnabled"

JAVA_OPTS=" $JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/logs001/tomcat/dump/$SERVER_NAME-java_pid.hprof_$DATE"

#JAVA_OPTS=" ${JAVA_OPTS} -javaagent:${SCOUTER_AGENT_DIR}/scouter.agent.jar"

#JAVA_OPTS=" ${JAVA_OPTS} -Dscouter.config=${SCOUTER_AGENT_DIR}/conf/scouter.conf"

#JAVA_OPTS=" ${JAVA_OPTS} -Dobj_name=$SERVER_NAME"


if [ "$1" = "start" ]; then

    JAVA_OPTS=" $JAVA_OPTS -verbose:gc -Xloggc:/logs001/tomcat/gc/gc_$SERVER_NAME_$DATE.log"

    JAVA_OPTS=" $JAVA_OPTS -XX:+UseParallelGC -XX:ParallelGCThreads=8 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -XX:+UseParallelOldGC -XX:-UseAdaptiveSizePolicy"

fi


#################################################################

#  Set Java options end                                                                                #

#################################################################

Garbage Collection은 Concurrent GC로 설정되어 있으며, 시스템에 따라 적절한 메모리, Log 등을 설정한다. 


4. server.xml 설정 변경


    <Connector port="8080" protocol="HTTP/1.1"

               maxPostSize="-1"

               maxParameterCount="100"

               connectionTimeout="20000"

               minSpareThreads="50"

               maxThreads="200"

               acceptCount="2000"

               redirectPort="8443" />

 Thread, Timeout 등 관련된 항목을 설정한다.

또한 AJP를 사용하는 경우에도 AJP Connector에 Thread, Timeout관련 설정을 수정한다.


  <Listener className="org.apache.catalina.security.SecurityListener" checkedOsUsers="root" />


root 계정으로 Tomcat을 시작할 수 없도록 Listener를 등록한다.



5. Start Script 작성


Tomcat 설치  디렉토리의 bin에 start.sh 스크립트 작성

[start.sh]


#!/bin/sh


# Licensed to the Apache Software Foundation (ASF) under one or more

# contributor license agreements.  See the NOTICE file distributed with

# this work for additional information regarding copyright ownership.

# The ASF licenses this file to You under the Apache License, Version 2.0

# (the "License"); you may not use this file except in compliance with

# the License.  You may obtain a copy of the License at

#

#     http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.


# -----------------------------------------------------------------------------

# Start Script for the CATALINA Server

# -----------------------------------------------------------------------------


# resolve links - $0 may be a softlink

PRG="$0"


CATALINA_BASE=/engn001/tomcat-7.0.88

SERVER_NAME=xxxServer1


export CATALINA_BASE SERVER_NAME


while [ -h "$PRG" ] ; do

  ls=`ls -ld "$PRG"`

  link=`expr "$ls" : '.*-> \(.*\)$'`

  if expr "$link" : '/.*' > /dev/null; then

    PRG="$link"

  else

    PRG=`dirname "$PRG"`/"$link"

  fi

done


PRGDIR=`dirname "$PRG"`

EXECUTABLE=catalina.sh


exec "$PRGDIR"/"$EXECUTABLE" start "$@"



6. Stop Script 작성


Tomcat 설치  디렉토리의 bin에 stop.sh 스크립트 작성

[stop.sh]


#!/bin/sh


# Licensed to the Apache Software Foundation (ASF) under one or more

# contributor license agreements.  See the NOTICE file distributed with

# this work for additional information regarding copyright ownership.

# The ASF licenses this file to You under the Apache License, Version 2.0

# (the "License"); you may not use this file except in compliance with

# the License.  You may obtain a copy of the License at

#

#     http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.


# -----------------------------------------------------------------------------

# Stop script for the CATALINA Server

# -----------------------------------------------------------------------------


# Better OS/400 detection: see Bugzilla 31132

os400=false


CATALINA_BASE=/engn001/tomcat-7.0.88

SERVER_NAME=xxxServer1


export CATALINA_BASE SERVER_NAME


PRG="$0"


while [ -h "$PRG" ] ; do

  ls=`ls -ld "$PRG"`

  link=`expr "$ls" : '.*-> \(.*\)$'`

  if expr "$link" : '/.*' > /dev/null; then

    PRG="$link"

  else

    PRG=`dirname "$PRG"`/"$link"

  fi

done


PRGDIR=`dirname "$PRG"`

EXECUTABLE=catalina.sh


exec "$PRGDIR"/"$EXECUTABLE" stop "$@"