4. Ubuntu 18 (CentOS 7) tomcat 설치 - flapper/codezen GitHub Wiki

ref

괄호안은 CentOS 7

First, create a new tomcat group

sudo groupadd tomcat

Next, create a new tomcat user. We'll make this user a member of the tomcat group, with a home directory of /opt/tomcat (where we will install Tomcat), and with a shell of /bin/false (so nobody can log into the account):

sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

(sudo useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat)

cd /tmp

wget {core tomcat 링크주소}

sudo mkdir /opt/tomcat

sudo tar xzvf apache-tomcat...tar.gz -C /opt/tomcat --strip-components=1

압축해제된 폴더로 이동

cd /opt/tomcat

Give the tomcat group ownership over the entire installation directory

sudo chgrp -R tomcat /opt/tomcat

Next, give the tomcat group read access to the conf directory and all of its contents, and execute access to the directory itself:

sudo chmod -R g+r conf

sudo chmod g+x conf

Make the tomcat user the owner of the webapps, work, temp, and logs directories

sudo chown -R tomcat webapps/ work/ temp/ logs/

JAVA_HOME 위치 찾기

sudo update-java-alternatives -l

java-1.11.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64

중 맨 오른쪽 /usr/lib/jvm/java-1.8.0-openjdk-amd64 가 실경로

따로 위 경로를 메모장에 복사해둔다

tomcat 서비스 실행 스크립트 작성

sudo vi/etc/systemd/system/tomcat.service

아래 전체 복사 붙여넣기

/etc/systemd/system/tomcat.service

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

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

[Install]
WantedBy=multi-user.target

Next, reload the systemd daemon so that it knows about our service file

sudo systemctl daemon-reload

Start the Tomcat service by typing

sudo systemctl start tomcat

Double check that it started without errors by typing

sudo systemctl status tomcat

방화벽 열기(aws 는 보안그룹 inbound 규칙추가)

sudo ufw allow 8080

브라우저로 확인

http://server_domain_or_IP:8080

서비스 등록 (리부팅시 자동 시작)

sudo systemctl enable tomcat