不存在这样的开箱即用的选项,可以从基于集群的所有服务中获取日志,就像每个容器在自己的空间(EC2 实例)中运行一样。
因此,您可以尝试类似的选项,但在此之前,您需要了解AWS ECS的日志记录机制。
日志驱动程序
用于容器的日志驱动程序。列出的有效值
此参数是 Amazon ECS 容器代理可以使用的日志驱动程序
默认情况下与.
对于使用 Fargate 启动类型的任务,支持的日志驱动程序是awslogs, splunk, and awsfirelens.
对于使用 EC2 启动类型的任务,支持的日志驱动程序是awslogs, fluentd, gelf, json-file, journald, logentries, syslog, splunk, and awsfirelens
.
因此,如果您在同一个 ec2 实例上运行多个容器,那么 syslog 对您来说很有意义。
系统日志记录驱动程序
The syslog logging driver routes logs to a syslog server. The syslog
protocol uses a raw string as the log message and supports a limited
set of metadata. The syslog message must be formatted in a specific
way to be valid. From a valid message, the receiver can extract the
following information:
但最好的方法是针对每个容器使用一个日志组。作为syslog在 Fargate 的情况下不起作用,因此最好为每个容器使用日志组。