Tomcat
    • PDF

    Tomcat

    • PDF

    Article Summary

    Classic/VPC 환경에서 이용 가능합니다.

    Tomcat은 Linux를 운영 체제로 사용하면서 Tomcat을 활용한 웹 애플리케이션 서버 및 서블릿 컨테이너 플랫폼입니다. 안정성이 우수한 네이버 클라우드 플랫폼의 Compute 인프라 서비스에 자동으로 구성되며, 몇 단계의 설정을 통해 즉시 서비스를 시작할 수 있습니다.

    Tomcat 사용의 이점은 다음과 같습니다.

    • 네이버 클라우드 플랫폼의 인프라 서비스를 활용하여 안정적으로 Tomcat을 이용할 수 있습니다.
    • 서버 이미지와 스펙을 선택하여 Tomcat 서버를 자동으로 설치하고 이용할 수 있습니다.
    참고

    네이버 클라우드 플랫폼의 Tomcat에서 사용되는 소프트웨어에 대한 자세한 내용은 다음 웹 사이트에서 확인해 주십시오.

    서버 생성 및 접속

    서버 생성 및 접속 방법은 네이버 클라우드 플랫폼의 일반 서버 생성 방법과 동일합니다. 자세한 절차 및 참고할 만한 가이드는 다음과 같습니다.

    절차설명
    1. ACG 설정
    • 참고 가이드: ACG(Classic) 또는 ACG(VPC)
    • 다음 포트 설정 필요
      • 터미널 접속을 위한 TCP 22 포트
      • 웹 서비스 이용을 위한 TCP 18080 포트
    2. 서버 생성
    3. 공인 IP 설정
    4. 포트 포워딩 설정(Classic 전용)
    5. 관리자 비밀번호 확인
    6. 서버 접속
    참고
    • 서버에 접속하여 로그인한 후에는 root 계정의 비밀번호를 기억할 수 있는 다른 비밀번호로 변경하기를 권장합니다. passwd root 명령어를 입력하여 새로운 비밀번호를 설정해 주십시오.
    • 공인 IP 주소와 ACG에 문제가 없어도 Tomcat Web 서비스에 접속되지 않는다면 웹 서버 프로세스가 정지된 것일 수 있습니다. 터미널 프로그램에서 재시작 명령어(systemctl start httpd)를 실행하여 프로세스를 다시 시작해 주십시오.

    서버 사용

    서버가 생성되면 자동으로 Tomcat 웹 애플리케이션 서버가 설치되어 쉽게 사용할 수 있습니다.
    서버에 접속한 상태에서 다음 명령어를 사용할 수 있습니다.

    • 서비스 정지: systemctl stop tomcat
    • 서비스 실행: systemctl start tomcat
    • 서비스 상태 확인
      [root@tomcat-c73 ~]# systemctl status tomcat
        ● tomcat.service - Apache Tomcat Web Application Container
            Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
            Active: active (running) since Wed 2022-10-05 13:11:14 KST; 10s ago
            Process: 6448 ExecStop=/opt/tomcat/bin/shutdown.sh (code=exited, status=0/SUCCESS)
            Process: 6530 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
          Main PID: 6537 (java)
            CGroup: /system.slice/tomcat.service
                    └─6537 /usr/lib/jvm/jre/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.ap...
      
        Oct 05 13:11:14 tomcat-c73 systemd[1]: Starting Apache Tomcat Web Application Container...
        Oct 05 13:11:14 tomcat-c73 startup.sh[6530]: Tomcat started.
        Oct 05 13:11:14 tomcat-c73 systemd[1]: Started Apache Tomcat Web Application Container.
      
    • 서비스 포트 상태 확인
       [root@tomcat-c73 ~]# netstat -na | grep 18080
        tcp        0      0 0.0.0.0:18080           0.0.0.0:*               LISTEN
      
    • 버전 정보 확인
        [root@tomcat-c73 ~]# /opt/tomcat/bin/version.sh
        Using CATALINA_BASE:   /opt/tomcat
        Using CATALINA_HOME:   /opt/tomcat
        Using CATALINA_TMPDIR: /opt/tomcat/temp
        Using JRE_HOME:        /usr
        Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
        Using CATALINA_OPTS:
        Server version: Apache Tomcat/8.5.78
        Server built:   Mar 31 2022 16:05:28 UTC
        Server number:  8.5.78.0
        OS Name:        Linux
        OS Version:     3.10.0-514.2.2.el7.x86_64
        Architecture:   amd64
        JVM Version:    1.8.0_345-b01
        JVM Vendor:     Red Hat, Inc.
      

    웹 브라우저 확인

    서버가 할당된 공인 IP에 포트가 정상적으로 동작하는지 확인할 수 있습니다.

    웹 브라우저를 실행한 후 URL을 입력해 주십시오.

    http(s)://(공인 IP 주소):(Tomcat 서비스 포트)
    

    정상 동작할 경우 Tomcat 기본 페이지가 표시됩니다.

    Manager 모듈 웹 실행 예제

    계정 정보를 설정하여 Tomcat Manager와 Tomcat Host Manager 모듈을 웹에서 실행할 수 있습니다.

    주의

    Tomcat 서버의 보안을 위해 Tomcat Manager와 Tomcat Host Manager는 비활성화 상태로 두길 권장합니다. 필요한 경우에만 접근 가능한 IP 대역을 설정하여 특정 운영자 및 대역에서 접근할 수 있게 해 주십시오.

    1. 서버에 접속한 상태에서 vi /opt/tomcat/conf/tomcat-users.xml 명령어를 입력해 주십시오.
      • Tomcat Manager 접근 계정을 설정할 수 있는 편집기가 열립니다.
    2. [I] 키를 눌러 입력 모드를 켠 후 user 입력 영역에 접근 계정 정보를 추가해 주십시오.
      • 이 예제에서는 username이 admin으로, 비밀번호는 password로 입력되어 있고 Manager와 Host Manager 모두 접근 권한을 부여합니다.
      <?xml version="1.0" encoding="UTF-8"?>
      <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
      
      ...(중략)
      
      The users below are wrapped in a comment and are therefore ignored. If you
      wish to configure one or more of these users for use with the manager web
      application, do not forget to remove the <!.. ..> that surrounds them. You
      will also need to set the passwords to something appropriate.
      -->
      
      <user username="admin" password="password" roles="manager-gui,admin-gui"/>
      
      <!--
      The sample user and role entries below are intended for use with the
      examples web application. They are wrapped in a comment and thus are ignored
      when reading this file. If you wish to configure these users for use with the
      examples web application, do not forget to remove the <!.. ..> that surrounds
      them. You will also need to set the passwords to something appropriate.
      -->
      
      ...(중략)
      
      </tomcat-users>
      
    3. 정보 입력을 완료했다면 [Esc] 키를 눌러 입력 모드를 끈 후 :wq 명령어를 입력해 편집기를 종료해 주십시오.
    4. vi /opt/tomcat/webapps/manager/META-INF/context.xml 명령어를 입력해 주십시오.
      • Tomcat Manager 접근 IP 범위를 설정할 수 있는 편집기가 열립니다.
    5. [I] 키를 눌러 입력 모드를 켠 후 원격 접속 허용 IP의 범위를 변경해 주십시오.
      • 이 예제에서는 모든 IP 대역에서 접근이 가능하도록 Valve 정보를 주석 처리합니다.
      <?xml version="1.0" encoding="UTF-8"?>
      <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
      
      ...(중략)
      
      <Context antiResourceLocking="false" privileged="true" >
      <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                      sameSiteCookies="strict" />
      <!--
      <Valve className="org.apache.catalina.valves.RemoteAddrValve"
              allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
      -->
      <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
      </Context>
      
    6. [Esc] 키를 눌러 입력 모드를 끈 후 :wq을 입력해 편집기를 종료해 주십시오.
    7. vi /opt/tomcat/webapps/host-manager/META-INF/context.xml 명령어를 입력해 주십시오.
      • Tomcat Host Manager 접근 IP 범위를 설정할 수 있는 편집기가 열립니다.
    8. [I] 키를 눌러 입력 모드를 켠 후 원격 접속 허용 IP의 범위를 변경해 주십시오.
      • 이 예제에서는 모든 IP 대역에서 접근이 가능하도록 Valve 정보를 주석 처리합니다.
      <?xml version="1.0" encoding="UTF-8"?>
      <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
      
      ...(중략)
      
      <Context antiResourceLocking="false" privileged="true" >
      <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                      sameSiteCookies="strict" />
      <!--
      <Valve className="org.apache.catalina.valves.RemoteAddrValve"
              allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
      -->
      <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
      </Context>
      
    9. [Esc] 키를 눌러 입력 모드를 끈 후 :wq을 입력해 편집기를 종료해 주십시오.
    10. systemctl restart tomcat 명령어를 입력해 Tomcat을 재시작해 주십시오.
    11. 웹 브라우저에서 URL을 입력해 Tomcat Manager 또는 Tomcat Host Manager 페이지에 접속해 주십시오.
      • Tomcat Manager 페이지: http(s)://(공인 IP 주소):(Tomcat 서비스 포트)/manager/html
      • Tomcat Host Manager 페이지: http(s)://(공인 IP 주소):(Tomcat 서비스 포트)/host-manager/html
    12. 로그인 팝업 창이 나타나면 2번 절차에서 생성했던 username과 비밀번호를 입력한 후 [로그인] 버튼을 클릭해 주십시오.
      • 정상적으로 로그인되면 Tomcat 웹 애플리케이션 매니저 페이지 또는 Tomcat 가상 호스트 매니저 페이지가 표시됩니다. 이제 원하는 명령을 실행할 수 있습니다.

    이 문서가 도움이 되었습니까?

    What's Next
    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.