Elastic Beanstalk에서 로깅 문제를 해결하려면 어떻게 해야 합니까?

2분 분량
0

로그 파일이 비어 있거나 로그 스트림이 갑자기 로그 메시지 스트리밍을 중단했습니다. 이 문제를 AWS Elastic Beanstalk에서 해결려고 합니다.

해결 방법

발생한 로깅 문제에 따라 다음 옵션 중 하나를 선택합니다.

빈 로그 파일 찾기

기본적으로 Elastic Beanstalk는 사용자 환경의 Amazon Elastic Compute Cloud(Amazon EC2) 인스턴스에 모든 로그를 보관합니다. Elastic Beanstalk는 정기적으로 로그를 로테이션시켜 파일 크기를 관리하고 디스크 공간을 절약합니다. Elastic Beanstalk는 로그를 Amazon Simple Storage Service(S3)로 내보냅니다. 자세한 내용을 보려면 Linux의 로그 로테이션 설정을 참조하세요. 최근에 로테이션된 로그 메시지에 액세스하려면 /var/log/rotated를 선택합니다.

로그 파일 및 로그 스트림이 새 로그 메시지 출력을 중단한 이유를 확인합니다.

Elastic Beanstalk EC2 인스턴스에서 로그 파일을 지속적으로 스트리밍하려면 Amazon CloudWatch 로그를 사용하세요.

EC2 인스턴스에서 첫 번째 로그 로테이션이 발생한 후 로그 스트리밍이 작동하지 않는 경우, 애플리케이션이 고유한 라인을 로깅하지 않는 것일 수 있습니다. 애플리케이션 로그는 다음 예와 같을 수 있습니다.

Hello my application!- at time 1:00 PM
Hello my application!
- at time 2:00 PM
...

위 예제에서는 모든 줄이 고유하지는 않습니다. 고유 항목은 두 줄에 걸쳐 있습니다. 이 로그 파일을 고유하게 식별하려면 최소 두 줄이 필요합니다.

참고: 로그 로테이션이 발생하는 시기를 감지하기 위해 CloudWatch Logs 에이전트는 로그 파일을 식별하고 파일에 포함된 고유한 줄 수를 사용합니다.

로그 스트리밍을 다시 작동시키려면 다음 해결 방법 중 하나를 시도하세요.

각 줄의 시작 부분에 타임스탬프와 같은 고유한 식별자를 포함하도록 애플리케이션 로그 형식을 편집합니다.

-또는-

파일을 고유하게 식별할 수 있는 충분한 줄이 포함될 때까지 file_fingerprint_lines 값을 편집하여 파일의 줄 수를 계산하세요.

참고: 이 값을 편집하려면 CloudWatch Logs 에이전트 구성을 사용자 지정해야 합니다. Elastic Beanstalk와 CloudWatch Logs의 통합은 애플리케이션에서 생성하는 사용자 지정 로그 파일의 스트리밍을 직접 지원하지 않습니다. 사용자 지정 로그를 스트리밍하려면 구성 파일을 사용하여 CloudWatch Logs 에이전트를 설치하고 푸시할 파일을 구성합니다.

예를 들어, 다음 .ebextension은 Node.js 애플리케이션 로그 파일에 대해 file_fingerprint_lines를 사용자 지정합니다:

files:  "/etc/awslogs/config/beanstalklogs.conf":
    mode: "000644"
    user: root
    group: root
    content: |
      [/var/log/nodejs/nodejs.log]
      log_group_name=/aws/elasticbeanstalk/streamlogs/var/log/nodejs/nodejs.log
      log_stream_name={instance_id}
      file=/var/log/nodejs/nodejs.log*
      file_fingerprint_lines=2-5

       [/var/log/nginx/error.log]
      log_group_name=/aws/elasticbeanstalk/streamlogs/var/log/nginx/error.log
      log_stream_name={instance_id}
      file=/var/log/nginx/error.log*

       [/var/log/nginx/access.log]
      log_group_name=/aws/elasticbeanstalk/streamlogs/var/log/nginx/access.log
      log_stream_name={instance_id}
      file=/var/log/nginx/access.log*

       [/var/log/httpd/error.log]
      log_group_name=/aws/elasticbeanstalk/streamlogs/var/log/httpd/error.log
      log_stream_name={instance_id}
      file=/var/log/httpd/error.log*

       [/var/log/httpd/access.log]
      log_group_name=/aws/elasticbeanstalk/streamlogs/var/log/httpd/access.log
      log_stream_name={instance_id}
      file=/var/log/httpd/access.log*

       [/var/log/eb-activity.log]
      log_group_name=/aws/elasticbeanstalk/streamlogs/var/log/eb-activity.log
      log_stream_name={instance_id}
      file=/var/log/eb-activity.log*
 commands:
  01_remove_eb_stream_config:
    command: 'rm -fr /etc/awslogs/config/beanstalklogs.conf.bak'
  02_restart_log_agent:
    command: 'service awslogs restart'

로그 스트림 생성 실패 문제 해결

로그 스트리밍을 켜도 로그 스트림이 여전히 표시되지 않는 경우 CloudWatch Logs 통합 문제 해결을 참조하세요.

관련 정보

Amazon CloudWatch Logs로 Elastic Beanstalk 사용

사용자 지정 로그 파일 스트리밍

GitHub 웹사이트의 logs-streamtocloudwatch-linux.config

AWS 공식
AWS 공식업데이트됨 8달 전