Apache Log Segmentation (Rotatelogs, Cronolog)

Source: Internet
Author: User
Tags local time apache log

Why do you want to split the log?

With the increase of website access, the log files generated by the Web server will become larger, if not split management, a single log file will become unusually large, not conducive to the comprehensive analysis of the log, monitoring and so on. In addition, when the server encountered a failure, operation and maintenance personnel will open the log file for analysis, the process will inevitably consume a long time, will inevitably increase the time to deal with the failure. Therefore, managing a large amount of log files is of great significance to the management of the website.

Here are two common ways to log segmentation: one. Apache Rotatelogs split Tool 1. Query the absolute path of the Rotatelogs command
which rotatelogs

2. Edit the httpd.conf configuration file
vim /etc/httpd/conf/httpd.conf

Modify the configuration file, mainly the Customlog parameter

<virtualhost *:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache/htdocs"
ServerName www.test.com
Errorlog "|/usr/sbin/rotatelogs-l/usr/local/apache/logs/www.test.com-error%y%m%d.log"
Customlog "|/usr/sbin/rotatelogs-l/usr/local/apache/logs/www.test.com-access
%y%m%d.log 86400" combined// Defines the access log format, where 86400 means one day, a new log file is generated daily
</VirtualHost>

Note: Rotatelogs-l uses local time instead of GMT as the time datum, and using-l in an environment that alters the GMT offset (such as daylight saving times) can cause unpredictable results.

3. Create a log file directory
mkdir -p /usr/local/apache/logs
4. Create a Web Site Directory
mkdir -p /usr/local/apache/htdocs
5. Restart the APAHCE service
service httpd stop      //停止service httpd start     //开启
6. Testing

Two. Third-party tools Cronolog log split 1. Unzip the source package into the/OPT directory
tar xzvf cronolog-1.6.2.tar.gz -C /opt
2. Enter the Cronolog directory
cd /opt/cronolog-1.6.2/
3. Configuration
./configure
4. Compiling and installing
make && make install
5. View the absolute path of the Cronolog command
which cronolog
6. Editing the Apache configuration file
vim /etc/httpd/conf/httpd.conf

Modify the configuration file, mainly the Customlog parameter

<virtualhost *:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache/htdocs"
ServerName www.test.com
Errorlog "|/usr/local/sbin/cronolog/usr/local/apache/logs/www.test.com-error%y%m%d.log"
Customlog "|/usr/local/sbin/cronolog/usr/local/apache/logs/www.test.com-access
%Y%m%d.log" combined
</VirtualHost>

7. Restart the HTPPD service
service httpd restart
8. Testing

Apache Log Segmentation (Rotatelogs, Cronolog)

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.