티스토리 뷰

카테고리 없음

[AWS] Linux에 톰캣설치하기

공부하는기획자 2017. 4. 11. 23:26

지난 주 스터디 주제로 AWS의 EC2 서비스를 이용하여 10분만에 Linux 서버 만들기에 대해 말씀드렸습니다. 

(매주 모든 분들이 하나씩 올리는 것인 줄 알았는데 저 말고는 아무도 올리지 않으셔서 조금 당황스럽습니다. 그래도 이번 주에도 꿋꿋하게..)

오늘은 지난 주 만든 EC2 Linux 인스턴스에 Apache Tomcat을 설치하는 방법을 공부하여 보았습니다. 참고로 삵에 이미 Apache Tomcat을 설치하는 많은 방법이 가이드되어 있지만, 아마 오늘 제가 설명드릴 패키지 설치 방식의 Tomcat 설치 방법은 없을 것입니다. 

 

이제 시작합니다. 이미 EC2에는 접속하셨겠죠? Apache Tomcat과 같은 WAS를 설치하려면 당연히 그 전에 자바 프로그램이 깔려있어야 할 것인데요, 자바가 설치되어 있는지 확인해 보겠습니다.

[ec2-user@ip-172-00-0-000 ~]$ java -version
java version "1.7.0_101"
OpenJDK Runtime Environment (amzn-2.6.6.1.67.amzn1-x86_64 u101-b00)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

이미 잘 있습니다. OpenJDK 64비트 1.7.0_101 버전이라고 합니다. 이 자바가 어느 위치에 설치되어 있는지 확인해 보겠습니다.

[ec2-user@ip-172-00-0-000 ~]$ which java
/usr/bin/java
[ec2-user@ip-172-00-0-000 ~]$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22  6월  3 22:23 /usr/bin/java -> /etc/alternatives/java
[ec2-user@ip-172-00-0-000 ~]$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 46  6월  3 22:23 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java

따라서 일반적인 JAVA_HOME은 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64가 될 것 같습니다.

 

자바가 설치되어 있는 것은 잘 확인을 했고, 이제 본격적으로 Apache Tomcat을 설치할 것입니다. yum list 명령어를 이용하여 어떠한 패키지 설치가 가능한지 확인해 볼께요.

[ec2-user@ip-172-00-0-000 /]$ sudo yum list tomcat*
Loaded plugins: priorities, update-motd, upgrade-helper
Available Packages
tomcat-native.x86_64                      1.1.34-1.16.amzn1            amzn-main
tomcat6.noarch                            6.0.45-1.4.amzn1             amzn-updates
tomcat6-admin-webapps.noarch              6.0.45-1.4.amzn1             amzn-updates
tomcat6-docs-webapp.noarch                6.0.45-1.4.amzn1             amzn-updates
tomcat6-el-2.1-api.noarch                 6.0.45-1.4.amzn1             amzn-updates
tomcat6-javadoc.noarch                    6.0.45-1.4.amzn1             amzn-updates
tomcat6-jsp-2.1-api.noarch                6.0.45-1.4.amzn1             amzn-updates
tomcat6-lib.noarch                        6.0.45-1.4.amzn1             amzn-updates
tomcat6-servlet-2.5-api.noarch            6.0.45-1.4.amzn1             amzn-updates
tomcat6-webapps.noarch                    6.0.45-1.4.amzn1             amzn-updates
tomcat7.noarch                            7.0.69-1.16.amzn1            amzn-updates
tomcat7-admin-webapps.noarch              7.0.69-1.16.amzn1            amzn-updates
tomcat7-docs-webapp.noarch                7.0.69-1.16.amzn1            amzn-updates
tomcat7-el-2.2-api.noarch                 7.0.69-1.16.amzn1            amzn-updates
tomcat7-javadoc.noarch                    7.0.69-1.16.amzn1            amzn-updates
tomcat7-jsp-2.2-api.noarch                7.0.69-1.16.amzn1            amzn-updates
tomcat7-lib.noarch                        7.0.69-1.16.amzn1            amzn-updates
tomcat7-log4j.noarch                      7.0.69-1.16.amzn1            amzn-updates
tomcat7-servlet-3.0-api.noarch            7.0.69-1.16.amzn1            amzn-updates
tomcat7-webapps.noarch                    7.0.69-1.16.amzn1            amzn-updates
tomcat8.noarch                            8.0.35-1.60.amzn1            amzn-updates
tomcat8-admin-webapps.noarch              8.0.35-1.60.amzn1            amzn-updates
tomcat8-docs-webapp.noarch                8.0.35-1.60.amzn1            amzn-updates
tomcat8-el-3.0-api.noarch                 8.0.35-1.60.amzn1            amzn-updates
tomcat8-javadoc.noarch                    8.0.35-1.60.amzn1            amzn-updates
tomcat8-jsp-2.3-api.noarch                8.0.35-1.60.amzn1            amzn-updates
tomcat8-lib.noarch                        8.0.35-1.60.amzn1            amzn-updates
tomcat8-log4j.noarch                      8.0.35-1.60.amzn1            amzn-updates
tomcat8-servlet-3.1-api.noarch            8.0.35-1.60.amzn1            amzn-updates
tomcat8-webapps.noarch                    8.0.35-1.60.amzn1            amen-updates

뭐가 엄청 많네요. 자세히 모르지만 가장 만만해보이는 tomcat7-webapps.noarch를 골라보겠습니다.

[ec2-user@ip-172-00-0-000 /]$ sudo yum install tomcat7-webapps.noarch
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main/latest                                            | 2.1 kB     00:00
amzn-updates/latest                                         | 2.3 kB     00:00
Resolving Dependencies
--> Running transaction check
---> Package tomcat7-webapps.noarch 0:7.0.69-1.16.amzn1 will be installed
--> Processing Dependency: tomcat7 = 7.0.69-1.16.amzn1 for package: tomcat7-webapps-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: jakarta-taglibs-standard >= 1.1 for package: tomcat7-webapps-7.0.69-1.16.amzn1.noarch
--> Running transaction check
---> Package jakarta-taglibs-standard.noarch 0:1.1.1-11.7.9.amzn1 will be installed
--> Processing Dependency: xalan-j2 >= 2.6.0 for package: jakarta-taglibs-standard-1.1.1-11.7.9.amzn1.noarch
--> Processing Dependency: apache-tomcat-apis for package: jakarta-taglibs-standard-1.1.1-11.7.9.amzn1.noarch
---> Package tomcat7.noarch 0:7.0.69-1.16.amzn1 will be installed
--> Processing Dependency: tomcat7-lib = 7.0.69-1.16.amzn1 for package: tomcat7-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: apache-commons-logging for package: tomcat7-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: apache-commons-daemon for package: tomcat7-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: apache-commons-collections for package: tomcat7-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: apache-commons-dbcp for package: tomcat7-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: apache-commons-pool for package: tomcat7-7.0.69-1.16.amzn1.noarch
--> Running transaction check
---> Package apache-commons-collections.noarch 0:3.2.2-3.10.amzn1 will be installed
---> Package apache-commons-daemon.x86_64 0:1.0.7-1.6.amzn1 will be installed
---> Package apache-commons-dbcp.noarch 0:1.4-7.7.amzn1 will be installed
---> Package apache-commons-logging.noarch 0:1.1.1-16.8.amzn1 will be installed
---> Package apache-commons-pool.noarch 0:1.5.6-1.7.amzn1 will be installed
---> Package apache-tomcat-apis.noarch 0:0.1-1.6.amzn1 will be installed
---> Package tomcat7-lib.noarch 0:7.0.69-1.16.amzn1 will be installed
--> Processing Dependency: tomcat7-servlet-3.0-api = 7.0.69-1.16.amzn1 for package: tomcat7-lib-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: tomcat7-jsp-2.2-api = 7.0.69-1.16.amzn1 for package: tomcat7-lib-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: tomcat7-el-2.2-api = 7.0.69-1.16.amzn1 for package: tomcat7-lib-7.0.69-1.16.amzn1.noarch
--> Processing Dependency: ecj >= 1:4.2.1 for package: tomcat7-lib-7.0.69-1.16.amzn1.noarch
---> Package xalan-j2.noarch 0:2.7.0-9.9.10.amzn1 will be installed
--> Processing Dependency: jaxp_parser_impl for package: xalan-j2-2.7.0-9.9.10.amzn1.noarch
--> Running transaction check
---> Package ecj.x86_64 1:4.2.1-4.15.amzn1 will be installed
---> Package tomcat7-el-2.2-api.noarch 0:7.0.69-1.16.amzn1 will be installed
---> Package tomcat7-jsp-2.2-api.noarch 0:7.0.69-1.16.amzn1 will be installed
---> Package tomcat7-servlet-3.0-api.noarch 0:7.0.69-1.16.amzn1 will be installed
---> Package xerces-j2.noarch 0:2.7.1-12.7.19.amzn1 will be installed
--> Processing Dependency: xml-commons-apis >= 1.3 for package: xerces-j2-2.7.1-12.7.19.amzn1.noarch
--> Processing Dependency: xml-commons-resolver >= 1.1 for package: xerces-j2-2.7.1-12.7.19.amzn1.noarch
--> Running transaction check
---> Package xml-commons-apis.noarch 0:1.3.04-3.6.9.amzn1 will be installed
---> Package xml-commons-resolver.noarch 0:1.1-4.18.10.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package                      Arch     Version                Repository      Size
===================================================================================
Installing:
 tomcat7-webapps              noarch   7.0.69-1.16.amzn1      amzn-updates   391 k
Installing for dependencies:
 apache-commons-collections   noarch   3.2.2-3.10.amzn1       amzn-updates   531 k
 apache-commons-daemon        x86_64   1.0.7-1.6.amzn1        amzn-main       51 k
 apache-commons-dbcp          noarch   1.4-7.7.amzn1          amzn-main      161 k
 apache-commons-logging       noarch   1.1.1-16.8.amzn1       amzn-main      131 k
 apache-commons-pool          noarch   1.5.6-1.7.amzn1        amzn-main      101 k
 apache-tomcat-apis           noarch   0.1-1.6.amzn1          amzn-main      216 k
 ecj                          x86_64   1:4.2.1-4.15.amzn1     amzn-main      1.4 M
 jakarta-taglibs-standard     noarch   1.1.1-11.7.9.amzn1     amzn-main      306 k
 tomcat7                      noarch   7.0.69-1.16.amzn1      amzn-updates    94 k
 tomcat7-el-2.2-api           noarch   7.0.69-1.16.amzn1      amzn-updates    81 k
 tomcat7-jsp-2.2-api          noarch   7.0.69-1.16.amzn1      amzn-updates    93 k
 tomcat7-lib                  noarch   7.0.69-1.16.amzn1      amzn-updates   3.8 M
 tomcat7-servlet-3.0-api      noarch   7.0.69-1.16.amzn1      amzn-updates   212 k
 xalan-j2                     noarch   2.7.0-9.9.10.amzn1     amzn-main      1.8 M
 xerces-j2                    noarch   2.7.1-12.7.19.amzn1    amzn-main      1.1 M
 xml-commons-apis             noarch   1.3.04-3.6.9.amzn1     amzn-main      264 k
 xml-commons-resolver         noarch   1.1-4.18.10.amzn1      amzn-main       63 k

Transaction Summary
===================================================================================
Install  1 Package (+17 Dependent packages)

Total download size: 11 M
Installed size: 13 M
Is this ok [y/d/N]: y

단순히 하나의 패키지만 설치하는 것은 아니고 관련된 모든 패키지를 설치하게 됩니다. (알아서 다 설치해주니 정말 편리합니다) y를 눌러 계속 진행합니다.

Downloading packages:
(1/18): apache-commons-collections-3.2.2-3.10.amzn1.noarch. | 531 kB     00:00
(2/18): apache-commons-daemon-1.0.7-1.6.amzn1.x86_64.rpm    |  51 kB     00:00
(3/18): apache-commons-dbcp-1.4-7.7.amzn1.noarch.rpm        | 161 kB     00:00
(4/18): apache-commons-logging-1.1.1-16.8.amzn1.noarch.rpm  | 131 kB     00:00
(5/18): apache-commons-pool-1.5.6-1.7.amzn1.noarch.rpm      | 101 kB     00:00
(6/18): apache-tomcat-apis-0.1-1.6.amzn1.noarch.rpm         | 216 kB     00:00
(7/18): ecj-4.2.1-4.15.amzn1.x86_64.rpm                     | 1.4 MB     00:00
(8/18): jakarta-taglibs-standard-1.1.1-11.7.9.amzn1.noarch. | 306 kB     00:00
(9/18): tomcat7-7.0.69-1.16.amzn1.noarch.rpm                |  94 kB     00:00
(10/18): tomcat7-el-2.2-api-7.0.69-1.16.amzn1.noarch.rpm    |  81 kB     00:00
(11/18): tomcat7-jsp-2.2-api-7.0.69-1.16.amzn1.noarch.rpm   |  93 kB     00:00
(12/18): tomcat7-lib-7.0.69-1.16.amzn1.noarch.rpm           | 3.8 MB     00:00
(13/18): tomcat7-servlet-3.0-api-7.0.69-1.16.amzn1.noarch.r | 212 kB     00:00
(14/18): tomcat7-webapps-7.0.69-1.16.amzn1.noarch.rpm       | 391 kB     00:00
(15/18): xalan-j2-2.7.0-9.9.10.amzn1.noarch.rpm             | 1.8 MB     00:00
(16/18): xerces-j2-2.7.1-12.7.19.amzn1.noarch.rpm           | 1.1 MB     00:00
(17/18): xml-commons-apis-1.3.04-3.6.9.amzn1.noarch.rpm     | 264 kB     00:00
(18/18): xml-commons-resolver-1.1-4.18.10.amzn1.noarch.rpm  |  63 kB     00:00
-----------------------------------------------------------------------------------
Total                                                  11 MB/s |  11 MB  00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apache-commons-pool-1.5.6-1.7.amzn1.noarch                     1/18
  Installing : apache-commons-dbcp-1.4-7.7.amzn1.noarch                       2/18
  Installing : tomcat7-servlet-3.0-api-7.0.69-1.16.amzn1.noarch               3/18
  Installing : xml-commons-apis-1.3.04-3.6.9.amzn1.noarch                     4/18
  Installing : xerces-j2-2.7.1-12.7.19.amzn1.noarch                           5/18
  Installing : xml-commons-resolver-1.1-4.18.10.amzn1.noarch                  6/18
  Installing : tomcat7-el-2.2-api-7.0.69-1.16.amzn1.noarch                    7/18
  Installing : apache-commons-collections-3.2.2-3.10.amzn1.noarch             8/18
  Installing : tomcat7-jsp-2.2-api-7.0.69-1.16.amzn1.noarch                   9/18
  Installing : xalan-j2-2.7.0-9.9.10.amzn1.noarch                            10/18
  Installing : apache-commons-daemon-1.0.7-1.6.amzn1.x86_64                  11/18
  Installing : apache-tomcat-apis-0.1-1.6.amzn1.noarch                       12/18
  Installing : jakarta-taglibs-standard-1.1.1-11.7.9.amzn1.noarch            13/18
  Installing : apache-commons-logging-1.1.1-16.8.amzn1.noarch                14/18
  Installing : 1:ecj-4.2.1-4.15.amzn1.x86_64                                 15/18
  Installing : tomcat7-lib-7.0.69-1.16.amzn1.noarch                          16/18
  Installing : tomcat7-7.0.69-1.16.amzn1.noarch                              17/18
  Installing : tomcat7-webapps-7.0.69-1.16.amzn1.noarch                      18/18
  Verifying  : apache-commons-pool-1.5.6-1.7.amzn1.noarch                     1/18
  Verifying  : apache-commons-collections-3.2.2-3.10.amzn1.noarch             2/18
  Verifying  : 1:ecj-4.2.1-4.15.amzn1.x86_64                                  3/18
  Verifying  : tomcat7-webapps-7.0.69-1.16.amzn1.noarch                       4/18
  Verifying  : xalan-j2-2.7.0-9.9.10.amzn1.noarch                             5/18
  Verifying  : tomcat7-7.0.69-1.16.amzn1.noarch                               6/18
  Verifying  : tomcat7-lib-7.0.69-1.16.amzn1.noarch                           7/18
  Verifying  : tomcat7-el-2.2-api-7.0.69-1.16.amzn1.noarch                    8/18
  Verifying  : xml-commons-apis-1.3.04-3.6.9.amzn1.noarch                     9/18
  Verifying  : apache-commons-logging-1.1.1-16.8.amzn1.noarch                10/18
  Verifying  : apache-tomcat-apis-0.1-1.6.amzn1.noarch                       11/18
  Verifying  : tomcat7-servlet-3.0-api-7.0.69-1.16.amzn1.noarch              12/18
  Verifying  : apache-commons-dbcp-1.4-7.7.amzn1.noarch                      13/18
  Verifying  : jakarta-taglibs-standard-1.1.1-11.7.9.amzn1.noarch            14/18
  Verifying  : apache-commons-daemon-1.0.7-1.6.amzn1.x86_64                  15/18
  Verifying  : xerces-j2-2.7.1-12.7.19.amzn1.noarch                          16/18
  Verifying  : tomcat7-jsp-2.2-api-7.0.69-1.16.amzn1.noarch                  17/18
  Verifying  : xml-commons-resolver-1.1-4.18.10.amzn1.noarch                 18/18

Installed:
  tomcat7-webapps.noarch 0:7.0.69-1.16.amzn1

Dependency Installed:
  apache-commons-collections.noarch 0:3.2.2-3.10.amzn1
  apache-commons-daemon.x86_64 0:1.0.7-1.6.amzn1
  apache-commons-dbcp.noarch 0:1.4-7.7.amzn1
  apache-commons-logging.noarch 0:1.1.1-16.8.amzn1
  apache-commons-pool.noarch 0:1.5.6-1.7.amzn1
  apache-tomcat-apis.noarch 0:0.1-1.6.amzn1
  ecj.x86_64 1:4.2.1-4.15.amzn1
  jakarta-taglibs-standard.noarch 0:1.1.1-11.7.9.amzn1
  tomcat7.noarch 0:7.0.69-1.16.amzn1
  tomcat7-el-2.2-api.noarch 0:7.0.69-1.16.amzn1
  tomcat7-jsp-2.2-api.noarch 0:7.0.69-1.16.amzn1
  tomcat7-lib.noarch 0:7.0.69-1.16.amzn1
  tomcat7-servlet-3.0-api.noarch 0:7.0.69-1.16.amzn1
  xalan-j2.noarch 0:2.7.0-9.9.10.amzn1
  xerces-j2.noarch 0:2.7.1-12.7.19.amzn1
  xml-commons-apis.noarch 0:1.3.04-3.6.9.amzn1
  xml-commons-resolver.noarch 0:1.1-4.18.10.amzn1

Complete!

 

잘 설치된 것 같습니다. 이제 tomcat7 서비스를 시작하겠습니다.

[ec2-user@ip-172-00-0-000 /]$ sudo service tomcat7 start

잘 시작되었는지 "java" 프로세스를 찾아볼께요.

[ec2-user@ip-172-00-0-000 /]$ ps -ef | grep java | grep -v grep
tomcat   32059     1 17 12:12 ?        00:00:03 /usr/lib/jvm/jre/bin/java -classpath :/usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat7/temp -Djava.util.logging.config.file=/usr/share/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start

Tomcat이 사용하는 포트 오픈 여부도 확인합니다.

[ec2-user@ip-172-00-0-000 /]$ netstat -an | grep 8080
tcp        0      0 :::8080                     :::*                        LISTEN
[ec2-user@ip-172-00-0-000 /]$ netstat -an | grep 8009
tcp        0      0 :::8009                     :::*                        LISTEN
[ec2-user@ip-172-00-0-000 /]$ netstat -an | grep 8005
tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN

 

이제 서버 로컬 환경에서 8080 포트에 접속해 보겠습니다.

[ec2-user@ip-172-00-0-000 /]$ curl http://127.0.0.1:8080

<!DOCTYPE html>


<html lang="en">
    <head>
        <title>Apache Tomcat/7.0.69</title>
        <link href="/favicon.ico" rel="icon" type="image/x-icon" />
        <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <link href="/tomcat.css" rel="stylesheet" type="text/css" />
    </head>
(생략)

성공적으로 접속되었습니다.

 

마지막으로 PC에서 브라우저로 접속을 해보겠습니다.

(페이지 열리지 않음)

그 이유는 Security Group을 통해 8080 포트가 열려있지 않기 때문입니다. 지금부터 Security Group 설정을 통해 8080 포트 오픈 방법을 알려드리겠습니다.

 

AWS 내 EC2 Management Console에 접속합니다.

 

Security Groups가 보이실 겁니다. 클릭합니다. 그리고 나서 [Create Security Group] 버튼을 클릭합니다.

 

외부에서 접속을 허용해야 하므로 "Inbound" 탭을 선택한 후, 8080 포트로 접속을 허용하고자 하는 IP 혹은 IP 대역을 입력합니다.

입력이 끝나면 저장을 하고 나옵니다.

 

자, 여기까지 새로운 Tomcat용 Security Group을 만들었습니다. 이제 EC2 Linux 인스턴스에 이 Security Group을 적용시켜 주어야 합니다. Security Group만 만들어서는 기존 EC2 Linux 인스턴스에 어떠한 영향을 끼치지 않습니다. 

 

아래와 같이 새로 만든 "sg-mytomcat"이라는 Security Group을 Assign합니다.

 

자! 다 끝났습니다. 이제 브라우저에서 Tomcat 화면을 확인할 수 있습니다.




출처 : http://sarc.io/index.php/aws/520-aws-ec2-linux-10-apache-tomcat