Lamp--apache Log Cutting

Source: Internet
Author: User
Tags apache log

In the case of a log, we log several logs each time we visit the site. If the log is not managed, the log files will grow larger and larger, too large to be open with cat, less, and vim, head and tail. To avoid generating such a large log file, Apache has a configuration that allows the logs to be archived according to our needs, such as a new log every day or every hour.

[Email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

Open the Apache virtual Host configuration file and you can see the sample configuration file:

#<virtualhost *:80># ServerAdmin [email protected]# documentroot]/usr/local/apache2/docs/dummy-host.example.c Om "# ServerName dummy-host.example.com# serveralias www.dummy-host.example.com# errorlog" Logs/dummy-host.example . Com-error_log "# customlog" Logs/dummy-host.example.com-access_log "common#</virtualhost>

Where errorlog is the error log, Customlog is the access log. The path in double quotes is the relative path to the/usr/local/apache2/directory, which can be configured to set the log name, common is the format of the log. This way is fixed generated log, will cause the above mentioned log file is too large, then we need to the existing host configuration to do the following operations.

Add errorlog and Customlog two lines to the corresponding virtual host configuration file:

<virtualhost *:80> documentroot "/data/www" ServerName www.123.com serveralias www.test.com errorlog "|/ Usr/local/apache2/bin/rotatelogs-l/usr/local/apache2/logs/123.com-error_%y%m%d_log 86400 "CustomLog" |/usr/local/ Apache2/bin/rotatelogs-l/usr/local/apache2/logs/123.com-access_%y%m%d_log 86400 "combined <directory/data/www/ admin.php> allowoverride authconfig authname "Please input the passwd"

In double quotes, the front vertical line is the pipe character, which means that the resulting log is passed to Rotatelogs, which is the tool for Apache's own cut logs. The function of-L is to calibrate the timezone to UTC, Beijing time. The last side of 86400, the unit is the second, meaning a day. The combined for double cited is the log format, which defines the log format in/usr/local/apache2/conf/httpd.conf.

[[email protected] ~]# grep logformat/usr/local/apache2/conf/httpd.conf logformat "%h%l%u%t \"%r\ "%>s%b \"%{re Ferer}i\ "\"%{user-agent}i\ "" Combined Logformat "%h%l%u%t \"%r\ "%>s%b" Common Logformat "%h%l%u%t \"%r \ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "%I%O" Combinedio

After setting the cutting configuration, restart Apache.

[Email protected] ~]#/usr/local/apache2/bin/apachectl-tsyntax ok[[email protected] ~]#/usr/local/apache2/bin/ Apachectl restart

After you access the Web site in your browser, view the log file

[Email protected] ~]# Ls/usr/local/apache2/logs/123.com-access_20160518_log DUMMY-HOST.EXAMPLE.COM-ACCESS_LOGACC Ess_log Dummy-host.example.com-error_logdummy-host2.example.com-access_log Error_logdummy-host2. Example.com-error_log Httpd.pid

The corresponding log has appeared, change the next time, and then browse the test

[[email protected] ~]# date-s "2016-05-19 09:00:00" May 19, 2016 Thu 09:00:00 cst[[email protected] ~]# Ls/usr/local/apa Che2/logs/123.com-access_20160518_log Dummy-host.example.com-access_log123.com-access_20160519_log dummy-h Ost.example.com-error_logaccess_log Error_logdummy-host2.example.com-access_log httpd.piddummy-h Ost2.example.com-error_log

A new log file is generated and the cut configuration is successful.


This article is from the "Learn Notes for students" blog, please make sure to keep this source http://sanyisheng.blog.51cto.com/11154168/1795813

Lamp--apache Log Cutting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.