절차
1. EC2 생성
2. IAM Role 생성
3. EC2에 IAM Role 연결
4. Cloudwatch-agent 설치
5. Cloudwatch-agent config.json 생성/설정
6. Cloudwatch-agent 시작
7. 로그그룹 생성
8. 로그스트림 생성
9. 로그 확인
10. SSM을 통한 Run command 수행
1. EC2 생성 후 IAM Role 연결
4. Cloudwatch-agent 설치
$ wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm$ sudo rpm -U ./amazon-cloudwatch-agent.rpm
5. Cloudwatch-agent config.json 생성/설정
amazon-cloudwatch-agent-config-wizard를 실행하여 기본설정을 시작한다.
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
$ sudo vi /opt/aws/amazon-cloudwatch-agent/bin/config.json
file_path, log_group_name, log_stream_name을 셋팅해준다.
{
"agent": {
"metrics_collection_interval": 10,
"run_as_user": "root",
"logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
},
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/home/ubuntu/logs/spring-boot-logging.log",
"log_group_name": "spring-boot-logging",
"log_stream_name": "{instance_id}"
}
]
}
}
},
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"collectd": {
"metrics_aggregation_interval": 60
},
"disk": {
"measurement": [
"used_percent"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"statsd": {
"metrics_aggregation_interval": 60,
"metrics_collection_interval": 10,
"service_address": ":8125"
}
}
}
}
6. Cloudwatch-agent 시작
Cloudwatch-agent 중지
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop
위에서 수정한 config.json을 사용해 설정 파일 업데이트 후 시작
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
에러발생 시 /usr/share/collectd/types.db 파일이 없다는 에러발생시 types.db 파일생성
$ mkdir /usr/share/collectd
$ cd /usr/share/collectd
$ touch types.db
/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log 로그 확인하여 정상기동되었음을 확인
2020/03/18 13:30:23 I! I! Detected the instance is EC2
2020/03/18 13:30:23 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json ...
/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json does not exist or cannot read. Skipping it.
2020/03/18 13:30:23 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json ...
Valid Json input schema.
I! Detecting runasuser...
No csm configuration found.
Configuration validation first phase succeeded
2020/03/18 13:30:23 I! Config has been translated into TOML /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml
2020/03/18 13:30:23 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json ...
2020/03/18 13:30:23 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json ...
2020/03/18 13:30:23 I! Detected runAsUser: root
2020/03/18 13:30:23 I! Change ownership to root:root
2020-03-18T13:30:23Z I! cloudwatch: get unique roll up list []
2020-03-18T13:30:23Z I! Starting AmazonCloudWatchAgent (version 1.237768.0)
2020-03-18T13:30:23Z I! Loaded outputs: cloudwatch cloudwatchlogs
2020-03-18T13:30:23Z I! Loaded inputs: disk mem socket_listener statsd tail
2020-03-18T13:30:23Z I! Tags enabled: host=ip-172-31-41-190
2020-03-18T13:30:23Z I! Agent Config: Interval:10s, Quiet:false, Hostname:"ip-172-31-41-190", Flush Interval:1s
2020-03-18T13:30:23Z I! Started the statsd service on :8125
2020-03-18T13:30:23Z I! cloudwatch: publish with ForceFlushInterval: 1m0s, Publish Jitter: 37s
2020-03-18T13:30:23Z I! Statsd listener listening on: [::]:8125
2020-03-18T13:30:24Z I! Reading from offset 9083 in /home/ubuntu/logs/spring-boot-logging.log
7. 로그그룹 생성
8. 로그스트림 생성
9. 로그 확인
10. SSM을 통한 Run command 수행
'클라우드 컴퓨팅 & NoSQL > Amazon Web Service' 카테고리의 다른 글
unhealthy host error 원인 분석 (0) | 2020.03.10 |
---|---|
[POC] Redis 연동을 위한 Jedis 사용법 (0) | 2020.03.08 |
Jumphost가 구성된 Main Server에 파일 업/다운로드 (0) | 2020.03.04 |
AWS ELB로 부터 Client IP 획득 (0) | 2020.03.03 |
[POC] Tunneling을 이용한 AWS Elastic Cache(redis) 로컬 테스트 (0) | 2020.03.03 |