当前位置: 首页 > news >正文

aws beanstalk 实例日志和环境状态日志的轮换和流式传输配置

参考资料

  • https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/AWSHowTo.cloudwatchlogs.html

  • 查看您的 Elastic Beanstalk 环境中的 Amazon EC2 实例的日志

  • https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/environments-cfg-logging.html

eb相关日志的说明

日志源

beanstalk环境中的相关日志主要包括以下几个

  • 实例日志

    • Web 服务器

    • 应用程序服务器

    • beanstalk平台脚本和

    • cloudformation创建日志

  • 环境状态日志

日志分类

按照日志的类型又可以分为

  • 结尾日志,beanstalk的操作日志和webserver日志,将条目保存为文本文件
  • 捆绑日志(windows平台不支持),yum 和 cron日志,cloudformation日志,打包为zip包

日志上传方式

日志的上传也有两种方式

  • 将轮换的实例日志上传到环境的s3存储桶

  • 将实例日志流式传输到CloudWatch Logs,相关配置项如下(包括实例日志和环境状态日志)

    aws:elasticbeanstalk:cloudwatch:logs:
      DeleteOnTerminate: 'false'
      RetentionInDays: '7'
      StreamLogs: 'false'
    aws:elasticbeanstalk:cloudwatch:logs:health:
      DeleteOnTerminate: 'false'
      HealthStreamingEnabled: 'false'
      RetentionInDays: '7'
    

日志配置项

日志配置主要涉及到的命名空间如下

  • aws:elasticbeanstalk:hostmanager - 配置为将轮换日志上传到 Amazon S3
  • aws:elasticbeanstalk:cloudwatch:logs - 配置为将实例日志流式传输到 CloudWatch
  • aws:elasticbeanstalk:cloudwatch:logs:health - 配置为将环境运行状况流式传输到 CloudWatch

实例日志的配置

可以直接在命令行快速开启

eb logs --log-group xxxxx
eb logs --cloudwatch-logs enable --cloudwatch-log-source instance
eb logs --cloudwatch-logs enable --cloudwatch-log-source environment-health
eb logs --stream

流日志

在应用根目录增加以下配置,aws:elasticbeanstalk:cloudwatch:logs

$ cat .ebextensions/cloudwatch.config
option_settings:
  aws:elasticbeanstalk:cloudwatch:logs:
    DeleteOnTerminate: 'false'
    RetentionInDays: '1'
    StreamLogs: 'true'

配置完成后控制台可以看到日志组名称

在这里插入图片描述

默认收集的日志如下

在这里插入图片描述

s3日志

在应用根目录增加以下配置,aws:elasticbeanstalk:hostmanager

$ cat .ebextensions/hostmanagerlog.config
option_settings:
  aws:elasticbeanstalk:hostmanager:
    LogPublicationControl: true

上传的日志清单为

https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/using-features.logging.html

查看应用对应的s3桶,eb实例每小时上传一次轮换日志

  • 如果应用程序不是在环境平台默认配置的位置生成日志,可以使用配置文件 (.ebextensions) 扩展默认配置。

  • 也可以将应用程序的日志文件添加到结尾日志、捆绑日志或日志轮换中

s3日志的存储位置为,名为elasticbeanstalk-region-account-id的存储桶,路径为resources/environments/logs/logtype/environment-id/instance-id``

日志名称规范为

  • 结尾日志s3://elasticbeanstalk-us-west-2-123456789012/resources/environments/logs/tail/e-mpcwnwheky/i-0a1fd158
  • 捆绑日志s3://elasticbeanstalk-us-west-2-123456789012/resources/environments/logs/bundle/e-mpcwnwheky/i-0a1fd158
  • 轮换日志s3://elasticbeanstalk-us-west-2-123456789012/resources/environments/logs/publish/e-mpcwnwheky/i-0a1fd158

结尾日志和捆绑日志创建15分钟后删除(eb使用用户权限删除s3)

对于轮换日志,具体配置在/etc/logrotate.elasticbeanstalk.hourly/

$ ll /etc/logrotate.elasticbeanstalk.hourly
total 28
-rw-r--r-- 1 root root 157 Apr  1 11:11 logrotate.elasticbeanstalk.eb-engine.conf
-rw-r--r-- 1 root root 156 Apr  1 11:11 logrotate.elasticbeanstalk.eb-hooks.conf
-rw-r--r-- 1 root root 171 Apr  1 11:45 logrotate.elasticbeanstalk.healthd.conf
-rw-r--r-- 1 root root 157 Apr  1 11:45 logrotate.elasticbeanstalk.nginx.conf
-rw-r--r-- 1 root root 156 Apr  1 11:11 logrotate.elasticbeanstalk.web-stderr.conf
-rw-r--r-- 1 root root 156 Apr  1 11:11 logrotate.elasticbeanstalk.web-stdout.conf
-rw-r--r-- 1 root root 162 Apr  1 11:45 logrotate.elasticbeanstalk.xray.conf

查看eb-engine日志配置

$ cat logrotate.elasticbeanstalk.eb-engine.conf
/var/log/eb-engine.log {
 su root root
 size 10M
 rotate 5
 missingok
 compress
 notifempty
 copytruncate
 dateext
 dateformat %s
 olddir /var/log/rotated
}

这些配置文件由定时任务配置进行调用

$ ls /etc/cron.hourly/
0anacron                                             cron.logrotate.elasticbeanstalk.eb-hooks.conf  cron.logrotate.elasticbeanstalk.web-stderr.conf
cron.logcleanup.elasticbeanstalk.healthd-proxy.conf  cron.logrotate.elasticbeanstalk.healthd.conf   cron.logrotate.elasticbeanstalk.web-stdout.conf
cron.logrotate.elasticbeanstalk.eb-engine.conf       cron.logrotate.elasticbeanstalk.nginx.conf     cron.logrotate.elasticbeanstalk.xray.conf

查看定时任务配置,可以看到关键程序为logrotate

$ cat /etc/cron.hourly/cron.logrotate.elasticbeanstalk.eb-engine.conf
#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate -f /etc/logrotate.elasticbeanstalk.hourly/logrotate.elasticbeanstalk.eb-engine.conf

可以对默认的日志位置进行扩展,具体的配置路径

  • 结尾日志/opt/elasticbeanstalk/tasks/taillogs.d/
  • 捆绑日志/opt/elasticbeanstalk/tasks/bundlelogs.d/
  • 轮换日志/opt/elasticbeanstalk/tasks/publishlogs.d/

扩展其实就是在.ebextension路径下在配置文件中设定日志配置的文件和内容

files:
  "/opt/elasticbeanstalk/tasks/taillogs.d/cwl-system.conf":
    content: |
      /var/log/awslogs-agent-setup.log
      /var/log/awslogs.log
      /var/log/eb-cwlogs.log
    mode : "000644"
  "/opt/elasticbeanstalk/tasks/bundlelogs.d/cwl-system.conf":
    content: |
      /var/log/awslogs-agent-setup.log
      /var/log/awslogs.log
      /var/log/eb-cwlogs.log
    mode : "000644"
  "/opt/elasticbeanstalk/tasks/systemtaillogs.d/cwl-system.conf":
    content: |
      /var/log/awslogs-agent-setup.log
      /var/log/awslogs.log
      /var/log/eb-cwlogs.log
    mode : "000644"
  "/opt/elasticbeanstalk/tasks/publishlogs.d/cwl-system.conf":
    content: |
      /var/log/awslogs-agent-setup.log    ## this isn't rotated
      /var/log/awslogs.log*.gz
    mode : "000644"

环境状态日志的配置

在应用根目录增加以下配置

$ cat .ebextensions/cloudwatch.config
option_settings:
  aws:elasticbeanstalk:healthreporting:system:
    SystemType: enhanced
  aws:elasticbeanstalk:cloudwatch:logs:health:
    DeleteOnTerminate: 'false'
    HealthStreamingEnabled: 'true'
    RetentionInDays: '1'

配置完成后控制台可以看到日志组名称

在这里插入图片描述

日志配置相关的仓库

  • https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/instance-configuration/awslogs-change-frequency.config
  • https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/instance-configuration/logs-streamtocloudwatch-linux-alami.config
  • https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/instance-configuration/logs-streamtocloudwatch-linux.config
  • https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/instance-configuration/logs-uploadonterminate-linux.config

相关文章:

  • GameFramework框架详解之 Scene场景
  • ChatGPT 使用 拓展资料:如何处理OpenAI 对 API 的调用限速
  • SoapUI基础使用教程
  • 【MySQL】表的完整性约束——非外键约束
  • vue打包上线利用插件去除 console
  • Spring bean的创建过程
  • [架构之路-148]-《软考-系统分析师》- 7-企业信息化战略与实施-5-企业信息系统、电子政务
  • 机器学习笔记之策略
  • 面向对象练习题(6)
  • 基于springboot实现时间管理系统演示【附项目源码+论文说明】
  • 【致敬嵌入式攻城狮第2期活动预热征文】——蜂鸣器(内化)
  • 第8章_索引的创建与设计原则
  • 了解PL/SQL看这一篇够够了~
  • 为什么我们认为GPT是一个技术爆炸
  • 低代码打翻前端的饭碗?探秘两者藕断丝连的关系
  • 5、React组件事件详解
  • ES6之路之模块详解
  • javascript面向对象之创建对象
  • Linux gpio口使用方法
  • Netty 框架总结「ChannelHandler 及 EventLoop」
  • Node.js 新计划:使用 V8 snapshot 将启动速度提升 8 倍
  • 安装python包到指定虚拟环境
  • 程序员最讨厌的9句话,你可有补充?
  • 构建二叉树进行数值数组的去重及优化
  • 如何胜任知名企业的商业数据分析师?
  • 深度学习在携程攻略社区的应用
  • [Shell 脚本] 备份网站文件至OSS服务(纯shell脚本无sdk) ...
  • # .NET Framework中使用命名管道进行进程间通信
  • #include到底该写在哪
  • (3)(3.2) MAVLink2数据包签名(安全)
  • (7)STL算法之交换赋值
  • (Bean工厂的后处理器入门)学习Spring的第七天
  • (PyTorch)TCN和RNN/LSTM/GRU结合实现时间序列预测
  • (附源码)python房屋租赁管理系统 毕业设计 745613
  • (附源码)springboot优课在线教学系统 毕业设计 081251
  • .net core 6 集成和使用 mongodb
  • .net 使用ajax控件后如何调用前端脚本
  • .NET(C#) Internals: as a developer, .net framework in my eyes
  • .Net6支持的操作系统版本(.net8已来,你还在用.netframework4.5吗)
  • .net分布式压力测试工具(Beetle.DT)
  • @ConditionalOnProperty注解使用说明
  • @requestBody写与不写的情况
  • [ MSF使用实例 ] 利用永恒之蓝(MS17-010)漏洞导致windows靶机蓝屏并获取靶机权限
  • []AT 指令 收发短信和GPRS上网 SIM508/548
  • [12] 使用 CUDA 进行图像处理
  • [AIGC] 深入浅出 Python中的`enumerate`函数
  • [bzoj1006]: [HNOI2008]神奇的国度(最大势算法)
  • [C++]使用yolov10的onnx模型结合onnxruntime和bytetrack实现目标追踪
  • [CareerCup] 17.8 Contiguous Sequence with Largest Sum 连续子序列之和最大
  • [Codeforces1137D]Cooperative Game
  • [CTO札记]盛大文学公司名称对联
  • [hdu 3065] 病毒侵袭持续中 [AC自动机] [病毒特征码匹配]
  • [HTML]HTML5实现可编辑表格
  • [IOI2018] werewolf 狼人
  • [ORM]register db Ping `default`, Error 1130: Host '' is not allow connect to this MySQL server