Kafka0.8版本長時間運行過程當中,在kafka_2.8.0-0.8.0/logs目錄下產生了大量的kafka-request.log.*和server.log.*文件,其中*表明日期和時間,好比kafka-request.log.2014-12-08-03和server.log.2014-12-06-03,這些文件對磁盤空間的消耗很是大,須要按期備份或者清理。目前沒有發現kafka自身提供了這些操做日誌備份或者清理的方法,須要用戶本身實現。linux
kafka0.8版本中,config/log4j.properties中日誌的級別設置的是TRACE,在長時間運行過程當中產生的日誌大小嚇人,因此若是沒有特殊需求,強烈建議將其更改爲INFO級別。具體修改方法以下所示,將config/log4j.properties文件中最後的幾行中的TRACE改爲INFO,修改前以下所示:vim
log4j.logger.kafka.network.RequestChannel$=TRACE, requestAppenderbash
log4j.additivity.kafka.network.RequestChannel$=falsespa
#log4j.logger.kafka.network.Processor=TRACE, requestAppender操作系統
#log4j.logger.kafka.server.KafkaApis=TRACE, requestAppender.net
#log4j.additivity.kafka.server.KafkaApis=false日誌
log4j.logger.kafka.request.logger=TRACE, requestAppenderserver
log4j.additivity.kafka.request.logger=falsecrontab
log4j.logger.kafka.controller=TRACE, controllerAppenderkafka
log4j.additivity.kafka.controller=false
log4j.logger.state.change.logger=TRACE, stateChangeAppender
log4j.additivity.state.change.logger=false
修改後以下所示:
log4j.logger.kafka.network.RequestChannel$=INFO, requestAppender
log4j.additivity.kafka.network.RequestChannel$=false
#log4j.logger.kafka.network.Processor=INFO, requestAppender
#log4j.logger.kafka.server.KafkaApis=INFO, requestAppender
#log4j.additivity.kafka.server.KafkaApis=false
log4j.logger.kafka.request.logger=INFO, requestAppender
log4j.additivity.kafka.request.logger=false
log4j.logger.kafka.controller=INFO, controllerAppender
log4j.additivity.kafka.controller=false
log4j.logger.state.change.logger=INFO, stateChangeAppender
log4j.additivity.state.change.logger=false
備份操做日誌的方式是按期拷貝操做日誌到指定大容量存儲設備,而後將其刪除。我在項目中採起的方式是直接清理過時操做日誌,方法很是簡單,利用linux操做系統提供的crontab功能,按期清理操做日誌,方法以下:
在/etc/crontab文件中添加刪除操做日誌的語句,而後執行crontab -f /etc/crontab命令便可,個人/etc/crontab文件以下所示,語句的含義是每4天在23:59執行清理操做:
[root@h10p11 logs]# vim /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
59 23 */4 * * rm -fr /root/kafka/kafka_2.8.0-0.8.0/logs/*-*-*
直接修改/etc/crontab文件重啓機器不用重複設置。