0
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?

Cloudwatchlogs設定

0
Posted at

参考URL

事前準備(プライベートサブネット構成のため)

①エンドポイントを作成

モニター情報取得用
・com.amazonaws.ap-northeast-1.monitoring:Cloudwatchのエンドポイント
ログ情報取得用
・com.amazonaws.ap-northeast-1.logs:Cloudwatch Logsのエンドポイン

初回接続する必要があるそう。
・com.amazonaws.ap-northeast-1.ec2:EC2のエンドポイント

②セキュリティグループ作成(エンドポイントとEC2用)

・インバウンドルール
port:443 HTTPS

・アウトバウンドルール
port:443 HTTPS

・サブネット
通常お客様環境の場合は
エンドポイント専用にサブネットを作成する

③CloudWatchlogs側にロググループ作成

④Roleの作成

CloudWatchAgentAdminPolicyポリシーを付与

Cloud-watch-agentインストール

amazonlinuxを想定

sudo su -
dnf install amazon-cloudwatch-agent

ウィザードを進める。
後で記載修正もできるからデフォルトでもよいかも。

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

ファイル修正

vi /opt/aws/amazon-cloudwatch-agent/bin/config.json

ログを収集するための設定を入れました。

log_group_nameは事前準備で作成したもの

log_stream_name": "{instance_id}"は、いったんお試しにはいいが、ファイル名はきちんとつけたほうがいい。

{
        "agent": {
                "run_as_user": "root"
        },
        "logs": {
        "logs_collected": {
            "files": {
                "collect_list": [
                    {
                        "file_path": "/var/log/messages",
                        "log_group_class": "STANDARD",
                        "log_group_name": "zzzz",
                        "log_stream_name": "{instance_id}",
                        "retention_in_days": -1
                    }
                ]
            }
        }
    },
        "metrics": {
                "metrics_collected": {
                        "statsd": {
                                "metrics_aggregation_interval": 60,
                                "metrics_collection_interval": 10,
                                "service_address": ":1"
                        }
                }
        }
}

     

修正後反映コマンド

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl  -a fetch-config -m ec2  -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json

サービス状態確認

systemctl status amazon-cloudwatch-agent

仕上げ

EC2に事前準備で作成したロールを紐づける

cloudwatch-logs側を確認

ロググループのログストリームにログが記録されていること

0
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
0
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?