Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to split logs in Apache

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report