처음에 설정할때 잘 설정했어야됬는데.. 이미 늦어버려서 이후에 설정하려고 함...
[공식 문서0] https://aws.amazon.com/ko/blogs/korea/attach-aws-iam-role-to-an-existing-ec2-instance/
cloudwatch에 넣을 꺼니까 아래 두개 넣어서, IAM 역할 생성
$ aws ec2 associate-iam-instance-profile --instance-id YourInstanceId --iam-instance-profile Name=YourNewRole-Instance-Profile
$ aws ec2 describe-iam-instance-profile-associations
$ wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
또는
$ curl -O https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
$ sudo rpm -U ./amazon-cloudwatch-agent.rpm
create group cwagent, result: 0
create user cwagent, result:0
create group aoc, result:0
create user aoc, result:0
$ cd /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/
$ vi config.json
ex) 메모리랑 디스크 확인 및 로그 접근
{
"agent": {
"run_as_user": "cwagent"
},
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/messages",
"log_group_name": "/var/log/messages",
"log_stream_name": "{instance_id}"
}
]
}
}
},"metrics": {
"namespace": "cwagent",
"metrics_collected": {
"mem": {
"measurement": [
"used_percent"
]
},
"disk": {
"measurement": [
"used_percent"
],
"resources": [
"*"
],
"ignore_file_system_types": [
"sysfs",
"devtmpfs",
"tmpfs"
],
"drop_device": true
}
},
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
}
}
}
$ sudo mkdir /usr/share/collectd
$ cd /usr/share/collectd
$ sudo touch types.db
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/config.json
$ sudo systemctl start amazon-cloudwatch-agent
만약 로그가 보이지 않는다면...?
클라우드 워치 로그 파일 : /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
여기서 확인
-> Permission Denied 인경우도 있음 (로그파일 접근시)
그럴때는 chmod로 권한을 주자!
참고: Wizard사용 -> 생성Cloudwatch agent 설정 파일 위치
/opt/aws/amazon-cloudwatch-agent/bin/config.json
참고 : 실제 Cloudwatch agent가 사용하는 설정 파일 위치
/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
cloudwatch에 토픽 추가해서, 이메일이나 톡방 넣기