본문 바로가기
Project/3-Tier Architecture

[3-Tier] Amazon Linux2에 Apache Tomcat 설치 (WAS 서버 구성2)

by ganyga 2024. 2. 22.

설치할 수 있는 OpenJDK 버전 확인 후 설치

  • OpenJDK : Java Development Kit(JDK)의 오픈 소스 구현체
  • Java SE (Standard Edition) 사양을 따르며, Java 언어의 컴파일러, 런타임 환경 및 다양한 라이브러리 등을 포함

JAVA를 사용하기 위해 yum 리포지토리에서 제공하는 Open JDK 목록을 확인

[root@was-a ~]# yum list java*jdk-devel

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Available Packages

java-1.7.0-openjdk-devel.x86_64       1:1.7.0.321-2.6.28.2.amzn2.0.2        amzn2-core
java-1.8.0-openjdk-devel.x86_64       1:1.8.0.392.b08-2.amzn2.0.1           amzn2-core

 

JAVA 8 설치 후 버전 확인

[root@was-a ~]# yum install java-1.8.0-openjdk-devel.x86_64

[root@was-a ~]# java -version
openjdk version "1.8.0_392"
OpenJDK Runtime Environment (build 1.8.0_392-b08)
OpenJDK 64-Bit Server VM (build 25.392-b08, mixed mode)

 

Apache Tomcat 설치

Apache Tomcat 버전과 지원되는 Java 버전 호환성 확인하기

→ 설치한 JAVA 버전이 8 이므로, Tomcat 9.0.x 버전 이상 설치해야 함

Tomcat 9.0.x 설치

 

Tomcat 9.0.86 설치 후 실행

[root@was-a ~]# wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.86/bin/apache-tomcat-9.0.86.zip

[root@was-a ~]# ls
apache-tomcat-9.0.86.zip

[root@was-a ~]# unzip apache-tomcat-9.0.86.zip
[root@was-a ~]# rm -rf apache-tomcat-9.0.86.zip
 

[root@was-a ~]# mv ./apache-tomcat-9.0.86/ ./tomcat
[root@was-a ~]# sudo chmod 755 -R ./tomcat/

[root@was-a ~]# cd tomcat/
[root@was-a tomcat]# ls
bin  BUILDING.txt  conf  CONTRIBUTING.md  lib  LICENSE  logs  NOTICE  README.md  RELEASE-NOTES  RUNNING.txt  temp  webapps  work

[root@was-a tomcat]# cd bin/
[root@was-a bin]# ./startup.sh
Using CATALINA_BASE:   /root/tomcat
Using CATALINA_HOME:   /root/tomcat
Using CATALINA_TMPDIR: /root/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /root/tomcat/bin/bootstrap.jar:/root/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.

 

Tomcat 버전확인

[root@was-a lib]# pwd
/root/tomcat/lib

[root@was-a lib]# java -cp catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/9.0.87
Server built:   Mar 11 2024 10:12:34 UTC
Server number:  9.0.87.0
OS Name:        Linux
OS Version:     5.10.210-201.852.amzn2.x86_64
Architecture:   amd64
JVM Version:    1.8.0_402-b06
JVM Vendor:     Red Hat, Inc.

curl localhost:8080 확인

[root@was-c bin]# curl localhost:8080
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Apache Tomcat/9.0.86</title>
        <link href="favicon.ico" rel="icon" type="image/x-icon" />
        <link href="tomcat.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
        <div id="wrapper">
            <div id="navigation" class="curved container">
                <span id="nav-home"><a href="https://tomcat.apache.org/">Home</a></span>
                <span id="nav-hosts"><a href="/docs/">Documentation</a></span>
                <span id="nav-config"><a href="/docs/config/">Configuration</a></span>
                <span id="nav-examples"><a href="/examples/">Examples</a></span>
                <span id="nav-wiki"><a href="https://cwiki.apache.org/confluence/display/TOMCAT/">Wiki</a></span>
                <span id="nav-lists"><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></span>
                <span id="nav-help"><a href="https://tomcat.apache.org/findhelp.html">Find Help</a></span>
                <br class="separator" />
            </div>
            <div id="asf-box">
                <h1>Apache Tomcat/9.0.86</h1>

 

Server 재부팅 시 자동으로 Tomcat이 실행되도록 설정

  • /etc/rc.d/rc.local은 리눅스 시스템에서 부팅 시 자동으로 실행되는 스크립트 파일
[root@was-a bin]# ls /etc/rc.d/rc.local
/etc/rc.d/rc.local

[root@was-a bin]# chmod +x /etc/rc.d/rc.local

[root@was-a tomcat]# pwd
/root/tomcat

# pwd 명령어로 tomcat bin 파일 위치 확인 후 절대경로 넣기
[root@was-a bin]# vi /etc/rc.d/rc.local 
sudo /root/tomcat/bin/startup.sh

 

pwd 명령어를 입력해서 tomcat이 설치된 경로에 지정해야 함

[root@was-a bin]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
sudo /root/tomcat/bin/startup.sh