1. Self-rotatelogs log cutting
Rotatelogs Log Polling Instructions
___________________________________________________________
Grammar
Rotatelogs [-l] logfile [rotationtime [offset]] | [Filesizem]
Options
-L uses local time instead of GMT time as the time base. Note: In an environment that changes the GMT offset (such as daylight saving time)
Using-L can cause unpredictable results.
LogFile it plus the reference name is the log file name. If logfile contains "%", it is treated as a format string for strftime () , otherwise it is automatically appended with the ". nnnnnnnnnn" suffix in seconds. Both formats represent the time when the new log began to be used.
Rotationtime the interval of time in seconds that the log file is scrolled.
the number of minutes to offset the time difference from UTC. If omitted, it is assumed to be "0" and UTC time is used. For example, to specify a UTC time difference of
"-5 hours" for local time in the region, then this parameter should be "300".
Filesizem Specifies to scroll with the size of the Filesizem file instead of scrolling by time or slack.
___________________________________________________________
Log polling production environment actual configuration
___________________________________________________________
Actual configuration of common production environments polled by day:
[[email protected]_server]vim /usr/local/apache2/conf/extra/httpd-vhosts.conf<virtualhost * : 80> serveradmin [email protected] documentroot "/data/www" ServerName szk5043.top # ServerAlias www.dummy-host.example.com errorlog "/usr/local/apache2/logs/szk5043.top-error_log " CustomLog " |/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/ logs/szk5043.top-access_%y%m%d_log 86400 " combined[[email protected]_server ~]# ls /usr/local/apache2/logsaccess_log error_log httpd.pid szk5043.top-access_20160402_log szk5043.top-error_log[[email protected]_server ~]# cat /usr/local/apache2/logs/szk5043.top-access_20160402_log127.0.0.1 - - [02/apr/ 2016:16:10:17 +0800] "options *  http/1.0 " 200 - "-" " apache/2.2.31 (Unix) PHP/5.5.31 (internal dummy connection) "127.0.0.1 - - [02/apr/2016:16:10:17 +0800] " OPTIONS * http/1.0 " 200 - "-" " apache/2.2.31 (Unix)
___________________________________________________________
Logging proxy IP and real client:
[[email protected]_server ~]# vim /usr/local/apache2/conf/httpd.conf #LogFormat "%h %l %u %t \"%r\ " %>s %b \"%{referer}i\ " \" %{user-agent}i\ "" combined #搜索LogFormat关键字, note the original configuration LogFormat "%h %{x-forwarded-for}i %l %u %t \"%r\ " %>s % B \ "%{referer}i\" \ "%{user-agent}i\" " combined #添加此行 [[email protected]_server ~]# apachectl graceful[[email protected]_server ~]# tail -2 /usr/local/apache2/logs/szk5043.top-access_20160402_log127.0.0.1 - - - [02/apr/ 2016:16:20:32 +0800] "options * http/1.0" 200 - "-" "apache/2.2.31 (Unix) PHP/5.5.31 (internal dummy connection) "112.65.11.52 - - - [02/apr/2016:16:21:09 +0800] "get /favicon.ico http/1.1" 200 5558 "http://115.28.241.168/admin.php" "mozilla/5.0 (WINDOWS&NBSP;NT&NBSP;10.0;&NBSP;WOW64) AppleWebKit/537.36 (khtml, like Gecko) chrome/48.0.2564.116 safari/537.36 "
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/6D/wKioL1b_lPHTRiG9AABCBpvlQIM068.png "title=" Clipboard.png "alt=" Wkiol1b_lphtrig9aabcbpvlqim068.png "/>
2.cronolog Log Cutting
Installing the Rotatelogs Log cutting tool
___________________________________________________________
HTTP://PAN.BAIDU.COM/S/1SLWP1S5 #百度网盘 [[email protected]_server src]# Tar xf cronolog-1.6.2.tar.gz[[email protected]_s erver src]# cd cronolog-1.6.2[[email protected]_server cronolog-1.6.2]#./configure [Email Protected]_server cronolog-1.6.2]# make && make install
Cronolog Log Cutting configuration instructions
___________________________________________________________
#按小时切割CustomLog "|/usr/local/sbin/cronolog/usr/local/apache2/logs/access_szk5043.top_%y%m%d%h.log" Combined # Cut by day (logs are not automatically overwritten) Customlog "|/usr/local/sbin/cronolog/usr/local/apache2/logs/access_szk5043.top_%y%m%d.log" Combined #按周建议目录, polling customlog by day "|/usr/local/sbin/cronolog/usr/local/apache2/logs/%w/access_szk5043.top_%y%m% D.log "combined
Log polling production environment actual configuration
___________________________________________________________
[[email protected]_server ~] #vim /usr/local/apache2/conf/extra/httpd-vhosts.conf<virtualhost *:80> ServerAdmin [email protected] documentroot "/data/www" ServerName szk5043.top # serveralias www.dummy-host.example.com errorlog "/usr/local/apache2/logs/ Szk5043.top-error_log " #CustomLog " |/usr/local/apache2/bin/rotatelogs -l /usr/ local/apache2/logs/szk5043.top-access_%y%m%d_log 86400 " combined #注释前面配置 CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2/logs/ Access_szk5043.top_%y%m%d%h.log " combined #新增此行 </VirtualHost>[[email protected]_server ~]# cat /usr/local/apache2/logs/access_szk5043.top_2016040217.log127.0.0.1 - - - [02/apr/2016:17:12:29 +0800] "options * http/1.0" 200 - "-" "apache/2.2.31 ( Unix) PHP/5.5.31 (internal dummy connection) "
3. The specified type log is not logged
[[email protected]_server ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf ErrorLog "/usr/local/apache2/logs/szk5043.top-error_log" setenvir request_uri ". *\.gif$" image-request setenvif request_uri ". *\.jpg$" image-request SetEnvIf Request_URI ". *\.png$" image-request setenvif request_uri ". *\.bmp$" image-request SetEnvIf Request_URI ". *\.swf$" image-request SetEnvIf request_uri ". *\.js$" image-request SetEnvIf Request_URI ". *\.css$" image-request CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/ local/apache2/logs/szk5043.top-access_%y%m%d_log 86400 " combined[[email protected]_server ~]# apachectl gracefUl
This article is from the "Fuqin Wine" blog, please make sure to keep this source http://szk5043.blog.51cto.com/8456440/1759579
Apache Log cutting and no logging of specified types