인프라

centos 톰캣 설치후 여러계정에서 시작/재시작 가능

소행성왕자 2022. 1. 7. 15:44

톰캣 설치후 여러 다른 계정이 톰캣 재시작 할수 있게 하는 방법

why? 자바 프로젝트 배포시 여러계정에서 war 파일 배포후 톰캣을 재시작 해야 되기 때문에

  • 자바 설치
  • 톰캣 설치
  • 톰캣 컨테이너 생성

자바  / 톰캣 설치

# cd /usr/local/src
# wget https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_linux-x64_bin.tar.gz
# wget https://mirror.navercorp.com/apache/tomcat/tomcat-9/v9.0.52/bin/apache-tomcat-9.0.52.tar.gz
# tar zxvf openjdk-16.0.2_linux-x64_bin.tar.gz
# tar zxvf apache-tomcat-9.0.52.tar.gz
# mv /usr/local/src/jdk-16.0.2/ /usr/lib/jvm/
# mv /usr/local/src/apache-tomcat-9.0.56 /opt/tomcat
# groupadd tomcat
# useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
# chgrp -R tomcat /opt/tomcat
# chmod -R g+r conf
# chmod g+x conf
# chown -R tomcat webapps/ work/ temp/ logs/
# systemctl daemon-reload
# /usr/lib
# mkdir jvm
# ln -s /usr/lib/jvm/jdk-16.0.2/bin/java /usr/bin/java
# ll /usr/bin/java
# java --version
# chown -R root.root jvm/
# vi /etc/systemd/system/tomcat.service
# systemctl start tomcat

톰캣 컨테이서 생성

vi /etc/systemd/system/tomcat.service
 
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jdk-17.0.1+12
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Dfile.encoding=UTF-8 -DServer=service  -Xms1000m -Xmx1000m -XX:G1ConcRefinementThreads=10 -XX:ParallelGCThreads=10 -XX:ConcGCThreads=5  -XX:MaxGCPauseMillis=200 -XX:MaxTenuringThreshold=0'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=devPage'

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

톰캣 시작 / 재시작

# sudo systemctl start tomcat