Los logs de Jira / Confluence se pueden dividir en dos grupos, los del servidor (Tomcat) y los propios del Framework (Jira / Confluence).
En esta guía se mostrará la forma más limpia de hacerlo, que en resumen es, desactivar la rotación y modificar el formato de logs en los ficheros de configuración para cederle así todo el control a logrotate. Jira y Confluence utilizan log4j con su configuración predeterminada, el servidor Tomcat basa su configuración en los ficheros server.xml y logging.properties.
Información sobre rotación de logs: How to Rotate Catalina Log File
De forma no permanente en la sección de administración del framework De forma permanente en el fichero: log4j.properties
log4j.logger.com.atlassian = XXXXX, console, filelog
Levels (XXXXX): 'DEBUG', 'INFO', 'WARN', 'ERROR' und 'FATAL'.
Jira framework: /opt/atlassian/jira/logs/ Jira Tomcat: /var/atlassian/application-data/jira/log/ Configuración de logs: /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties
Confluence framework: /var/atlassian/application-data/confluence/logs/ Confluence Tomcat: /opt/atlassian/confluence/logs/ Configuración de logs: /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties
access_log.log: server.xml (Depende de la configuración realizada) catalina.out: catalina.sh || setenv.sh || logging.properties catalina.log: (catalina.log es un “resumen” de catalina.out) host-manager.log: logging.properties manager.log: logging.properties localhost.log: logging.properties
NOTA: Se suelen crear / modificar cuando se reinicia el sistema / servicio.
atlassian-jira.log: log4j.properties atlassian-jira-security.log: log4j.properties atlassian-greenhopper.log: log4j.properties atlassian-bonfire.log: log4j.properties atlassian-jira-security.log: log4j.properties
atlassian-confluence.log: log4j.properties
NOTA: El fichero atlassian-jira-security.log puede contener passwords si se configura el nivel de logs en modo “DEBUG”
Se configurará el fichero log4j.properties para que no rote logs hasta que estos superen 1 Gb, así nos aseguramos que logrotate llegue antes de que eso ocurra.
service jira stop cp /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties_backup sed 's/20480KB/1048576KB/g' /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties > log4j.properties_1G mv log4j.properties_1G /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties
Editamos la linea 167 del fichero /opt/atlassian/jira/conf/server.xml
valve classname="org.apache.catalina.valves.AccessLogValve" pattern="combined" resolvehosts="false" rotatable="false" suffix="log"
El fichero logging.properties en jira v6.1 viene en formato “DOS”, si estamos en entornos Unix es mejorar pasarlo a formato Unix.
cp /opt/atlassian/jira/conf/logging.properties /opt/atlassian/jira/conf/logging.properties_backup perl -pi -e 's/\r\n/\n/g' /opt/atlassian/jira/conf/logging.properties
Editamos el fichero /opt/atlassian/jira/conf/logging.properties a partir de la linea 25.
############################################################ # Handler specific properties. # Describes specific configuration info for Handlers. ############################################################ 1catalina.org.apache.juli.FileHandler.level = FINE 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.FileHandler.prefix = catalina 1catalina.org.apache.juli.FileHandler.rotatable = false 2localhost.org.apache.juli.FileHandler.level = FINE 2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.FileHandler.prefix = localhost. 2localhost.org.apache.juli.FileHandler.rotatable = false 2localhost.org.apache.juli.FileHandler.suffix = log 3manager.org.apache.juli.FileHandler.level = FINE 3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 3manager.org.apache.juli.FileHandler.prefix = manager. 3manager.org.apache.juli.FileHandler.rotatable = false 3manager.org.apache.juli.FileHandler.suffix = log 4host-manager.org.apache.juli.FileHandler.level = FINE 4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 4host-manager.org.apache.juli.FileHandler.prefix = host-manager. 4host-manager.org.apache.juli.FileHandler.rotatable = false 4host-manager.org.apache.juli.FileHandler.suffix = log java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter ############################################################
service jira start
Creamos los ficheros /etc/logrotate.d/jira_tomcat y /etc/logrotate.d/jira.
Archivo /etc/logrotate.d/jira_tomcat
/opt/atlassian/jira/logs/*.log { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok } /opt/atlassian/jira/logs/*.out { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok }
Archivo /etc/logrotate.d/jira
/var/atlassian/application-data/jira/log/*.log { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress }
Se configurará el fichero log4j.properties para que no rote logs hasta que estos superen 1 Gb, así nos aseguramos que logrotate llegue antes de que eso ocurra.
service confluence stop
cp /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties_backup sed 's/20480KB/1048576KB/g' /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties > log4j.properties_1G mv log4j.properties_1G /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties
Editamos el fichero /opt/atlassian/confluence/conf/logging.properties a partir de la linea 25.
############################################################ # Handler specific properties. # Describes specific configuration info for Handlers. ############################################################ 1catalina.org.apache.juli.FileHandler.level = FINE 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.FileHandler.prefix = catalina 1catalina.org.apache.juli.FileHandler.rotatable = false 2localhost.org.apache.juli.FileHandler.level = FINE 2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.FileHandler.prefix = localhost. 2localhost.org.apache.juli.FileHandler.rotatable = false 2localhost.org.apache.juli.FileHandler.suffix = log 3manager.org.apache.juli.FileHandler.level = FINE 3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 3manager.org.apache.juli.FileHandler.prefix = manager. 3manager.org.apache.juli.FileHandler.rotatable = false 3manager.org.apache.juli.FileHandler.suffix = log 4host-manager.org.apache.juli.FileHandler.level = FINE 4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 4host-manager.org.apache.juli.FileHandler.prefix = host-manager. 4host-manager.org.apache.juli.FileHandler.rotatable = false 4host-manager.org.apache.juli.FileHandler.suffix = log java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter ############################################################
service confluence start
Creamos los ficheros /etc/logrotate.d/confluence y /etc/logrotate.d/confluence_tomcat
Archivo /etc/logrotate.d/confluence_tomcat
/opt/atlassian/confluence/logs/*.log { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok } /opt/atlassian/confluence/logs/*.out { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok }
Archivo /etc/logrotate.d/confluence_tomcat
/var/atlassian/application-data/confluence/logs/*.log { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok }
Sería suficiente con tener una copia de seguridad de la anterior instancia, parar el servicio y sustituir los siguientes ficheros.
Jira: logging.properties y server.xml Confluence: logging.properties y log4j.properties
yum install crontabs
service crond start
chkconfig crond on
NOTA: SeLinux debe desactivarse o bien configurarse a medida, en caso contrario la rotación de logs automática fallará. Si se ejecuta logrotate desde la linea de comando como root veremos que se ejecuta todo correctamente, pero si delegamos la tarea en cron / crontab esta fallará si SeLinux está activo. Esto puede depender de la distribución utilizada y la configuración de logrotate. En redHat / CentOS con esta configuración dada es altamente recomendable desactivar SeLinux (o configurarlo para que permita la rotación).
Salida de /var/log/messages
logrotate: ALERT exited abnormally with [1]
SeLinux log: /var/log/audit/audit.log
type=SYSCALL msg=audit(1385260621.900:1755): arch=c000003e syscall=2 success=no exit=-13 a0=7ffff9ef0500 a1=90800 a2=203b7d0 a3=2f617461642d6e6f items=0 ppid=10146 pid=10148 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=102 comm="logrotate" exe="/usr/sbin/logrotate" subj=system_u:system_r:logrotate_t:s0-s0:c0.c1023 key=(null) type=AVC msg=audit(1385260621.902:1756): avc: denied { write } for pid=10148 comm="logrotate" name="catalina.2013-11-22.log" dev=dm-0 ino=6908 scontext=system_u:system_r:logrotate_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:usr_t:s0 tclass=file
Activar / definir el nivel de logs en JIRA / Confluence (Optativo): Leer
Directorio donde JIRA y Confluence almacenan los logs: Leer
Instalar crond / crontabs (CentOS / RedHat): Leer
El fichero de configuracion de los logs “log4j.properties” será modificado para que los logs sean rotados por Tomcat al llegar a 1Gb, de esa forma nos aseguramos de que logrotate llegue antes.
service jira stop cp /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties_backup sed 's/20480KB/1048576KB/g' /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties > log4j.properties_1G mv log4j.properties_1G /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties service jira start
Crear los ficheros /etc/logrotate.d/jira_tomcat y /etc/logrotate.d/jira
Fichero /etc/logrotate.d/jira_tomcat
/opt/atlassian/jira/logs/*.log { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok } /opt/atlassian/jira/logs/*.out { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress }
Fichero /etc/logrotate.d/jira
/var/atlassian/application-data/jira/log/*.log { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress postrotate find /var/atlassian/application-data/jira/log -type f -empty -mtime +3 -exec rm {} \; #Die leere Tomcat Logs wird nach 3 Tage mit keiner Bearbeitung gelöscht / access_log Dateien ab 7 tage eliminieren (logrotate kann es nicht allein machen) find /opt/atlassian/jira/logs/ -type f -empty -mtime +3 -exec rm {} \; find /opt/atlassian/jira/logs/ -type f -name "access_log.*" -mtime +6 -exec rm {} \; endscript }
Lo mismo que en Jira, el fichero de configuracion de los logs “log4j.properties” será modificado para que los logs sean rotados por Tomcat al llegar a 1Gb, de esa forma nos aseguramos de que logrotate llegue antes.
service confluence stop cp /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties_backup sed 's/20480KB/1048576KB/g' /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties > log4j.properties_1G mv log4j.properties_1G /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties service confluence start
Crear los ficheros /etc/logrotate.d/confluence_tomcat y /etc/logrotate.d/confluence.
Fichero /etc/logrotate.d/confluence_tomcat
/opt/atlassian/confluence/logs/*.log { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok postrotate #Die leere Logs wird nach 3 Tage mit keiner Bearbeitung gelöscht find /opt/atlassian/confluence/logs/ -type f -empty -mtime +3 -exec rm {} \; endscript } /opt/atlassian/confluence/logs/*.out { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok }
Fichero /etc/logrotate.d/confluence
/var/atlassian/application-data/confluence/logs/*.log { copytruncate notifempty daily dateext dateformat __%d-%m-%Y rotate 7 delaycompress compress missingok }
Jira
service jira stop cp /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties_backup sed 's/20480KB/1048576KB/g' /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties > log4j.properties_1G mv log4j.properties_1G /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/log4j.properties service jira start
Confluence
service confluence stop cp /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties_backup sed 's/20480KB/1048576KB/g' /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties > log4j.properties_1G mv log4j.properties_1G /opt/atlassian/confluence/confluence/WEB-INF/classes/log4j.properties service confluence start