2015-02-24 53 views
2

我已經在Ubuntu機器上安裝了Cassandra 2.0.11。Cassandra:如何歸檔日誌文件

日誌記錄配置是默認設置。日誌文件的位置在

/var/log/cassandra/ 

此外,日誌文件已處於旋轉模式。

如何配置要壓縮的日誌文件? 因此它不會消耗大量的磁盤存儲空間。

回答

1

對於卡桑德拉2.0和以前

如果按照從這裏docs,你可能看到過compress命令。默認情況下,logrotate將使用gzip壓縮旋轉的文件。man page表示您還可以設置compresscmdcompressext以使用您自己的壓縮應用程序(即zip)。你可以把你自己的壓縮腳本放在一起。

例子:

/var/log/cassandra/output.log { 
     size 1k 
     copytruncate 
     create 
     compress 
     compresscmd /bin/bzip2 
     compressext .bz2 
     rotate 4 
} 

對於卡桑德拉2.1及更高版本

按照documentation,你應該結束你的fileNamePatternrollingPolicyzipgz。就像這裏的example一樣。

卡桑德拉文件,第二個鏈接上還說:大小超過20MB 後

默認策略滾動SYSTEM.LOG文件。檔案以zip格式壓縮。 Logback命名爲log 文件system.log.1.zip,system.log.2.zip等。有關更多 信息,請參閱logback文檔。

+0

的logback在卡桑德拉2.1推出,它是在Log4J的卡桑德拉2.0 – 2015-02-24 13:55:25

+0

好了,沒注意到......最近,我開始一個新項目,並開始與2.1,所以我機械回答是這樣的... – 2015-02-24 14:02:37

1

答案僅適用於Cassandra 2.0及之前版本。

Cassandra 2.0和更早版本正在使用log4j作爲日誌API。 它回答的必要性:

  1. 簡單的日誌
  2. 旋轉日誌文件

它不解答,需要壓縮\存檔舊的文件以節省存儲位置。

爲了支持舊的日誌文件的ZIP,你需要使用的log4j的擴展(見compress log4j log files) 如果你真的想激活它在卡桑德拉,你需要做到以下幾點:

  1. 從源代碼
  2. 下載log4j的,額外安裝它,並把它添加到卡桑德拉lib目錄
  3. 使用Maven編譯項目

顯然,你會這麼做的機會很渺茫。太多麻煩了。

有一個簡單的解決方案:(僅適用於Linux操作系統)

  1. 配置卡桑德拉使用簡單的日誌記錄
  2. 配置logrotate的守護程序處理日誌文件

配置Cassandra使用簡單的日誌記錄

sudo vi /etc/cassandra/log4j-server.properties 

更改下面這個文件中:

# Add the new Appender to the rootLogger 
log4j.rootLogger=INFO,stdout,F,R 

# Mark the following configuration (all the RollingFileAppender) 
# rolling log file 
#log4j.appender.R=org.apache.log4j.RollingFileAppender 
#log4j.appender.R.maxFileSize=1MB 
#log4j.appender.R.maxBackupIndex=3 
#log4j.appender.R.layout=org.apache.log4j.PatternLayout 
#log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n 

#log4j.appender.R.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy 
#log4j.appender.R.RollingPolicy.FileNamePattern=cassandra.%d{yyyy-MM-dd-HH}.gz 
#log4j.appender.R.RollingPolicy.ActiveFileName =cassandra.log 

# Edit the next line to point to your logs directory 
#log4j.appender.R.File=/var/log/cassandra/cassandra.log 
######################################################## 

# Add the new File Appender 
# file appender 
# Define the file appender 
log4j.appender.F=org.apache.log4j.FileAppender 
# Set the name of the file 
log4j.appender.F.File=/var/log/cassandra/cassandra.log 
# Define the layout for file appender 
log4j.appender.F.layout=org.apache.log4j.PatternLayout 
log4j.appender.F.layout.conversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n 

現在卡桑德拉僅記錄到一個文件,而不是將其旋轉。下一步...

配置logrotate的守護程序處理日誌文件

如果你真的想知道什麼是日誌輪播:Understanding logrotate utility

執行以下操作:

sudo vi /etc/logrotate.d/cassandra 

添加數據如下:

/var/log/cassandra/cassandra.log { 
    daily 
    rotate 50 
    size 100M 
    copytruncate 
    compress 
    delaycompress 
    missingok 
    notifempty 
    create 644 cassandra cassandra 
} 

就是這樣。從現在開始,logrotate會照顧你的日誌文件,並保持整個存儲空間不超過5GB。

如果你想改變存儲大小,配置旋轉大小你認爲合適的。