Tomcat
    • PDF

    Tomcat

    • PDF

    Article Summary

    Classic/VPC環境で利用できます。

    Tomcatは、Linuxを OSとして使用しながら本サービスを活用したウェブアプリケーションサーバおよびサーブレットコンテナプラットフォームです。安定性に優れた NAVERクラウドプラットフォームの Computeインフラサービスに自動的に構成され、いくつかの段階の設定を行うことですぐにサービスを開始できます。

    Tomcatを使用するメリットは、次の通りです。

    • NAVERクラウドプラットフォームのインフラサービスを活用して、安定的に Tomcatを利用できます。
    • サーバイメージとスペックを選択して Tomcatサーバを自動的にインストールして利用できます。
    参考

    NAVERクラウドプラットフォームの Tomcatで使用されるソフトウェアの詳細については、次のウェブサイトでご確認ください。

    サーバ作成とアクセス

    サーバの作成とアクセス方法は、NAVERクラウドプラットフォームの一般的なサーバ作成方法と同じです。詳しい手順と参考になるガイドは、次の通りです。

    手順説明
    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>
    
    1. 情報入力が完了したら、 [Esc] キーを押して入力モードをオフにし、:wqコマンドを入力してエディタを終了します。
    2. vi /opt/tomcat/webapps/manager/META-INF/context.xmlコマンドを入力します。
      • Tomcat Managerのアクセス IPアドレス範囲を設定できるエディタが開きます。
    3. [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>
    
    1. [Esc] キーを押して入力モードをオフにした後、:wqを入力してエディタを終了します。
    2. vi /opt/tomcat/webapps/host-manager/META-INF/context.xmlコマンドを入力します。
      • Tomcat Host Managerのアクセス IPアドレス範囲を設定できるエディタが開きます。
    3. [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>
    
    1. [Esc] キーを押して入力モードをオフにした後、:wqを入力してエディタを終了します。
    2. systemctl restart tomcatコマンドを入力して Tomcatを再起動します。
    3. ウェブブラウザで URLを入力し、Tomcat Managerまたは Tomcat Host Managerページにアクセスします。
      • Tomcat Managerページ: http(s)://(グローバル IPアドレス):(Tomcatサービスポート)/manager/html
      • Tomcat Host Managerページ: http(s)://(グローバル IPアドレス):(Tomcatサービスポート)/host-manager/html
    4. ログインのポップアップが表示されたら、ステップ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.