顯示廣告
隱藏 ✕
看板 Knuckles_note
作者 Knuckles (站長 那克斯)
標題 [Linux][CentOS] Apache 使用 cronolog 產生每日log檔
時間 2012年06月28日 Thu. PM 12:41:35



==== 2014/5/6 更新 ===================

CentOS 6 預設就可以使用 logrotate 產生每日log檔
參考: http://disp.cc/b/11-7Eh8
不需安裝 cronolog 了

==== 以下為原本的內容 ================
要先 安裝 EPEL repo

安裝 cronolog
$ yum install cronolog


找出cronolog的安裝路徑
$ which cronolog
/usr/sbin/cronolog

安裝好之後修改 Apache 的設定檔,將原本的 log 設定,如:
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/apache2/access.log combined
改成
    ErrorLog "|/usr/sbin/cronolog /var/log/httpd/%Y%m%d.error.log"
    CustomLog "|/usr/sbin/cronolog /var/log/httpd/%Y%m%d.access.log" combined

前面的 “|” 那是 pipeline 給 cronolog 作處理的意思


每個 virtual host 可以設定自己的 log 檔,例如

<VirtualHost *:80>
    ServerName    disp.cc
    DocumentRoot  /var/www/disp

    <Directory "/var/www/disp">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    #log
    ErrorLog "|/usr/sbin/cronolog /var/log/httpd/%Y%m%d.disp.error.log"
    LogLevel warn
    CustomLog "|/usr/sbin/cronolog /var/log/httpd/%Y%m%d.disp.access.log" combined

</VirtualHost>



--
※ 作者: Knuckles 時間: 2012-06-28 12:41:35
※ 編輯: Knuckles 時間: 2014-05-06 08:57:14
※ 看板: KnucklesNote 文章推薦值: 0 目前人氣: 0 累積人氣: 1378 
e)編輯 d)刪除 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇