Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Squid 日誌過大處理:logrotate 切割與 Squid 自帶 rotate 指令結合方案

編輯:關於伺服器

問題

Squid access.log、cache.log、store.log 單檔過大,影響查詢效能與磁碟空間。

方案一:logrotate 系統級切割 (推薦)

編輯 /etc/logrotate.d/squid (若修改過日誌路徑請同步更新):

/home/log/squid/access.log {
    weekly
    rotate 5
    copytruncate
    compress
    notifempty
    missingok
}

/home/log/squid/cache.log {
    weekly
    rotate 5
    copytruncate
    compress
    notifempty
    missingok
}

/home/log/squid/store.log {
    weekly
    rotate 5
    copytruncate
    compress
    notifempty
    missingok
    postrotate
        /usr/sbin/squid -k rotate
    endscript
}
  • copytruncate:複製後清空原檔,**無需重啟 Squid**,避免連線中斷。
  • postrotate:對 store.log 呼叫 squid -k rotate 讓 Squid 內部切換檔案描述符。

方案二:Squid 內建 rotate + crontab (每日切割)

  1. 修改 squid.conf:
    logfile_rotate 3 (保留 3 份)。
  2. 編輯 /etc/crontab:
    0 0 * * * squid /usr/local/squid/sbin/squid -k rotate (每天 00:00 切割)。
  3. 生效:crontab /etc/crontab。

比較建議

維度logrotateSquid rotate + cron
對 Squid 影響無 (copytruncate)需發送信號,極短暫阻塞
壓縮支援內建 compress需額外腳本
靈活度高 (按大小/時間/郵件通知)僅定時
推薦場景生產環境標準化運維簡單環境、舊版 Squid
Copyright © Windows教程網 All Rights Reserved