[CentOS] CentOS에 Tomcat 8 설치

MOON·2021년 6월 7일
2
post-thumbnail

개발환경 : aws, CentOS 7, jdk11


1. Tomcat 설치

// wget 설치
# yum install wget
// Tomcat 8.5 설치
# wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.27/bin/apache-tomcat-8.5.27.tar.gz

// 압축 해제
# tar zxvf apache-tomcat-8.5.27.tar.gz

// 압축 해제한 톰캣을 /usr/local/tomcat8 경로로 이동
# mv apache-tomcat-8.5.27 /usr/local/tomcat8

2. 환경변수 등록

vi /etc/profile

//하단에 입력
...

JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.11.0.9-1.el7_9.x86_64
CATALINA_HOME=/usr/local/tomcat8
CLASSPATH=$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib-jsp-api.jar:$CATALINA_HOME/lib/servlet-api.jar
PATH=$PATH:$JAVA_HOME/bin:/bin:/sbin
export JAVA_HOME PATH CLASSPATH CATALINA_HOME

설정 후 명령어 입력
source /etc/profile


3. server.xml 설정

vi /usr/local/tomcat8/conf/server.xml

// 아래 설정에서 URIEncoding="UTF-8" 추가
...
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443"
           URIEncoding="UTF-8" />
...

4. Tomcat 8 실행

// startup.sh 로 톰캣서버를 실행
# /usr/local/tomcat8/bin/startup.sh

or

# $CATALINA_HOME/bin/startup.sh
  • 실행확인
Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/lib/jvm/java-11-openjdk-11.0.11.0.9-1.el7_9.x86_64
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.
  • 8080포트가 열렸는지 확인
// 8080 포트가 열려있는지 확인
# netstat -ntl
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp6       0      0 :::8080                 :::*                    LISTEN

5. systemctl 등록

  • systemctl 등록

vi /etc/systemd/system/tomcat8.service

// 내용 입력

# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.11.0.9-1.el7_9.x86_64"
Environment="CATALINA_HOME=/usr/local/tomcat8"
Environment="CATALINA_BASE=/usr/local/tomcat8"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

ExecStart=/usr/local/tomcat8/bin/startup.sh
ExecStop=/usr/local/tomcat8/bin/shutdown.sh

User=root
Group=root
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

// systemctl 리로드
# systemctl daemon-reload
# systemctl enable tomcat8

// tomcat8 실행
# systemctl start tomcat8
  • systemctl service 부팅 시 자동 실행하도록 설정
//부팅 시 자동 실행 서비스 등록
# systemctl enable tomcat8.service
//등록된 서비스 조회
# systemctl list-unit-files --type service |grep tomcat8

1개의 댓글

comment-user-thumbnail
2022년 6월 2일

깔끔한 정리 감사합니다.

답글 달기