- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个单体,目前正在转移到 aws(使用 ecs/fargate),稍后将分解为微服务。它使用 amazon linux 1 镜像,配置了 apache、php 和我所有的生产网站数据。目前,它将日志发送到/etc/httpd/logs 和/var/www/vhosts/logs 中的几个文件。
据说我可以在 ecs 任务定义中用日志配置和卷做一些事情,但我还没有找到任何解释如何做的细节的东西。
最佳答案
如果是容器,我绝不会建议将日志写入文件,最好将日志容器写入标准输出和标准错误。
另一个有趣的事情,如果你搬到了 Fargate,你将如何处理日志文件?所以不要将日志写入文件,也不要像实例机一样对待容器。
AWS 日志驱动的美妙之处在于,它将日志推送到 Cloud watch 日志,并且从 Cloud watch 将这些推送到 ELK 也非常容易。
选择 AWS 日志驱动程序,设计您的入口点,使其将日志写入容器中的 stdout 和 stderr。通常,当您在前台运行进程时,这非常容易,它会自动将日志写入容器标准输出。
只需在您的任务定义中添加这一行并添加云观察角色。
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "awslogs-wordpress",
"awslogs-region": "us-west-2",
"awslogs-stream-prefix": "awslogs-example"
}
}
配置完成后你会看到日志
使用 awslogs 日志驱动程序
You can configure the containers in your tasks to send log information to CloudWatch Logs. If you are using the Fargate launch type for your tasks, this allows you to view the logs from your containers. If you are using the EC2 launch type, this enables you to view different logs from your containers in one convenient location, and it prevents your container logs from taking up disk space on your container instances. This topic helps you get started using the awslogs log driver in your task definitions.
注意
The type of information that is logged by the containers in your task depends mostly on their
ENTRYPOINT command
. By default, the logs that are captured show the command output that you would normally see in an interactive terminal if you ran the container locally, which are theSTDOUT
andSTDERR I/O streams
. The awslogs log driver simply passes these logs from Docker to CloudWatch Logs. For more information on how Docker logs are processed, including alternative ways to capture different file data or streams, see View logs for a container or service in the Docker documentation.
关于amazon-web-services - 如何将多个日志文件发送到 amazon cloudwatch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58543214/
我是一名优秀的程序员,十分优秀!