apache - ECS 日志记录(awslogs 驱动程序)仅将 apache 服务器启动日志记录到 cloudwatch,没有 error.log 和没有 access.log

标签 apache docker logging amazon-ecs amazon-cloudwatch

我的问题是我的 ECS 日志(awslogs 驱动程序)没有按预期工作。在 Cloudwatch 中,我只看到服务器启动日志,而不是来自 apache 的有用日志( /var/log/apache2/error.log/var/log/apache2/access.log )

我有一个 docker 多容器设置,其中一个容器运行 apache 服务器,另一个容器运行 PHP-FPM。我在 cloudwatch 上的容器日志如下所示:

Apache 容器:

23:35:39 *** Running /etc/my_init.d/02_init.sh...
23:35:39 Starting Apache
23:35:39 * Starting Apache httpd web server apache2
23:35:39 /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
23:35:39 Setting ulimit failed. See README.Debian for more information.
23:35:40 *** Running /etc/rc.local...
23:35:40 *** Booting runit daemon...
23:35:40 *** Runit started as PID 225
23:35:40 Oct 25 22:35:40 apache-container syslog-ng[231]: syslog-ng starting up; version='3.5.6'
2019-10-26 00:17:01
Oct 25 23:17:01 apache-container CRON[947]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
...
07:35:16 tail: '/var/log/syslog' has been replaced; following new file
...

FPM-容器:
...
10:25:23 172.x.x.x - 27/Okt/2019:09:25:23 +0000 "GET /app.php" 200
10:25:25 172.x.x.x - 27/Okt/2019:09:25:24 +0000 "GET /app.php" 200
...

我检查了各种论坛和在线资源。据我了解,我只需要将我的日志符号链接(symbolic link)到 STDOUT/STDERR 甚至更好地链接到 /proc/self/fd/1 & /proc/self/fd/2像这样:
ln -sf /dev/stdout /var/log/apache2/access.log
ln -sf /dev/stderr /var/log/apache2/error.log

我试图链接我的 .Dockerfile 中的日志通过 RUN命令 & 也在运行时,但没有成功。在链接它们之前,我看到我的日志在日志文件中正确显示。我也尝试过 echo "test stderr logs" >> /dev/stderrecho "test stdout logs" >> /dev/stdout容器内部和外部,但 cloudwatch 日志中没有显示任何内容。当我尝试 docker logs MY_DOCKER_CONTAINER_ID我得到:Error response from daemon: configured logging driver does not support reading .

也许我在这里缺少一些基本知识。我看到 syslog在我的环境/基本镜像中(也许我需要合并 syslog 和 apache 日志?)并且 PHP-FPM-container 正在记录 200 个但仅记录到 app.php即使我想知道访问的 url 的确切路径。

最佳答案

您需要在 ECS 使用的 docker-compose 中指定使用 cloudwatch 日志记录驱动程序,如下所示:

version: '2'
services:
  myapp:
    build:
      context: .
    logging:
      driver: awslogs
      options:
        awslogs-group: "/my/log/group"
        awslogs-region: "us-west-2"
        awslogs-stream-prefix: some-prefix

这应该会导致/dev/stdout 和/dev/stderr 出现在 CloudWatch 中。您可以在 Docker page 上找到有关日志记录驱动程序选项的更多信息。 .

关于apache - ECS 日志记录(awslogs 驱动程序)仅将 apache 服务器启动日志记录到 cloudwatch,没有 error.log 和没有 access.log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58589153/

相关文章:

django - Apache 服务于 Django 和 Angular

linux - Docker 在没有运行任何容器的情况下使用了近 8GB

php - 尝试在 composer 中运行 php 内置服务器时获取 "php_network_getaddresses: getaddrinfo failed: Name or service not known"

python-3.x - 输出文件为空,在Docker容器中的ubuntu16.04中未进行任何编码(检查-ss/-t/-frames参数(如果使用))

c# - 将 Serilog 与 Microsoft.Extensions.Logging.ILogger 一起使用

php - pg_query() : Query failed: ERROR: operator does not exist: integer ~~ unknown\n

apache - Phusion 乘客未登录

php - mod_rewrite 对没有正斜杠的链接的影响?

java - 为某些记录器设置日志级别,但不为其他记录器设置日志级别

python - hadoop 流 : where are application logs?