Apache分割日誌

來源:互聯網
上載者:User

標籤:虛擬機器主機   使用者名稱   設定檔   common   local   

我們訪問網站的時候會有記錄留下來,這個就是記錄檔,日誌的資訊有(來源ip,訪問時間等資訊)


1.在虛擬機器主機的設定檔中已經存在了記錄檔的配置,我們只需要把它開啟就可以


vi /usr/local/apache2/conf/extra/httpd-vhosts.conf


日誌中有個common表示日誌的格式,把它修改為combined


650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M01/8B/23/wKioL1hFlLmDppgtAACEwKbr5jE539.png-wh_500x0-wm_3-wmp_4-s_928462825.png" style="float:none;" title="1.png" alt="wKioL1hFlLmDppgtAACEwKbr5jE539.png-wh_50" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/8B/27/wKiom1hFlLuyQpB6AACW37NWVMs062.png-wh_500x0-wm_3-wmp_4-s_1460624953.png" style="float:none;" title="2.png" alt="wKiom1hFlLuyQpB6AACW37NWVMs062.png-wh_50" />

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />



2.可以修改日誌的名稱


修改為test.com-error_log

          test.com-access_log


預設日誌路徑在 /usr/local/apache2/logs/


650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s2.51cto.com/wyfs02/M02/8B/27/wKiom1hFlMajucEnAACmQRcjZpc152.png-wh_500x0-wm_3-wmp_4-s_341088372.png" title="3.png" alt="wKiom1hFlMajucEnAACmQRcjZpc152.png-wh_50" />



3.設定好後重啟並重新載入


apachectl -t

apachectl graceful


4.重新整理網頁


進入日誌目錄查看是否產生了記錄檔


cd /usr/local/apache2/logs/


ls 查看檔案


650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />



cat test.com-access_log  可以查看訪問日誌訊息


日誌格式:LogFormat "%h %l %u %t %T \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""


%h 遠端主機

%l 遠端登入名稱

%u 遠端使用者名

%t 時間,用普通日誌時間格式

%T 處理完請求所花時間,以秒為單位

%r 請求的第一行,動作

來源ip後面二個是不存在,所有用--表示(l:u:表示使用者)



650) this.width=650;" src="http://s2.51cto.com/wyfs02/M02/8B/23/wKioL1hFlOXQD-t8AAD6Sm4eLZw674.png-wh_500x0-wm_3-wmp_4-s_2260812398.png" title="34.png" alt="wKioL1hFlOXQD-t8AAD6Sm4eLZw674.png-wh_50" />

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />





5.查看記錄檔的容量


wc -l test.com-access_log


650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />


為了使格式按時間排序應該如何做?


在虛擬機器主機日誌設定檔裡添加一些內容


CustomLog "| /usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400" combined


650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/8B/27/wKiom1hFlP-RWEb1AACiOSxQLrU156.png-wh_500x0-wm_3-wmp_4-s_4167075387.png" title="4.png" alt="wKiom1hFlP-RWEb1AACiOSxQLrU156.png-wh_50" />


重新整理網頁,產生一個有日期的日誌


650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/8B/23/wKioL1hFlQ-igCipAAAOmERYZ14245.png-wh_500x0-wm_3-wmp_4-s_3854248745.png" title="5.png" alt="wKioL1hFlQ-igCipAAAOmERYZ14245.png-wh_50" />


修改日期,然後在重新整理網頁看是否有沒有組建記錄檔


date -s "2016-11-21 15:55:20"



650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/8B/27/wKiom1hFlTbS5pXFAAANNkWJIz4223.png-wh_500x0-wm_3-wmp_4-s_166256326.png" title="6.png" alt="wKiom1hFlTbS5pXFAAANNkWJIz4223.png-wh_50" />


重新整理網頁,會產生一個新的記錄檔



650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s4.51cto.com/wyfs02/M00/8B/27/wKiom1hFlT6hbIsTAAAN4QLSHbQ496.png-wh_500x0-wm_3-wmp_4-s_1725241055.png" title="7.png" alt="wKiom1hFlT6hbIsTAAAN4QLSHbQ496.png-wh_50" />



Apache分割日誌

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.