日志不适用于 Elastic Beanstalk Tomcat 环境 [英] Logs not working on Elastic Beanstalk Tomcat environment

查看:24
本文介绍了日志不适用于 Elastic Beanstalk Tomcat 环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在使用 Elastic Beanstalk 在我们公司的 Tomcat 上运行我们的 Java (8) 应用程序,没有任何问题.现在我们决定继续使用 Java 11.我们使用 CloudFormation 设置我们的环境,就像我们之前为 Java 8 应用程序所做的那样,但现在我们正在使用这个解决方案堆栈:'64bit Amazon Linux 2 v4.1.1 running Tomcat 8.5 Corretto 11'(也试过 v4.1.2).一切正常,但看起来请求日志功能在弹性 beantalk 中不再起作用(最后 100 行和完整日志).我还向应用服务器添加了一个密钥对,以检查位于/var/log/tomcat/的 ec2 服务器上的日志,但是我们找不到 catalina.out 文件(只有日期为 catalina.2020-10 的 catalina 文件-14.log).这些文件只包含我们使用的库的日志,但不包含我们发送到标准系统输出的日志.我们有时合作的另一家公司在此解决方案堆栈上遇到了同样的问题.

We've been using Elastic Beanstalk to run our Java (8) applications on Tomcat in our company without any issues. Now we have decided to move on to Java 11. We set up our environments with CloudFormation as we did before for the Java 8 applications but now we are using this solution stack: '64bit Amazon Linux 2 v4.1.1 running Tomcat 8.5 Corretto 11' (also tried v4.1.2). Everything works fine but it looks like the request logs feature isn't working anymore in elastic beanstalk (Last 100 lines and full logs). I also added a keypair to the application server to check the logs on the ec2 server at /var/log/tomcat/ but we can't find the catalina.out file (only catalina files with a date like: catalina.2020-10-14.log). Those files contains only logs of a library we used but not the logs we send to the Standard system output. Another company we sometimes work with experiences the same issue on this solution stack.

有没有人在此解决方案堆栈上遇到过同样的问题并找到了解决方法?

Has anyone experienced the same issue on this solution stack and found a fix?

这是我们的 CloudFormation 配置 (YAML):

This is our CloudFormation configuration (YAML):

Application:
Type: AWS::ElasticBeanstalk::Application
Properties:
Description: Application backend
ApplicationVersion:
Type: AWS::ElasticBeanstalk::ApplicationVersion
Properties:
ApplicationName:
Ref: Application
Description: !Ref AppVersion
SourceBundle:
S3Bucket: !Ref BeanstalkSourceS3
S3Key: !Ref BuildFileName
AppEC2ServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- elasticbeanstalk.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth"
- "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkService"
AppEnvironment:
Type: AWS::ElasticBeanstalk::Environment
Properties:
ApplicationName:
Ref: Application
OptionSettings:
- Namespace: aws:autoscaling:launchconfiguration
OptionName: InstanceType
Value: !Ref EC2InstanceSize
- Namespace: aws:elasticbeanstalk:environment
OptionName: EnvironmentType
Value: SingleInstance
- Namespace: aws:autoscaling:launchconfiguration
OptionName: IamInstanceProfile
Value: !Ref AppInstanceProfile
- Namespace: aws:autoscaling:launchconfiguration
OptionName: EC2KeyName
Value: CompanyTestKey
- Namespace: aws:ec2:vpc
OptionName: VPCId
Value: !Ref Vpc
- Namespace: aws:ec2:vpc
OptionName: Subnets
Value: !Join [",",https://forums.aws.amazon.com/
- Namespace: aws:ec2:vpc
OptionName: AssociatePublicIpAddress
Value: true
- Namespace: aws:elasticbeanstalk:environment
OptionName: ServiceRole
Value: !Ref AppEC2ServiceRole
- Namespace: aws:elasticbeanstalk:cloudwatch:logs
OptionName: StreamLogs
Value: true
- Namespace: aws:elasticbeanstalk:cloudwatch:logs
OptionName: RetentionInDays
Value: 14
SolutionStackName: 64bit Amazon Linux 2 v4.1.1 running Tomcat 8.5 Corretto 11
VersionLabel:
Ref: ApplicationVersion
Tags:
- Key: group
Value: !Ref ResourceGroupTagValue

推荐答案

我已经在新的Medium blog 这一切如何适用于 Tomcat,我遇到了类似的问题,尤其是由于 S3 导致的零长度文件日志轮换.

I've detailed in a new Medium blog how this all works for Tomcat, I hit similar issues, particularly zero-length files due to S3 Log Rotation.

以下是您可能可以使用的摘录,文章解释了如何确定要流式传输的正确文件夹/文件.

Below is an excerpt that you might be able to use, the article explains how to determine the right folder/file(s) to stream.

这里我正在流式传输三个不同的文件(它会自动处理您提到的日期),请查看您需要流式传输的每个文件的 logs.conf内容"部分下的内容.

Here I'm streaming three different files (it deals with the dates you mention automatically), review what's under the logs.conf 'content' section for each file that you need to stream.

不要忘记同时设置您的策略和角色,使 Elastic Beanstalk EC2 实例能够与 CloudWatch 通信.

Don't forget to also setup your policy and role that enables the Elastic Beanstalk EC2 instance to communicate with CloudWatch.

packages:
  yum:
    awslogs: []

option_settings:
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: StreamLogs
    value: true
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: DeleteOnTerminate
    value: false
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: RetentionInDays
    value: 90

files:
  "/etc/awslogs/awscli.conf" :
    mode: "000600"
    owner: root
    group: root
    content: |
      [plugins]
      cwlogs = cwlogs
      [default]
      region = `{"Ref":"AWS::Region"}`

  "/etc/awslogs/config/logs.conf" :
    mode: "000600"
    owner: root
    group: root
    content: |
      [/var/log/tomcat/localhost.log]
      log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/tomcat/localhost.log"]]}`
      log_stream_name = {instance_id}
      file = /var/log/tomcat/localhost.*

      [/var/log/tomcat/catalina.log]
      log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/tomcat/catalina.log"]]}`
      log_stream_name = {instance_id}
      file = /var/log/tomcat/catalina.*

      [/var/log/tomcat/localhost_access_log.txt]
      log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/tomcat/access_log"]]}`
      log_stream_name = {instance_id}
      file = /var/log/tomcat/access_log.*

commands:
  "01":
    command: systemctl enable awslogsd.service
  "02":
    command: systemctl restart awslogsd

这篇关于日志不适用于 Elastic Beanstalk Tomcat 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆