톰켓 다운로드
https://tomcat.apache.org/download-90.cgi
Apache Tomcat® - Apache Tomcat 9 Software Downloads
Welcome to the Apache Tomcat® 9.x software download page. This page provides download links for obtaining the latest version of Tomcat 9.0.x software, as well as links to the archives of older releases. Unsure which version you need? Specification version
tomcat.apache.org
다운로드 받은 톰켓 파일을 설치 폴더에 압축 해제
tar xvf 압축파일
unzip 압축파일
conf/catalina.properties 파일에서 server.xml에 설정 할 포트 정보를 맨 하단에 설정
catalina.properties에 설정 시 포트 확인 및 관리가 편하다.
tomcat.server.port=8008
tomcat.http.port=8086
tomcat.ajp.port=18012
conf/server.xml에 catalina.properties에 설정한 포트 변수로 수정 및 로그 경로 수정
<?xml version="1.0" encoding="UTF-8"?>
<Server port="${tomcat.server.port}" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="${tomcat.http.port}" protocol="HTTP/1.1" URIEncoding="UTF-8" connectionTimeout="20000" />
<Connector protocol="AJP/1.3" port="${tomcat.ajp.port}" address="0.0.0.0" secretRequired="false"/>
<Engine name="Catalina" defaultHost="localhost">
<Valve className="org.apache.catalina.valves.RemoteIpValve"
internalProxies="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
remoteIpHeader="Apache-Forwarded-For"
proxiesHeader="Apache-Forwarded-By"
protocolHeader="Apache-Forwarded-Proto" />
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false">
<Valve className="org.apache.catalina.valves.RemoteIpValve"
internalProxies="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
remoteIpHeader="Apache-Forwarded-For"
proxiesHeader="Apache-Forwarded-By"
protocolHeader="Apache-Forwarded-Proto" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="access" suffix="_project_cai_admin.log" pattern=" %h %l %u %t "%r" %s %b"/>
</Host>
</Engine>
</Service>
</Server>
불필요한 코드는 전부 삭제 하고 필요한 코드만 적용
<Valve className="org.apache.catalina.valves.RemoteIpValve"
internalProxies="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
remoteIpHeader="Apache-Forwarded-For"
proxiesHeader="Apache-Forwarded-By"
protocolHeader="Apache-Forwarded-Proto" />
이코드는 이전에 apache server와 tomcat server 사이에 elb가 이중화 되어 있으면서 apache에 ssl로 들어온 url이
tomcat으로 프록시 될때 http로 들어오는 현상 때문에 apache에 해당 내용을 같이 설정 해주고 tomcat에도 같이 설정을
했을 때 문제가 해결 됨.
bin/catalina.sh 에 톰켓 경로나 실행시 java 옵션을 설정
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=devser -Xms512m -Xms512m -XX:MaxPermSize=512m"
# OS specific support. $var _must_ be set to either true or false.
cygwin=false
darwin=false
os400=false
hpux=false
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin*) darwin=true;;
OS400*) os400=true;;
HP-UX*) hpux=true;;
esac
# resolve links - $0 may be a softlink
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
export CATALINA_HOME=/data/app/project_cai_web/apache-tomcat-9.0.82
export TOMCAT_HOME=/data/app/project_cai_web/apache-tomcat-9.0.82
export CATALINA_BASE=/data/app/project_cai_web/apache-tomcat-9.0.82
CATALINA_PID=/data/app/project_cai_web/apache-tomcat-9.0.82/bin/tomcat.pid
bin/startup.sh 제일 하단에 exec "$PRGDIR"/"$EXECUTABLE" start "$@" 가 없으면 똑같이 수정 또는 추가
pid 때문에 했던거 같음
권한 변경이 안되면 파일 쓰기 시 퍼미션 오류가 있으면 UMASK 부분을 찾아서 권한 변경
UMASK="0027" -> UMASK="0022" 변경
#!/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
# -----------------------------------------------------------------------------
# Better OS/400 detection: see Bugzilla 31132
os400=false
case "`uname`" in
OS400*) os400=true;;
esac
# resolve links - $0 may be a softlink
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
# Check that target executable exists
if $os400; then
# -x will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
eval
else
if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
echo "Cannot find $PRGDIR/$EXECUTABLE"
echo "The file is absent or does not have execute permission"
echo "This file is needed to run this program"
exit 1
fi
fi
exec "$PRGDIR"/"$EXECUTABLE" start "$@"
bin/shutdown.sh에도 exec "$PRGDIR"/"$EXECUTABLE" stop -force "$@" 없으면 추가
#!/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
case "`uname`" in
OS400*) os400=true;;
esac
# resolve links - $0 may be a softlink
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
# Check that target executable exists
if $os400; then
# -x will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
eval
else
if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
echo "Cannot find $PRGDIR/$EXECUTABLE"
echo "The file is absent or does not have execute permission"
echo "This file is needed to run this program"
exit 1
fi
fi
exec "$PRGDIR"/"$EXECUTABLE" stop -force "$@"
톰켓 port나 톰켓 경로를 설정해서 사용을 해야 같은 서버에 여러개의 톰켓을 운영 하기 편하다.