要啟用logrotate的自動壓縮功能,可以按照以下步驟操作:
打開logrotate的配置文件,通常位于/etc/logrotate.conf或/etc/logrotate.d/目錄中。
在配置文件中找到要壓縮的日志文件的條目,并確保下面的選項設置為“compress”: compress
如果要自定義壓縮選項,可以添加以下選項: compresscmd /usr/bin/gzip compressoptions -9 compressext .gz
保存配置文件并退出編輯器。
確保logrotate的定時任務已啟用??梢允褂靡韵旅顧z查: systemctl status logrotate
如果未啟用,可以使用以下命令啟用logrotate的定時任務: systemctl enable logrotate
重新加載logrotate的配置文件,以使更改生效: logrotate -f /etc/logrotate.conf
現在,logrotate將在輪換日志文件時自動壓縮舊的日志文件。