演習 - JBoss EAP 管理ツールとアプリケーション ログにアクセスする

完了

この演習では、JBoss 管理ツールにアクセスして、アプリケーション ログをストリーミングします。

TCP トンネルの作成

リモート サーバーにアクセスするには、リモート サーバーとローカル コンピューターの間に TCP トンネルを作成する必要があります。 次のコマンドを実行します。

az webapp create-remote-connection -n ${WEBAPP_NAME} -g ${RESOURCEGROUP_NAME}

このコマンドでは、次の結果が返されます。

Verifying if app is running....
App is running. Trying to establish tunnel connection...
Opening tunnel on port: 59445
SSH is available { username: root, password: Docker! }
Ctrl + C to close

コマンドの結果から次の情報を取得します。

必要な情報
Opening tunnel on port PORT_NUMBER (例: 59445)
username root
password Docker!

パスワードとポート番号をメモします。 この 2 つの値は次のセクションで使用します。

SSH と TCP トンネルを使用してサインインする

次に、ssh コマンドを使用してサーバーにサインインする必要があります。 新しいコマンド ターミナルを開き、次のコマンドを実行します。

export PORT_NUMBER=<the port number from above>
ssh root@127.0.0.1 -L 9990:localhost:9990 -p $PORT_NUMBER 

ヒント

JBoss EAP 管理 Web コンソールにアクセスする場合は、-L 9990:localhost:9990 オプションを指定します。 次に、JBoss Web コンソールの http://localhost:9990/console にアクセスします。 JBoss Web コンソールにサインインする必要がない場合は、"-L" オプションを削除できます。

サーバーにサインインしたとき、次のメッセージが表示されます。

The authenticity of host '[127.0.0.1]:59445 ([127.0.0.1]:59445)' can't be established.
ECDSA key fingerprint is SHA256:vHsp1b3+7NtnHISvZ6aKS82pww+e5L6CUc9fKaPZGDQ.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[127.0.0.1]:59445' (ECDSA) to the list of known hosts.
root@127.0.0.1's password:
   _|_|
 _|    _|  _|_|_|_|  _|    _|  _|  _|_|    _|_|
 _|_|_|_|      _|    _|    _|  _|_|      _|_|_|_|
 _|    _|    _|      _|    _|  _|        _|
 _|    _|  _|_|_|_|    _|_|_|  _|          _|_|_|

     J A V A   O N   A P P   S E R V I C E

Documentation: https://aka.ms/appservice

**NOTE**: No files or system changes outside of /home will persist beyond your application's current session. /home is your application's persistent storage and is shared across all the server instances.

JBoss CLI コマンドを実行する

リモート サーバーにサインインすると、JBoss EAP 管理 CLI ツールを jboss-cli.sh として実行できます。 この CLI コマンドは /opt/eap/bin/ ディレクトリにあります。

次のコマンドを使用して JBoss EAP に接続します。

/opt/eap/bin/jboss-cli.sh --connect
Picked up JAVA_TOOL_OPTIONS: -Xmx2402M -Djava.net.preferIPv4Stack=true 

JBoss EAP サーバーに接続したら、JBoss CLI コマンドを実行して、JBoss サーバーの情報を取得します。

[standalone@localhost:9990 /] :product-info
{
    "outcome" => "success",
    "result" => [{"summary" => {
        "host-name" => "295cf7c97684",
        "instance-identifier" => "24bb4e37-ac89-42bc-b87e-d635d37a56f3",
        "product-name" => "JBoss EAP",
        "product-version" => "7.4.2.GA",
        "product-community-identifier" => "Product",
        "product-home" => "/opt/eap",
        "last-update-date" => "4/26/22, 10:29 PM",
        "standalone-or-domain-identifier" => "STANDALONE_SERVER",
        "host-operating-system" => "Ubuntu 20.04.4 LTS",
        "host-cpu" => {
            "host-cpu-arch" => "amd64",
            "host-core-count" => 2
        },
        "jvm" => {
            "name" => "OpenJDK 64-Bit Server VM",
            "java-version" => "11",
            "jvm-version" => "11.0.14.1",
            "jvm-vendor" => "Microsoft",
            "java-home" => "/usr/lib/jvm/msopenjdk-11-amd64"
        }
    }}]

次のコマンドから、デプロイされているすべてのアプリケーションを取得できます。

[standalone@localhost:9990 /] ls deployment
ROOT.war

次に、次のコマンドを実行して、データベース接続をテストします。

[standalone@localhost:9990 /] /subsystem=datasources/data-source="JPAWorldDataSourceDS":test-connection-in-pool
{
    "outcome" => "success",
    "result" => [true]
}

JBoss EAP CLI を終了します。

exit

JBoss EAP 管理 Web コンソールにアクセスする

次に、JBoss 管理 Web コンソールにアクセスしましょう。

まず、認証用の管理者ユーザーとパスワードを作成します。

/opt/eap/bin/add-user.sh -u admin -p admin -r ManagementRealm

次のような出力が表示されます。

Picked up JAVA_TOOL_OPTIONS: -Xmx5480M -Djava.net.preferIPv4Stack=true
Updated user 'admin' to file '/opt/eap/standalone/configuration/mgmt-users.properties'
Updated user 'admin' to file '/opt/eap/domain/configuration/mgmt-users.properties'

これで、ローカル環境から Web コンソールにアクセスできるようになります。 ブラウザーを使用して、次の URL にアクセスします。

http://127.0.0.1:9990/console

認証ダイアログ ボックスで、前に作成したユーザー名とパスワードを使用してサインインします。

Screenshot that shows the authentication dialog box for the admin console.

Web コンソールにサインインすると、次の画面が表示されます。

Screenshot that shows the main page of the admin console.

作成したデータ ソースは、[Configuration]\(構成\)>[Subsystems]\(サブシステム\)>[Datasources & Drivers]\(データソースとドライバー\)>[Datasources]\(データソース\) から確認できます。

Screenshot that shows the list of data sources on the admin console.

[Runtime](ランタイム)>[System](システム)>[JAX-RS]>[Your Application](アプリケーション) から、アプリケーションの RESTful エンドポイントを確認することもできます。

Screenshot that shows RESTful endpoints on the admin console.

警告

JBoss CLI コマンドまたは Web コンソールを使用してリモート サーバーに直接アクセスし、構成を追加または更新すると、Azure App Service インスタンスの再起動後に構成が消去され、削除されます。 構成を永続化するには、スタートアップ スクリプトでこれを構成します。 たとえば、前のユニットではスタートアップ スクリプトとして createMySQLDataSource.sh を作成しました。

ログ ストリームを開く

次に、サーバーにサインインし、アプリケーション ログにアクセスします。 次のコマンドを使用してローカル コンピューターにサインインすることにより、ログにアクセスできます。

az webapp log tail --name ${WEBAPP_NAME} --resource-group ${RESOURCEGROUP_NAME}

コマンドを実行すると、ログ出力が表示されます。

az webapp log tail  -n jakartaee-app-on-jboss-1606464084546 \
  -g jakartaee-app-on-jboss-1606464084546-rg

2020-12-09T02:23:24.412067731Z: [INFO]  02:23:24,411 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 82) WFLYUT0021: Registered web context: '/' for server 'default-server'
2020-12-09T02:23:24.455340165Z: [INFO]  02:23:24,453 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0010: Deployed "ROOT.war" (runtime-name : "ROOT.war")
2020-12-09T02:23:24.464834646Z: [INFO]  02:23:24,456 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 45) WFLYSRV0010: Deployed "activemq-rar.rar" (runtime-name : "activemq-rar.rar")
2020-12-09T02:23:24.674103836Z: [INFO]  02:23:24,673 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
2020-12-09T02:23:24.676640538Z: [INFO]  02:23:24,675 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: JBoss EAP 7.2.9.GA (WildFly Core 6.0.30.Final-redhat-00001) started in 25914ms - Started 537 of 709 services (345 services are lazy, passive or on-demand)
2020-12-09T02:23:24.680203180Z: [INFO]  02:23:24,679 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
2020-12-09T02:23:24.680950010Z: [INFO]  02:23:24,680 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990

演習の概要

このユニットでは、Java EE 8 (Jakarta EE) アプリケーションを構成して、JBoss EAP on Azure App Service にデプロイする方法を学習しました。 次に、DataSource オブジェクトを使用して、スタートアップ スクリプトで MySQL を JBoss EAP に接続しました。

また、CLI と GUI の両方から TCP トンネルを使用してリモート サーバーにアクセスする方法についても学習しました。 最後に、ローカル コンピューターからログ ファイルにアクセスしました。