- tomcat다운로드
아래 전 과정은 root가 필요한 별도 명령어를 제외하고 tomcat계정으로 실행
$ su - tomcat
전송 및 압축해제
$ mkdir /u00/tomcat $ tar xvfp apache-tomcat-8.5.12.tar.gz
실행스크립트
$ vi /u00/tomcat/apache-tomcat-8.5.12/bin/setenv.sh ## 1. service name TomcatUser="tomcat" CATALINA_OUT="/u00/tomcat/apache-tomcat-8.5.12/logs/catalina.out" JAVA_HOME="/u00/java/jdk1.8.0_261/" CATALINA_HOME="/u00/tomcat/apache-tomcat-8.5.12" ## 2. JAVA Options ## Max HEAP Size MAX_HEAP_SIZE="2G" JAVA_OPTS="$JAVA_OPTS -Xmx$MAX_HEAP_SIZE -Xms$MAX_HEAP_SIZE" ## IBM JAVA MaxPermSize and GC Path not support!!! #JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=256m -Xloggc:$CATALINA_HOME/logs/gc/gc.log" JAVA_OPTS="$JAVA_OPTS -Xloggc:$CATALINA_HOME/logs/gc/gc.log" JAVA_OPTS="$JAVA_OPTS -server -d64 -XX:+UseParallelGC -XX:ParallelGCThreads=4" JAVA_OPTS="$JAVA_OPTS -XX:-UseGCOverheadLimit" JAVA_OPTS="$JAVA_OPTS -verbose:gc" JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails -XX:+PrintGCTimeStamps" JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC -XX:+HeapDumpOnOutOfMemoryError" JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=$CATALINA_HOME/logs/gc/" ## 3. tomcat user check if [ "`whoami`" != "${TomcatUser}" ] ; then echo "Run as ${TomcatUser} user !!!" echo "su - ${TomcatUser} -c `pwd`/$0 $*" exit 1 fi ## 4. Move logs Today=`date +%Y-%m-%d` HMS=`date '+%H%M%S'` logs="$CATALINA_OUT $CATALINA_HOME/logs/gc/gc.log" for log in $logs ; do if [ ! -f $log-$Today -a -f $log ] ; then mv -b -S "-$HMS" $log $log-$Today &> /dev/null fi done
실행권한부여
$ chmod 700 /u00/tomcat/apache-tomcat-8.5.12/bin/setenv.sh
server.xml수정
$ vi /u00/tomcat/apache-tomcat-8.5.12/conf/server.xml <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxThreads="1024" acceptorThreadCount="4" keepAliveTimeout="3000" maxKeepAliveRequests="1000" URIEncoding="UTF-8" /> <!--<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />-->
서비스설정을 위한 스크립트
$ vi /u00/tomcat/apache-tomcat-8.5.12/bin/tomcatctl #!/bin/bash # # tomcat This shell script takes care of starting and stopping Tomcat # # chkconfig: - 80 20 # ### BEGIN INIT INFO # Provides: tomcat # Required-Start: $network $syslog # Required-Stop: $network $syslog # Default-Start: # Default-Stop: # Short-Description: start and stop tomcat ### END INIT INFO TOMCAT_USER="tomcat" TOMCAT_HOME="/u00/tomcat/apache-tomcat-8.5.12/" SHUTDOWN_WAIT=50 # Second . /etc/bashrc tomcat_pid() { echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep $TOMCAT_HOME | grep -v grep | awk '{ print $2 }'` } start() { pid=$(tomcat_pid) if [ -n "$pid" ] ; then echo "Tomcat is already running (pid: $pid)" else # Start tomcat echo "Starting tomcat" if [ "`whoami`" != "$TOMCAT_USER" ] ; then /bin/su -l $TOMCAT_USER -s /bin/bash -c "cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/startup.sh" else cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/startup.sh fi fi return 0 } stop() { pid=$(tomcat_pid) if [ -n "$pid" ] ; then echo "Stoping Tomcat" if [ "`whoami`" != "$TOMCAT_USER" ] ; then /bin/su -l $TOMCAT_USER -s /bin/bash -c "cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/shutdown.sh" else cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/shutdown.sh fi let kwait=$SHUTDOWN_WAIT count=0 count_by=1 until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ] ; do echo "Waiting for processes to exit. Timeout before we kill the pid: ${count}/${kwait}" sleep $count_by let count=$count+$count_by; done if [ $count -gt $kwait ]; then echo "Killing processes which didn't stop after $SHUTDOWN_WAIT seconds" kill -9 $pid fi else echo "Tomcat is not running" fi return 0 } if [ "`whoami`" != "${TOMCAT_USER}" -a "`whoami`" != "root" ] ; then echo "Run as ${TOMCAT_USER} user !!!" echo "su - ${TOMCAT_USER} -c `pwd`/$0 $*" exit 1 fi case $1 in start) start ;; stop) stop ;; restart) stop start ;; status) pid=$(tomcat_pid) if [ -n "$pid" ] then echo "Tomcat is running with pid: $pid" else echo "Tomcat is not running" fi ;; *) echo "Usage : $0 [start|stop|restart|status]" ;; esac exit 0
서비스등록 및 자동재시작
$ chmod 700 /u00/tomcat/apache-tomcat-8.5.12/bin/tomcatctl $ su root $ ln -s /u00/tomcat/apache-tomcat-8.5.12/bin/tomcatctl /etc/init.d/tomcat $ systemctl enable tomcat
$ chkconfig --add tomcat $ chkconfig tomcat on서비스 시작 및 종료 , 재시작, 상태 등
$ service tomcat start $ service tomcat stop $ service tomcat restart $ service tomcat status
sudo 권한 부여
$root visudo ## tomcat tomcat ALL=/usr/sbin/service tomcat, /usr/bin/systemctl start nginx, /usr/bin/systemctl stop nginx tomcat ALL=NOPASSWD: ALL
- 편의기능
심볼릭 링크를 통한 배포 위치 설정
$ ln -s /u00/tomcat/apache-tomcat-8.5.12/webapps/ ./
ls -s 원본 링크
'운영체제 이야기 > Linux(CentOS)' 카테고리의 다른 글
[CentOS7] NAS mount 방법 및 규칙 (0) | 2019.05.06 |
---|---|
[CentOS7] 리눅스환경변수 (0) | 2019.05.06 |
[CentOS7] 설치 및 설정 (0) | 2019.05.06 |
[CentOS7] MySql 5.6 설치 및 설정 (0) | 2019.05.06 |
[CentOS7] Nginx 설치 및 설정 (0) | 2019.04.29 |
댓글