1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS Elastic Beanstalk + Javaアプリケーション + Instana Agent導入手順

Posted at

この手順では、AWS Elastic BeanstalkにJavaアプリケーション(Tomcat)をデプロイし、Instana Agentでモニタリングする方法を説明します。

1. 環境準備

1.1. AWS Cloud Shellでの準備

AWS Cloud Shellを開き、以下のコマンドを実行します。

# Elastic Beanstalk CLIのインストール
git clone https://github.com/aws/aws-elastic-beanstalk-cli-setup.git
pip install virtualenv
python ./aws-elastic-beanstalk-cli-setup/scripts/ebcli_installer.py

# パスの設定
echo 'export PATH="/home/cloudshell-user/.ebcli-virtual-env/executables:$PATH"' >> ~/.bashrc
source ~/.bashrc

# インストール確認
eb --version

2. サンプルアプリケーションの準備

2.1. Tomcatサンプルアプリのダウンロード

# 作業ディレクトリ作成
mkdir -p eb-tomcat1
cd eb-tomcat1

# サンプルアプリケーションのダウンロード
wget https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/samples/tomcat.zip
unzip tomcat.zip

2.2. Instana Agent設定の追加

# .ebextensionsディレクトリの作成
mkdir -p .ebextensions

# Instana Agent設定ファイル
cat > .ebextensions/instana-agent.config << 'EOF'
commands:
  01_install_instana:
    command: |
      curl -o setup.sh https://setup.instana.io/agent && chmod +x setup.sh && ./setup.sh -a YOUR_INSTANA_AGENT_KEY -t dynamic
EOF

# GP3ディスク設定(Amazon Linux 2023必須設定)
cat > .ebextensions/storage.config << 'EOF'
option_settings:
  aws:autoscaling:launchconfiguration:
    RootVolumeType: gp3
EOF

# 環境変数の設定(アプリケーション名などを設定)
cat > .ebextensions/options.config << 'EOF'
option_settings:
  aws:elasticbeanstalk:application:environment:
    INSTANA_SERVICE_NAME: "beanstalk-tomcat"
EOF

重要: YOUR_INSTANA_AGENT_KEYを実際のInstanaエージェントキーに置き換えてください。

3. Elastic Beanstalk環境の初期化と作成

3.1. 環境の初期化

# EB環境の初期化
eb init

# プロンプト選択例:
# - リージョン: 9) ap-northeast-1(東京)
# - アプリケーション: 9) [ Create new Application ]
# - アプリケーション名: デフォルト名を使用またはカスタム名を入力
# - Tomcatの確認: Y
# - プラットフォーム: 6) Tomcat 9 with Corretto 11 running on 64bit Amazon Linux 2023
# - SSHセットアップ: Y(必要に応じて)
# - キーペア選択: 既存のキーまたは新規作成

3.2. 環境の作成

# 環境の作成(m5.largeインスタンスタイプを指定)
eb create eb-tomcat-dev --instance-type m5.large

# または単にデフォルト設定で作成
# eb create --single

3.3. デプロイ状態の確認

# 環境の状態確認
eb status

# 出力例:
# Environment details for: eb-tomcat12-dev
#   Application name: eb-tomcat12
#   Region: ap-northeast-1
#   Platform: arn:aws:elasticbeanstalk:ap-northeast-1::platform/Tomcat 9 with Corretto 11 running on 64bit Amazon Linux 2023/5.5.0
#   Tier: WebServer-Standard-1.0
#   CNAME: eb-tomcat12-dev.eba-nkspumaa.ap-northeast-1.elasticbeanstalk.com
#   Status: Ready
#   Health: Green

3.4. アプリケーションの確認

# ブラウザでアプリケーションを開く
eb open

4. Instana Agentの確認

4.1. EC2インスタンスへの接続

# SSHで接続
eb ssh

# Instana Agentのステータス確認
sudo systemctl status instana-agent

# 出力例:
# ● instana-agent.service - "Instana(tm) agent."
#      Loaded: loaded (/usr/lib/systemd/system/instana-agent.service; enabled; preset: disabled)
#     Drop-In: /etc/systemd/system/instana-agent.service.d
#              └─agent-custom-start.conf, custom-environment.conf
#      Active: active (running) since Thu 2025-03-06 16:06:29 UTC; 7s ago
#    Main PID: 3675 (java)
#       Tasks: 28 (limit: 9245)
#      Memory: 170.3M

4.2. Instana設定の確認と修正

# Instana設定ディレクトリに移動
cd /opt/instana/agent/etc/instana/

# 設定確認
ls -la

# 設定ファイルの編集(タグの追加など)
sudo vi configuration.yaml

# 変更例:
# com.instana.plugin.host:
#   tags:
#     - 'beanstalk'

# エージェントを再起動して変更を適用
sudo systemctl restart instana-agent

4.3. ログの確認

# ログファイルの確認
cd /opt/instana/agent/data/log/
cat agent.log

5. Instanaダッシュボードでの確認

  1. Instanaダッシュボードにログイン
  2. プラットフォーム→インフラストラクチャマップからEC2インスタンスを確認
  3. 「beanstalk」タグでフィルタリング(設定した場合)
  4. トレースの確認

6. 環境の削除(不要になった場合)

# 環境の削除
eb terminate

注意点

  1. 本番環境では適切なインスタンスタイプ(m5.large以上推奨)を使用する
  2. デフォルトのt3.microインスタンスはリソース不足になる可能性がある
  3. Amazon Linux 2023では、GP3ディスク設定が必要
  4. Instana Agentには適切なネットワーク接続(アウトバウンド通信)が必要
  5. Java/Tomcatのバージョンと互換性のあるInstana Agentバージョンを使用する

付録: 動作確認した環境

  • Java バージョン: Amazon Corretto 11
  • Tomcat バージョン: Tomcat 9
  • Elastic Beanstalk プラットフォーム: Tomcat 9 with Corretto 11 running on 64bit Amazon Linux 2023/5.5.0
  • インスタンスタイプ: m5.large
  • リージョン: ap-northeast-1 (東京)
  • Instana Agent バージョン: 最新
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?