Amazon ECS Exec이 활성화되어 있는 Fargate 작업에 대한 SSM 에이전트 로그를 가져오려면 어떻게 해야 합니까?

3분 분량
0

Amazon Elastic Container Service(Amazon ECS) Exec이 활성화된 AWS Fargate 작업에 대한 AWS Systems Manager Agent(SSM Agent) 로그를 가져오고 싶습니다. 하지만 어떻게 해야 할지 모르겠습니다.

간략한 설명

Amazon ECS Exec을 사용하기 전에 ECS Exec을 사용하기 위한 사전 요구 사항을 참조하세요.

ECS Exec이 활성화된 Fargate 작업에 대한 SSM 에이전트 로그를 가져오려면 Amazon Elastic File System(Amazon EFS) 파일 시스템을 생성합니다. 그런 다음 Fargate 컨테이너에 Amazon EFS 파일 시스템을 마운트합니다. 마지막으로, Amazon Elastic Compute Cloud(Amazon EC2) 인스턴스에 동일한 파일 시스템을 마운트하여 SSM 에이전트 로그를 가져옵니다.

중요: Amazon EFS 파일 시스템, Amazon ECS 클러스터 및 Fargate 작업이 모두 동일한 Amazon Virtual Private Cloud(VPC)에 있어야 합니다.

참고: 다음 해결 방법은 ECS Exec이 활성화된 Fargate 작업에만 적용됩니다. 이 해결 단계는 디버깅에만 사용하세요. 독립 실행형 작업으로 시작하거나, Amazon ECS 서비스에서 desiredCount를 ‘1’로 유지하여 로그를 재정의하지 않도록 하세요. 컨테이너에서 stderr/stdout 이외의 로그를 확인해야 하는 시나리오에도 다음 해결 방법을 적용할 수 있습니다.

해결 방법

Amazon EFS 파일 시스템을 생성하고 작업 또는 서비스의 Fargate 컨테이너에 마운트합니다.

  1. Amazon EFS 파일 시스템을 생성합니다.
  2. Amazon EFS ID 및 보안 그룹 ID를 기록해 둡니다.
  3. Fargate 작업과 연결된 보안 그룹에서 포트 2049를 통한 인바운드 연결을 허용하도록 파일 시스템 보안 그룹 규칙을 편집합니다.
  4. 파일 시스템의 보안 그룹에 대한 포트 2049의 아웃바운드 연결을 허용하도록 Amazon ECS 서비스 보안 그룹을 업데이트합니다.
  5. Amazon ECS 콘솔을 열고 Amazon ECS 작업 정의로 이동합니다.
  6. Volumes(볼륨) 섹션에서 **Add volume(볼륨 추가)**을 선택합니다.
  7. **Name(이름)**에 볼륨 이름을 입력합니다.
  8. **Volume type(볼륨 유형)**에 ‘EFS’를 입력합니다.
  9. **File system ID(파일 시스템 ID)**에 파일 시스템의 ID를 입력합니다.
  10. Containers definition(컨테이너 정의) 섹션에서 STORAGE AND LOGGING(스토리지 및 로깅) 섹션으로 이동하여, 새로 생성한 볼륨을 소스 볼륨으로 선택합니다.
  11. **Container path(컨테이너 경로)**에서 /var/log/amazon을 선택합니다.
  12. 생성한 작업 정의를 사용하여 Fargate 서비스 또는 작업을 업데이트합니다.

Amazon EC2 인스턴스에 Amazon EFS 파일 시스템을 마운트하고 SSM 에이전트 로그를 가져옵니다.

1.    파일 시스템을 EC2 인스턴스에 마운트합니다.

2.    다음 명령을 실행하여 로그 데이터를 가져옵니다.

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-01b0bxxxxxxxx.efs.ap-southeast-1.amazonaws.com:/ /efs

출력 예:

# df -h
Filesystem                                          Size  Used Avail Use% Mounted on
fs-01b0bxxxxxxxx.efs.us-west-2.amazonaws.com:/      8.0E     0  8.0E   0% /efs

다음은 Fargate 컨테이너의 /var/log/amazon/ssm/amazon-ssm-agent.log 경로에 저장된 로그의 예입니다.

[root@ip-172-31-32-32 efs]# cd ssm/
[root@ip-172-31-32-32 ssm]# ls
amazon-ssm-agent.log  audits
[root@ip-172-31-32-32 ssm]# cat amazon-ssm-agent.log | tail -n 10
2022-10-20 11:50:34 INFO [ssm-agent-worker] [MessageService] [MessageHandler] ended idempotency deletion thread
2022-10-20 11:50:37 INFO [ssm-agent-worker] [MessageService] [MGSInteractor] send failed reply thread started
2022-10-20 11:50:37 INFO [ssm-agent-worker] [MessageService] [MGSInteractor] send failed reply thread done
2022-10-20 11:55:37 INFO [ssm-agent-worker] [MessageService] [MGSInteractor] send failed reply thread started
2022-10-20 11:55:37 INFO [ssm-agent-worker] [MessageService] [MGSInteractor] send failed reply thread done
2022-10-20 12:00:34 INFO [ssm-agent-worker] [MessageService] [MessageHandler] started idempotency deletion thread
2022-10-20 12:00:34 WARN [ssm-agent-worker] [MessageService] [MessageHandler] [Idempotency] encountered error open /var/lib/amazon/ssm/170b15cacf5846ed836bcd7903cbee48-2531612879/idempotency: no such file or directory while listing replies in /var/lib/amazon/ssm/170b15cacf5846ed836bcd7903cbee48-2531612879/idempotency
2022-10-20 12:00:34 INFO [ssm-agent-worker] [MessageService] [MessageHandler] ended idempotency deletion thread
2022-10-20 12:00:37 INFO [ssm-agent-worker] [MessageService] [MGSInteractor] send failed reply thread started
2022-10-20 12:00:37 INFO [ssm-agent-worker] [MessageService] [MGSInteractor] send failed reply thread done
[root@ip-172-31-32-32 ssm]#

AWS 공식
AWS 공식업데이트됨 일 년 전
댓글 없음

관련 콘텐츠