Jump to content

Recommended Posts

Posted

Tenho uma máquina CentOS 7.4 com o logrotate 3.8.6 instalado. Criei um ficheiro logrotate em /etc/logrotate.d/ para rodar logs de um Tomcat (e.g., catalina.out) que está instalado na mesma máquina em /opt, com a seguinte configuração:

/opt/test/apache-tomcat-8.5.15-client/logs/catalina.out {
copytruncate
daily
rotate 30 
olddir /opt/test/apache-tomcat-8.5.15-client/logs/backup
compress
missingok
maxsize 50M
dateext
dateformat .%Y-%m-%d
}

Quero que o log seja rodado diariamente ou se o seu tamanho atingir os 50MB. Quando tal acontecer, os logs são comprimidos e copiados para uma pasta de backup e ficam lá durante 30 dias, findos os quais são apagados.

Eu já corri o logrotate manualmente em modo de debug com o seguinte comando e não obtive erros (tendo sido criados os ficheiros de log zipados, tal como expectável):

/usr/sbin/logrotate -d /etc/logrotate.d/tomcat 2> /tmp/logrotate.debug

No ficheiro /var/lib/logrotate/logrotate.status não há sinal de problemas, é indicado que os logs foram rodados mas de facto não foram:

"/var/log/yum.log" 2017-11-27-19:0:0
"/opt/test/apache-tomcat-8.5.15-client/logs/catalina.out" 2017-12-15-3:41:1
"/var/log/boot.log" 2017-12-15-3:41:1
"/var/log/up2date" 2017-11-27-19:0:0

Estou a usar o /etc/logrotate.conf que vem por omissão:

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
        minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.

E também uso o /etc/cron.daily/logrotate que vem por omissão:

#!/bin/sh

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

De acordo com a manpage do logrotate:

Citação

maxsize size

Log files are rotated when they grow bigger than size bytes even before the additionally specified time interval ( daily, weekly, monthly, or yearly). The related size option is similar except that it is mutually exclusive with the time interval options, and it causes log files to be rotated without regard for the last rotation time. When maxsize is used, both the size and timestamp of a log file are considered.

Até agora os logs ainda não atingiram os 50MB e já passaram vários dias sem haver qualquer rotação.

A minha única pista neste momento aparece no /var/log/messages a mensagem de warning do script /etc/cron.daily/logrotate: "ALERT existed abnormally with [1]". Já pesquisei e cheguei a esta página que diz que o problema se deve ao facto de os ficheiros de log não estarem na diretoria /var/log, mas que isso não é impedimento para que o logrotate faça o seu trabalho. Ainda não investiguei a fundo o que é o SELinux e por isso não me sinto muito confortável em executar a solução sugerida (até porque tenho de ter algum cuidado com a máquina em questão). Mas será que o problema vem mesmo daí?

Já coloquei a questão no Unix StackExchange mas ninguém me respondeu.

Posted (edited)

Estive a estudar o SELinux pela documentação da Redhat e era mesmo disso, resolvi usando a mesma resolução na página que eu tinha encontrado (https://access.redhat.com/solutions/39006).

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security-enhanced_linux/sect-security-enhanced_linux-maintaining_selinux_labels_-checking_the_default_selinux_context

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security-enhanced_linux/sect-security-enhanced_linux-selinux_contexts_labeling_files-persistent_changes_semanage_fcontext

Também encontrei uma thread no SO com o mesmo problema que eu, o que também ajudou: https://stackoverflow.com/questions/15652654/logrotate-cron-job-not-rotating-certain-logs

Confirmei também o erro que encontrava no /var/log/messages:

# aureport -a

245. 01/08/2018 03:45:01 logrotate system_u:system_r:logrotate_t:s0-s0:c0.c1023 2 file write unconfined_u:object_r:usr_t:s0 denied 55073
246. 01/08/2018 03:45:01 logrotate system_u:system_r:logrotate_t:s0-s0:c0.c1023 2 file write system_u:object_r:usr_t:s0 denied 55074
247. 01/08/2018 03:45:01 logrotate system_u:system_r:logrotate_t:s0-s0:c0.c1023 2 file write system_u:object_r:usr_t:s0 denied 55075
248. 01/08/2018 03:45:01 logrotate system_u:system_r:logrotate_t:s0-s0:c0.c1023 2 file write system_u:object_r:usr_t:s0 denied 55076
Edited by Baderous
  • Vote 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.