Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to split logs in Apache

Shulou Source: shulou.com Published: 2022-06-01 00:06:28 11月16日 Update

This article mainly introduces Apache how to split the log, the article is very detailed, has a certain reference value, interested friends must read it!

Why do we have to split the log?

With the increasing number of visits to the website, the log files generated by the web server will become larger and larger. If it is not segmented and managed, a single log file will become extremely large, which is not conducive to comprehensive analysis and monitoring of the log. In addition, when the server encounters a failure, the operation and maintenance staff have to open the log file for analysis, the opening process is bound to take a long time, and it is bound to increase the time to deal with the failure. Therefore, managing a large number of log files is of great significance to the management of the website.

This blog simply introduces two ways to split the log. First install the Apache package using yum-y install httpd.

Then modify the main configuration file, / etc/httpd/conf/httpd.conf, to change the hostname here to a test domain name.

Then find the line of the log file, and change the path to ErrorLog "| / usr/sbin/rotatelogs-l / var/log/httpd/www.demo.com.error_%Y%m%dlog 86400", which is fixed.

After the error log modification is completed, we need to modify the normal access log. Comment out the original configuration statement, and then add a new statement CustomLog "| / usr/sbin/rotatelogs-l logs/demo.com.access_%Y%m%dlog 86400" combined below, and then save and exit the startup service.

Then the date-separated log file appears. Then change the system date here and see if the log file can be generated. Now the system time is October 10, 2019. Here, change the system time to October 20, 2019, and then restart the service.

Then a log file split on October 20, 2019 appears. This is achieved by Apache's own tool for log segmentation, and there is also a third-party software that can also split logs, that is, cronolog. Finally, a download link will be attached.

First, let's push the package to the mnt directory of the Linux system.

Then use the rpm-ivh cronolog-1.6.2-14.el7.x86_64.rpm command to install the package, and then look at the path to the command.

Then modify the configuration file for Apache. ErrorLog "| / usr/sbin/cronolog / var/log/httpd/abc.com.error_%Y%m%dlog" this is how the error log is written. CustomLog "| / usr/sbin/cronolog / var/log/httpd/abc.com.access_%Y%m%dlog" log is written. Note that the domain name should be changed to your own domain name.

Then delete all files under the log path and restart the service. Finally, the split file of the nursery rhyme log is also out, and both tools can achieve the same effect.

.

The above is all the contents of the article "how to split Apache logs". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Logs files services systems software this is writing domain name time path software package management configuration content commands tools failure date server article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB MySQL Xiaomi Shulou Tech Info