■ 참고 : CentOS 에 tomcat 을 service 로 등록하여 booting 시 자동으로 구동되게 하기(펌)
■ /etc/rc.d/init.d 폴더에 tomcat7 이라는 파일명으로 시작 스크립트 등록하고 스크립트의 내용중에서 톰캣이 설치된 폴더 위치와 톰캣 실행 사용자를 적절한 일반 사용자로 수정한다.
# vi /etc/rc.d/init.d/tomcat7
#!/bin/bash # # tomcat # # chkconfig: 345 96 30 # description: Start up the Tomcat servlet engine. # # processname: java # pidfile: /var/run/tomcat.pid # ### BEGIN INIT INFO # Provides: tomcat # Required-Start: $network $syslog # Required-Stop: $network $syslog # Should-Start: distcache # Short-Description: start and stop Apache HTTP Server # Description: implementation for Servlet 2.5 and JSP 2.1 ## END INIT INFO # Source function library. . /etc/rc.d/init.d/functions ## tomcat installation directory PROCESS_NAME=tomcat # tomcat이 설치된 폴더 CATALINA_HOME="/usr/local/tomcat/" ## run as a diffent user # tomcat 실행 사용자를 root가 아닌 일반 사용자로 변경 TOMCAT_USER=nextman ## Path to the pid, runnning info file pidfile=${PIDFILE-/var/run/${PROCESS_NAME}.pid}; lockfile=${LOCKFILE-/var/lock/subsys/${PROCESS_NAME}}; RETVAL=0 case "$1" in start) PID=`pidofproc -p ${pidfile} ${PROCESS_NAME}` if [[ (-n ${PID}) && ($PID -gt 0) ]]; then logger -s "${PROCESS_NAME}(pid ${PID}) is already running." exit; fi if [ -f $CATALINA_HOME/bin/startup.sh ]; then logger -s "Starting Tomcat" /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/startup.sh -Dprocessname=${PROCESS_NAME}" PID=`ps -eaf|grep processname=${PROCESS_NAME}|grep -v grep|awk '{print $2}'` RETVAL=$? [ $RETVAL = 0 ] && touch ${lockfile} [ $RETVAL = 0 ] && echo "${PID}" > ${pidfile} fi ;; stop) PID=`pidofproc -p ${pidfile} ${PROCESS_NAME}` ## if PID valid run shutdown.sh if [[ -z ${PID} ]];then logger -s "${PROCESS_NAME} is not running." exit; fi if [[ (${PID} -gt 0) && (-f $CATALINA_HOME/bin/shutdown.sh) ]]; then logger -s "Stopping Tomcat" /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/shutdown.sh" RETVAL=$? [ $RETVAL = 0 ] && rm -f ${lockfile} [ $RETVAL = 0 ] && rm -f ${pidfile} fi ;; status) status -p ${pidfile} ${PROCESS_NAME} RETVAL=$? ;; restart) $0 stop $0 start ;; version) if [ -f $CATALINA_HOME/bin/version.sh ]; then logger -s "Display Tomcat Version" /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/version.sh" RETVAL=$? fi ;; *) echo $"Usage: $0 {start|stop|restart|status|version}" exit 1 ;; esac exit $RETVAL
■ 새로 생성한 /etc/rc.d/init.d/tomcat7 파일에 실행속성을 추가한다.
# chmod +x /etc/rc.d/init.d/tomcat7
■ 부팅과 동시에 tomcat이 실행되게 하려면 run-level에 등록한다.
# chkconfig –add tomcat7
■ run-level에 등록되었는지 확인(run-level이 3,4,5가 ‘on’일 경우 부팅과 동시에 실행된다.)
# chkconfig –list tomcat7
■ service 명령어로 shell에서 실행되는지 확인한다.
# systemctl start tomcat7.service
■ 아래와 같은 메세지와 함께 tomcat 서비스가 실행되지 않으면 다음의 명령어로 실행되지 않는 이유를 확인한다.
Job for tomcat7.service failed. See ‘systemctl status tomcat7.service’ and ‘journalctl -xn’ for details.
# systemctl start tomcat7.service
tomcat7.service – LSB: start and stop Apache HTTP Server
Loaded: loaded (/etc/rc.d/init.d/tomcat7)
Active: failed (Result: resources) since 수 2015-04-08 22:02:05 KST; 6min ago
Process: 2078 ExecStart=/etc/rc.d/init.d/tomcat7 start (code=exited, status=0/SUCCESS)
4월 08 22:02:05 centos01 systemd[1]: Starting LSB: start and stop Apache HTTP Server…
4월 08 22:02:05 centos01 tomcat7[2078]: logger: Starting Tomcat
4월 08 22:02:05 centos01 su[2081]: (to nextman) root on none
4월 08 22:02:05 centos01 tomcat7[2078]: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
4월 08 22:02:05 centos01 tomcat7[2078]: At least one of these environment variable is needed to run this program
4월 08 22:02:05 centos01 systemd[1]: PID file /var/run/tomcat.pid not readable (yet?) after start.
4월 08 22:02:05 centos01 systemd[1]: Failed to start LSB: start and stop Apache HTTP Server.
4월 08 22:02:05 centos01 systemd[1]: Unit tomcat7.service entered failed state
■ 위의 메세지는 nextman 사용자의 홈디렉토리의 .bash_profile에 JAVA_HOME환경변수가 설정되지 않은 이유로 tomcat서비스가 실행되지 않았다. nextman사용자의 환경변수에 java(JAVA_HOME)을 적어준다.
# su – nextman
$ vi ~/.bash_profile
■ nextman 사용자의 .bash_profile 내용
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs export JAVA_HOME=/usr/local/java PATH=$JAVA_HOME/bin:$PATH:$HOME/.local/bin:$HOME/bin export PATH
■ 다시 root사용자로 돌아와서 tomcat 서비스를 실행시킨다.
# systemctl start tomcat7.service
Job for tomcat7.service failed. See ‘systemctl status tomcat7.service’ and ‘journalctl -xn’ for details.
[root@centos01 bin]# systemctl status tomcat7.service
tomcat7.service – LSB: start and stop Apache HTTP Server
Loaded: loaded (/etc/rc.d/init.d/tomcat7)
Active: failed (Result: resources) since 수 2015-04-08 22:18:41 KST; 8s ago
Process: 2217 ExecStart=/etc/rc.d/init.d/tomcat7 start (code=exited, status=0/SUCCESS)
4월 08 22:18:41 centos01 systemd[1]: Starting LSB: start and stop Apache HTTP Server…
4월 08 22:18:41 centos01 tomcat7[2217]: logger: Starting Tomcat
4월 08 22:18:41 centos01 su[2220]: (to nextman) root on none
4월 08 22:18:41 centos01 tomcat7[2217]: touch: cannot touch `/usr/local/tomcat/logs/catalina.out’: 허가 거부
4월 08 22:18:41 centos01 tomcat7[2217]: /usr/local/tomcat//bin/catalina.sh: line 385: /usr/local/tomcat/logs/catalina.out… 거부
4월 08 22:18:41 centos01 systemd[1]: PID file /var/run/tomcat.pid not readable (yet?) after start.
4월 08 22:18:41 centos01 systemd[1]: Failed to start LSB: start and stop Apache HTTP Server.
4월 08 22:18:41 centos01 systemd[1]: Unit tomcat7.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.
■ 위의 메세지는 기존에 root사용자로 실행시킬때의 /usr/local/tomcat/logs/catalina.out 로그파일이 root사용자의 권한으로 만들어져서이다. /usr/local/tomcat/ 폴더 하위 폴더및 파일 전부를 nextman사용자.nextman그룹 소유로 변경시키고 다시 tomcat 서비스를 시작한다.
# chown -R nextman.nextman /usr/local/tomcat/
# systemctl start tomcat7.service
■ systemctl start tomcat7.service 명령어로 tomcat 서비스를 시작시키고 나서 아무런 메세지도 없이 # 프롬프트가 떨어지면 정상적으로 tomcat 서비스가 실행된 것이다. 이제 CentOS7 서버를 reboot명령어로 재시작했을 때 tomcat 서비스가 시작 되는지 확인한다.
# reboot
# ps ax | grep tomcat
■ 끝
- The uploaded file could not be moved to wp-content/uploads/2023/01. 2023년 1월 4일
- Linux 리눅스 디스크 사용량 확인 2022년 3월 23일
- 현재 서버의 포트가 열려있는지 확인하는 방법 2021년 12월 21일
- catalina.out 파일 최근 10000라인으로 자르기 2021년 4월 8일
- 리눅스 targ gzip을 이용한 디렉토리 압축 백업 2019년 4월 10일
- Window10에서 원격서버 포트 점검 2019년 1월 21일
- 리눅스 특정 문자열을 포함하는 파일 찾기 2019년 1월 8일
- Vmware에서 설치된 CentOS 7의 네트워크 설정 2017년 7월 24일
- AH00558: Set the ‘ServerName’ directive globally to suppress this message 2017년 4월 18일
- configure: error: You need a C++ compiler for C++ support. 2017년 4월 18일
- CentOS에서 컴파일할 때 no acceptable C compiler found in $PATH 에러 메세지 2017년 4월 18일
- XShell 단축키 모음 2016년 9월 5일
- ubuntu 일반 계정에서 SUDO를 이용하여 root 암호 변경하기 2016년 8월 30일
- yum으로 Linux man 설치 2016년 3월 14일
- vi 편집기 단어 바꾸기 2016년 3월 13일
- vi 편집기 환경 설정 2016년 3월 12일
- Linux sudo – 패스워드없이 root권한 명령 실행 2016년 3월 9일
- tar gzip bzip2 bz2 명령어 정리 2016년 3월 8일
- XShell 접속 리눅스 한글 2016년 3월 8일
- Sed 사용법 2016년 3월 7일
- Linux SCP 명령어 사용법 2016년 2월 29일
- VMware Clone 2016년 2월 25일
- CentOS7 ~/.bash_profile 예제 2015년 5월 2일
- CentOS7 Linux Tomcat7 자동시작 2015년 4월 8일
- CentOS7 Linux Subversion(SVN) 설치 2015년 4월 7일
- CentOS7 vsftpd 설치 2015년 3월 26일
- vsftpd 서비스 시작 메세지 – Redirecting to /bin/systemctl… 2015년 3월 17일
- [펌] yum 사용법 2015년 3월 17일
- Linux 일반 팁 2015년 3월 15일
- apache php mysql tomcat 연동 설치 2014년 10월 7일
- Vmware에 CentOS 설치 2014년 10월 1일
- VMWare 설치 2014년 9월 29일
- SSH 자동 로그인 2014년 9월 15일
- 리눅스 검색 tip 2014년 9월 15일
- 리눅스 아파치 프로세스 소유자 변경하기 2014년 9월 2일