4.4. 管理日志

容器化服务日志文件存储在 /var/log/containers/<service&gt; 中,如 /var/log/containers/cinder。容器内运行的服务的日志文件存储在本地。可用的日志可能会因启用和禁用的服务而异。

以下示例强制 logrotate 任务在达到 10 MB 时创建新日志文件,并保留 14 天的日志文件。

parameter_defaults
  LogrotateRotate: '14'
  LogrotatePurgeAfterDays: '14'
  LogrotateMaxsize: '10M'

若要自定义日志轮转参数,可在环境模板中包括这些参数 _defaults,然后部署 overcloud。

openstack overcloud deploy \
--timeout 100 \
--templates /usr/share/openstack-tripleo-heat-templates \
... \
-e /home/stack/templates/rotate.yaml \
--log-file overcloud_deployment_90.log

验证:在任何 overcloud 节点上,确保 logrotate_crond 已更新:

[root@compute0 ~]# podman exec -it logrotate_crond cat /etc/logrotate-crond.conf
/var/log/containers/*/*log /var/log/containers/*/*/*log /var/log/containers/*/*err {
  daily
  rotate 14
  maxage 14
  # minsize 1 is required for GDPR compliance, all files in
  # /var/log/containers not managed with logrotate will be purged!
  minsize 1
  # Do not use size as it's not compatible with time-based rotation rules
  # required for GDPR compliance.
  maxsize 10M
  missingok
  notifempty

  copytruncate


  delaycompress


  compress


}

在以下示例中,nova-compute.log 文件已被轮转一次。

[root@compute0 ~]# ls -lah /var/log/containers/nova/
total 48K
drwxr-x---. 2 42436 42436  79 May 12 09:01 .
drwxr-x---. 7 root  root   82 Jan 21  2021 ..
-rw-r--r--. 1 42436 42436 12K May 12 14:00 nova-compute.log
-rw-r--r--. 1 42436 42436 33K May 12 09:01 nova-compute.log.1
-rw-r--r--. 1 42436 42436   0 Jan 21  2021 nova-manage.log

日志文件轮转过程发生在 logrotate_crond 容器中。/var/spool/cron/root 配置文件被读取,其配置被发送到进程。

验证:确保配置存在于任何 Controller 节点上:

[root@controller0 ~]# podman exec -it logrotate_crond /bin/sh
()[root@9410925fded9 /]$ cat /var/spool/cron/root
# HEADER: This file was autogenerated at 2021-01-21 16:47:27 +0000 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: logrotate-crond
PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh
0 * * * * sleep `expr ${RANDOM} \% 90`; /usr/sbin/logrotate -s /var/lib/logrotate/logrotate-crond.status /etc/logrotate-crond.conf 2>&1|logger -t logrotate-crond

/var/lib/config-data/puppet-generated/crond/etc/logrotate-crond.conf 文件绑定到 logrotate_crond 容器中的 /etc/logrotate-crond.conf

注意

由于历史原因,旧的配置文件会被保留,但不会使用它们。