카테고리 없음
[Public Cloud] AWS 기본 정리 3 (로그 확인)
신샤인
2022. 11. 4. 19:46
반응형
노션에 작성했는 내용 정리
S3에 로그를 저장하여 Cloudwatch에서 확인
httpd 로그
- /var/log/httpd에서 access.log 확인 가능
- /var/log/httpd 에 있는 내부 로그들을 Archive
s3 생성
- 로그 저장용 버킷 생성
yum -y install awscli
#IAM 에 S3 권한을 부여 후 User 생성 후 Access Key 복사
aws configure
aws s3 ls
aws s3 cp access.log.tar.gz s3://web-logs/
IAM role 생성
- log admin role 생성
- s3fullAccess / cloudwatchlogsfullAccess Policy 지정
- WEB EC2 인스턴스 IAM role 변경 하여 생성한 role 설정
- 웹서버 설정
curl <https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py>
python awslogs-agent-setup.py --region us-east-2
설정값 입력 후
service awslogs status
cloudwatch에서 로그 확인
- log groups → 위 작업에서 설정한 log group 명 접속하여 로그 확인
- 로그 경로 추가 시 /var/awslogs/etc/awslogs.conf에서 설정 변경
- Log streams 확인 시 추가된 것을 알 수 있음
- Metric filters → Create metric filter → 생성 하여 Alerm 설정 가능
- LB 생성 후 → 하단 Attribute → Configure Access log → S3 버킷 설정
- S3 → edit bucket policy → Policy 입력
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::elb-account-id:root"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::bucket-name/prefix/AWSLogs/your-aws-account-id/*"
},
{
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::bucket-name/prefix/AWSLogs/your-aws-account-id/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
},
{
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::bucket-name"
}
]
}
반응형