<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[MaruMagi部落格之拷貝經驗]]></title> 
<link>http://maru.gates.tw/index.php</link> 
<description><![CDATA[別人耶經驗,著是我耶成功啦!!]]></description> 
<language>zh-tw</language> 
<copyright><![CDATA[MaruMagi部落格之拷貝經驗]]></copyright>
<item>
<link>http://maru.gates.tw/read.php/.htm</link>
<title><![CDATA[Apache Server log 肥大的問題]]></title> 
<author>zuyan &lt;zuyan_chang@yahoo.com.tw&gt;</author>
<category><![CDATA[伺服器軟體]]></category>
<pubDate>Fri, 26 Nov 2010 09:24:36 +0000</pubDate> 
<guid>http://maru.gates.tw/read.php/.htm</guid> 
<description>
<![CDATA[ 
	由於Apache 流量漸漸增加而，Log檔一直增大，到時會很難處理<br/>必需要解決這個問題，查了一下資料 可以使用 apache 內建的一支程式處理<br/>rotatelogs<br/><br/><br/>我希望的存檔方式是每10MB即存成另一個檔案<br/>記錄的方式為 主機名+日期 範例如下<br/><br/><div class="code">&lt;VirtualHost *:80&gt;<br/>&nbsp;&nbsp; ......<br/>&nbsp;&nbsp;&nbsp;&nbsp;ErrorLog &quot;logs/maru.gates.tw.log&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#原來的設定方式<br/>&nbsp;&nbsp;&nbsp;&nbsp;#CustomLog &quot;logs/maru.gates.tw.log&quot; common&nbsp;&nbsp;<br/>&nbsp;&nbsp; #修改後的方式<br/>&nbsp;&nbsp;&nbsp;&nbsp;CustomLog &quot;&#124;D:/AppServ/Apache2.2/bin/rotatelogs D:/AppServ/Apache2.2/logs/maru.gates.tw%Y%m%d.log 10M&quot; common<br/>.......<br/>&lt;/VirtualHost&gt;</div><br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">◆ Windows下的日誌循環 <br/><br/>　　一般在Linux下的日誌循環可以由系統的 /etc/logrotate.conf 設定，而 Apache 的日誌循環設定檔在 /etc/logrotate.d/httpd 中(以Redhat/Fedora為例)，預設為一星期循環一次。有關系統日誌循環請參考相關教學文章。<br/>　　但是若您的Apache是安裝在Windows的系統中，日誌原則上(預設值)是不會循環的，所以若您一直沒有清除或手動循環log檔，一個檔案上GB大小也是有可能的，若需要去解析它可能要花很久的時間。Apache本身提供了 rotatelogs (在Windows下為 rotatelogs.exe) 這個指令來循環日誌，讓你可以手動執行指令(請參考 rotatelogs 指令教學) ，或是直接在 httpd.conf 中設定，範例如下：<br/><br/>每天循環(一天為86400秒)<br/>CustomLog "&#124;c:/apache2/bin/rotatelogs c:/apache2/logs/access_log 86400" combined<br/>檔案到達5MB就循環<br/>CustomLog "&#124;c:/apache2/bin/rotatelogs c:/apache2/logs/access_log 5M" common<br/> <br/><br/>但這樣設定的話，它所產生的Log檔案名稱格式為 access_log.nnnn，後面的 nnnn 由系統自動產生，例如：access_log.1168300800，但這樣的話比較不容易維護或分析，您可以把它改成這樣：<br/><br/>每天循環(一天為86400秒)<br/>CustomLog "&#124;c:/apache2/bin/rotatelogs c:/apache2/logs/access_log_%Y%m%d 86400" combined <br/><br/>如此產生出來的檔案名稱會像這樣：access_log_20070110<br/><br/>若您想自訂檔案名稱的日期格式，可以參考以下的設定值：<br/><br/>%A - full weekday name (localized)<br/>%a - 3-character weekday name (localized)<br/>%B - full month name (localized)<br/>%b - 3-character month name (localized)<br/>%c - date and time (localized)<br/>%d - 2-digit day of month<br/>%H - 2-digit hour (24 hour clock)<br/>%I - 2-digit hour (12 hour clock)<br/>%j - 3-digit day of year<br/>%M - 2-digit minute<br/>%m - 2-digit month<br/>%p - am/pm of 12 hour clock (localized)<br/>%S - 2-digit second<br/>%U - 2-digit week of year (Sunday first day of week)<br/>%W - 2-digit week of year (Monday first day of week)<br/>%w - 1-digit weekday (Sunday first day of week)<br/>%X - time (localized)<br/>%x - date (localized)<br/>%Y - 4-digit year<br/>%y - 2-digit year<br/>%Z - time zone name<br/>%% - literal `%' <br/><br/>完成以上 設定後，重新啟動 Apache 即可。<br/>*******************************************************************************<br/><br/>使用之前，請先把httpd.conf中，關於access.log的部分，先disable掉。<br/>->CustomLog logs/access.log common<br/>改成<br/>->#CustomLog logs/access.log common<br/>也就是加個 "#" 即可。<br/><br/>依據自己實際測試後，發現上面所舉的例子，對我並不適用<br/>->CustomLog "&#124;c:/apache2/bin/rotatelogs c:/apache2/logs/access_log 86400" combined<br/><br/>我是把它改成如下的方式：<br/><br/>TransferLog "&#124;c:/AppServ/Apache2/bin/rotatelogs.exe c:/AppServ/Apache2/logs/%Y%m%d_access.log 86400"<br/>ErrorLog "&#124;c:/AppServ/Apache2/bin/rotatelogs.exe c:/AppServ/Apache2/logs/%Y%m%d_error.log 86400"<br/><br/>這樣之後，它會自動每天更換一個檔名，來做為記錄檔使用，也不必去清空它的內容，感覺還不錯。</div></div><br/><br/>參考資料<br/><a href="http://forum.lifetype.org.tw/index.php?topic=2010.5;wap2" target="_blank">http://forum.lifetyp...hp?topic=2010.5;wap2</a><br/>Tags - <a href="http://maru.gates.tw/go.php/tags/apache/" rel="tag">apache</a> , <a href="http://maru.gates.tw/go.php/tags/rotatelogs/" rel="tag">rotatelogs</a> , <a href="http://maru.gates.tw/go.php/tags/log/" rel="tag">log</a>
]]>
</description>
</item><item>
<link>http://maru.gates.tw/read.php/.htm#blogcomment</link>
<title><![CDATA[[評論] Apache Server log 肥大的問題]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[評論]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://maru.gates.tw/read.php/.htm#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>