Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@eonishispi

CloudWatch エージェントをインストール

More than 1 year has passed since last update.

CloudWatch エージェントのインストール

$ cd /usr/local/src #自分でインストールしたライブラリはここに入れてる

$ sudo wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm

$ sudo rpm -U ./amazon-cloudwatch-agent.rpm

その後
IAMでアカウントを作成
シークレットコード、アクセスキーを取得する
アタッチするロールはよくわからないので
CloudWatch*
の名のついたものすべてにしてみた。

CloudWatch エージェント設定ファイルを作成

ウィザードで簡単に作成してみる

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

# 全部デフォルトで。
# 追加ログいる?って聞かれたところで2. noを選択

Do you want to specify any additional log files to monitor?
1. yes
2. no
default choice: [1]:
2
Saved config file to /opt/aws/amazon-cloudwatch-agent/bin/config.json successfully.
Current config as follows:

# 設定ファイルの中身が表示される

Please check the above content of the config.
The config file is also located at /opt/aws/amazon-cloudwatch-agent/bin/config.json.
Edit it manually if needed.
Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:

What parameter store name do you want to use to store your config? (Use 'AmazonCloudWatch-' prefix if you use our managed AWS policy)
default choice: [AmazonCloudWatch-linux]

Trying to fetch the default region based on ec2 metadata...
Which region do you want to store the config in the parameter store?
default choice: [ap-northeast-1]

Please provide credentials to upload the json config file to parameter store.
AWS Access Key:
[AMIで取得したアクセスキー]
AWS Secret Key:
[AMIで取得したシークレットキーを入力]
Successfully put config to parameter store AmazonCloudWatch-linux.
Program exits now.

IAM 認証情報とAWS リージョンの指定

$ sudo aws configure
Traceback (most recent call last):
  File "/usr/bin/aws", line 19, in <module>
    import awscli.clidriver
ImportError: No module named awscli.clidriver

# ↑ awscli.clidriver がないといわれる
# 念のためアップデート

$ sudo /usr/local/bin/pip install --upgrade pip
$ sudo /usr/local/bin/pip uninstall awscli
$ sudo /usr/local/bin/pip install awscli

# 再度実行
$ sudo aws configure
Traceback (most recent call last):
  File "/usr/bin/aws", line 19, in <module>
    import awscli.clidriver
ImportError: No module named awscli.clidriver

# まだawscli.clidriverがないといわれる、パッケージがあるかチェック
$ locate clidriver
/usr/local/lib/python2.6/site-packages/awscli/clidriver.py
/usr/local/lib/python2.6/site-packages/awscli/clidriver.pyc
/usr/local/lib/python2.6/site-packages/awscli/clidriver.pyo

# ある、対話モードでパスを確認
$ python
>>import sys
>>print sys.path
['', '/usr/local/lib/python26.zip', '/usr/local/lib/python2.6', '/usr/local/lib/python2.6/plat-linux4', 
'/usr/local/lib/python2.6/lib-tk', '/usr/local/lib/python2.6/lib-old', '/usr/local/lib/python2.6/lib-dynload', 
'/usr/local/lib/python2.6/site-packages', '/usr/local/lib/python2.6/site-packages/pip-9.0.1-py2.6.egg', 
'/usr/local/lib/python2.6/site-packages/setuptools-33.1.1-py2.6.egg']

# 見づらいけど「/usr/local/lib/python2.6/site-packages/」はあるなー
# 対話モードを[ctr +D]で終了

# 再度実行するとなぜかできた、パス認識してなかったのかも
aws configureaws 
AWS Access Key ID [None]: [AMIで取得したアクセスキー]
AWS Secret Access Key [None]: [AMIで取得したシークレットキーを入力]
Default region name [None]: ap-northeast-1 #東京リージョンを入力
Default output format [None]: 

#できたか確認
$ aws ec2 describe-instances
# 所有しているインスタンス情報が確認できればOK

cloudwatchエージェントを実行

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

# エラー

E! Error parsing /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml, 
open /usr/share/collectd/types.db: no such file or directory

# types.dbがないといわれる
# これは、「collectd」をインストールすることで解決

$ sudo vi /etc/yum.repos.d/epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=0 → ここを1に変更
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

#保存してインストール

$ sudo yum install collectd

# もう一度、cloudwatchエージェントを実行

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

Successfully fetched the config and saved 
in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp

止めるのはこう

$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop

OK!みたいな雰囲気だけどどうかな?

設定ファイル「config.json」を変更した場合のパラメータリストへの手動アップ方法

$ cd /opt/aws/amazon-cloudwatch-agent/bin/
$ aws ssm put-parameter --name "AmazonCloudWatch-linux" --type "String" --overwrite --value file://config.json
3
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
eonishispi
フリーランスでWebエンジニアしています。 インフラも勉強中。備忘録や転職時につかえたらなーと思ってます。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?