LoginSignup
3
6

More than 5 years have passed since last update.

AWS CloudWatch Log を使って httpd ログを監視してみる

Last updated at Posted at 2016-11-15

手順

  • IAM ロールに権限を付与
  • EC2 に監視対象となる httpd をインストール・起動
  • EC2 に CloudWatch agent をインストール・起動
  • CloudWatch Log の画面で確認

IAM ロールに権限を付与

今回はここを設定するつようがなかったので、割愛。
必要な場合は以下を参照。
http://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/logs/QuickStartEC2Instance.html

EC2 に監視対象となる httpd をインストール・起動

$ sudo yum install httpd -y
$ sudo service httpd start

EC2 に ClodWatch agent をインストール・起動

$ sudo yum update -y
$ sudo yum install -y awslogs

次に、設定を変更。

$ sudo cat /etc/awslogs/awscli.conf
[plugins]
cwlogs = cwlogs
[default]
region = us-east-1

$ sudo vim /etc/awslogs/awscli.conf
$sudo cat /etc/awslogs/awscli.conf
[plugins]
cwlogs = cwlogs
[default]
region = ap-northeast-1
aws_access_key_id = <YOUR ACCESS KEY>
aws_secret_access_key = <YOUR SECRET KEY>

<YOUR ACCESS KEY>, <YOUR SECRET KEY> は適切なものに変更。
また、ここでは東京リージョン(ap-northeast-1)を設定していますが、ここで設定したリージョンにロググループ・ログストリームが作成されるので注意。
次に、監視対象のファイルと送信先を設定。
デフォルトでは /var/log/messages が設定されているので、それに加えて、httpd のログ(/var/log/httpd/access.log)を設定してみる。/etc/awslogs/awslogs.conf の末尾に以下を追加。

[/var/log/httpd/access_log]
datetime_format = %b %d %H:%M:%S
file = /var/log/httpd/access_log
buffer_duration = 5000
log_stream_name = hogehoge
initial_position = start_of_file
log_group_name = /var/log/httpd/access_log

agent を起動。

$ sudo service awslogs start

下記を実行してエラーが出ていないかを確認。

$ cat /var/log/awslogs.log

agent を自動起動するように設定。

$ sudo chkconfig awslogs on

CloudWatch Log の画面で確認

CloudWatch Log の画面でログが反映されているのを確認します。
httpd にアクセスするために、適当に curlコマンドを実行。

$ curl localhost:80

上記の設定では、東京リージョンに、/var/log/httpd/access_logというロググループの中にhogehogeというログストリームが作成されていると思います。
ログストリームhogehogeに該当ログが表示されていれば成功です。

参考URL

3
6
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
3
6