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)