본문으로 바로가기
반응형

RHOSP13 (Queens) 버전에서, logrotate 컨테이너를 설치해서 모든 OpenStack log를 관리하는데, OpenStack Log 가 설정한 주 단위 4주치를 저장하지 않는 이슈가 있습니다.

 

관련 에러는 container-tmpwatch의 잘못된 계산으로 인해 OpenStack의 모든 로그가 일찍 지워지는 현상입니다.

https://access.redhat.com/solutions/4394231

 

1.  Overcloud Compute 노드 logrotate 배포 및 적용 내용

logrotate 설정정보

[root@rhosp-dpdk-comp-1 ~]# cat /var/lib/config-data/puppet-generated/crond/etc/logrotate-crond.conf
/var/log/containers/*/*log /var/log/containers/*/*/*log /var/log/containers/*/*err {
  weekly
  rotate 4
  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

}

 

 

2. 해결방법

배포가 완료된 overcloud 노드에 /etc/cron.daily/containers-tmpwatch에 15를 15d로 변경해주면 됩니다.

## Deploy시 적용되는 값
#!/bin/sh
tmpwatch --nodirs \
-X "/var/log/containers/*/*log" \
-X "/var/log/containers/*/*/*log" \
-X "/var/log/containers/*/*err" \
15 \
/var/log/containers/ 2>&1 | logger -t container-tmpwatch


## 수동으로 아래와 같이 변경한 후 저장
#!/bin/sh
tmpwatch --nodirs \
-X "/var/log/containers/*/*log" \
-X "/var/log/containers/*/*/*log" \
-X "/var/log/containers/*/*err" \
15d \
/var/log/containers/ 2>&1 | logger -t container-tmpwatch

 

 

2.1 logrotate 주기 변경 (Option)

기본적으로 RHOSP13을 설치하면 daily형태로 로그를 보관하는데, 주 단위로 변경하고자 할 경우 아래와 같이 설정을 변경한 후 logrotate_crond 컨테이너를 재기동해줍니다.

[root@rhosp-comp-1 etc]# cat /var/lib/config-data/puppet-generated/crond/etc/logrotate-crond.conf

/var/log/containers/*/*log /var/log/containers/*/*/*log /var/log/containers/*/*err {
  daily
  rotate 30
  maxage 30
  

다음과 같이 변경

  weekly
  rotate 4
  
  
[root@rhosp-comp-1 etc]# docker restart logrotate_crond
logrotate_crond

 

 

2.2 logrotate 주 단위 변경방법 (Option)

오픈스택 배포시에 아예 주단위로 로그를 설정하고 싶을 경우 아래와 같이 파일을 생성한 후, deploy.sh에 추가하여 배포하면 됩니다.

1. logrotate 구성
[stack@rhosp-tb0-director etc]$cat logrotate.yaml
parameter_defaults:
  LogrotateRotationInterval: 'weekly'
  LogrotateRotate: '4

2. deploy.sh 추가
[stack@rhosp-tb0-director etc]$cat ~/deploy.sh-http
#!/bin/bash

source /home/stack/stackrc

#exit

LANG=C openstack overcloud deploy --templates  \
-n /home/stack/templates/leaf-spine-composable/composable-network.yaml \
-r /home/stack/templates/leaf-spine-composable/composable-roles.yaml \
-e /home/stack/templates/etc/server-blacklist.yaml \
< 중략 >
-e /usr/share/openstack-tripleo-heat-templates/environments/docker-ha.yaml \
-e /usr/share/openstack-tripleo-heat-templates/environments/cinder-backup.yaml \
-e /home/stack/templates/etc/nova-filter.yaml \
-e /home/stack/templates/etc/logrotate.yaml \
--ntp-server 60.30.157.4 \
--libvirt-type kvm \
--log-file=overcloud_deploy.log \
--timeout 60 \


3. 배포 및 적용 확인
[root@rhosp-dpdk-comp-1 ~]# cat /var/lib/config-data/puppet-generated/crond/etc/logrotate-crond.conf
/var/log/containers/*/*log /var/log/containers/*/*/*log /var/log/containers/*/*err {
  weekly
  rotate 4

 

 

3. workaround 방법 (RedHat 권고 사항 아님)

RedHat에서 권고하지 않는 방법이긴 하지만, 아래와 같이 기본 소스를 수정해서 overcloud 배포할 때 자동으로 적용될 수 있게 할 수 있습니다. (RedHat에서는 수동으로 변경권고)

## Director 소스 변경 경로
/usr/share/openstack-tripleo-heat-templates/docker/services/logrotate-crond.yaml


변경 전 : 
              tmpwatch --nodirs \
                -X "/var/log/containers/*/*log" \
                -X "/var/log/containers/*/*/*log" \
                -X "/var/log/containers/*/*err" \
                {{ LogrotatePurgeAfterDays|int +1 }} \
                /var/log/containers/ 2>&1 | logger -t container-tmpwatch

변경 후 : 
              tmpwatch --nodirs \
                -X "/var/log/containers/*/*log" \
                -X "/var/log/containers/*/*/*log" \
                -X "/var/log/containers/*/*err" \
                {{ LogrotatePurgeAfterDays|int +1 }}d \
                /var/log/containers/ 2>&1 | logger -t container-tmpwatch

 

 

4. 테스트 결과

위 내용 적용 후 1개 파일에서 1~2일치의 Log만 가지고 었던 이슈가 아래와 같이 4주치 파일과 4주치의 내용을 정상적으로 관리 및 유지할 수 있습니다. 

[root@rhosp-dpdk-comp-1 nova]# ls -alh
합계 6.7M
drwxr-xr-x. 2 42436 42436  140  7월  4 00:00 .
drwxr-xr-x. 5 root  root    48  4월  6 10:07 ..
-rw-r--r--. 1 42436 42436 1.1M  7월  5 09:14 nova-compute.log
-rw-r--r--. 1 42436 42436 5.4M  7월  4 00:00 nova-compute.log.1
-rw-r--r--. 1 42436 42436 112K  6월 27 00:00 nova-compute.log.2.gz
-rw-r--r--. 1 42436 42436 106K  6월 20 00:01 nova-compute.log.3.gz
-rw-r--r--. 1 42436 42436    0  4월  6 11:15 privsep-helper.lo

 

 

728x90