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

Apache log segmentation experiment

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains the "Apache log segmentation experiment", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn the "Apache log segmentation experiment"!

Log segmentation

As the number of visits to the website increases, the single log file for Apache becomes larger and larger by default.

Log files take up a lot of disk space.

It is not convenient to view relevant information.

Split the log file

Apache has its own rotatelogs segmentation tool.

Third-party tool cronolog segmentation

Rotatelogs Segmentation tool

Configure the log files of the website to be transferred to rotatelogs split processing

[root@www ~] # vim / etc/httpd/conf/httpd.conf

ErrorLog "/ usr/local/bin/rotatelogs-|

/ var/log/httpd/error Y%m%d.log 86400 "

CustomLog "| / usr/local/bin/rotatelogs-|

/ var/log/httpd/access% Y%m%d.log 86400 "combined

[root@www ~] # systemctl restart httpd

[root@www httpd] # II

Total dosage 80

-rW-r--r-- 1 root root 1814 July 7 17:54 access 201 80707.log

-rW-r--r-- 1 root root 584 July 7 17:55 error 201 80707.l0g configuration format is

"ErrorLog" | absolute path of rotatelogs command-| Log file path / website name-

Error%Y%m%d.log 86400 "

CustomLog "| rotatelogs command path-| Log file path / website name-

Access\% Y%m%d.log 86400 "combined

Source code compilation and installation of cronolog tools

Configure site log files to be transferred to cronolog split processing

The configuration format is:

"ErrorLog" | absolute path of the cronolog command, log file path / website name-

Error_ Y%m%d.log "

"CustomLog" | absolute path of cronolog command log file path / website name

Y m%d.log "combined

Log segmentation experiment Apache comes with the log separation tool rotatelogs1. Install the Apache service

[root@localhost ~] # yum install httpd-y / / install the httpd service

[root@localhost ~] # cd / usr/sbin / / switch to / usr/sbin directory

[root@localhost sbin] # ls rotat* / / location of log analysis tool

Rotatelogs

[root@localhost sbin] # vim / etc/httpd/conf/httpd.conf / / enter and modify the Apache configuration file

Listen 192.168.131.129 80 # # modify the ipv4 listening address to the local address

# Listen 80 / / annotate ipv6 port

ServerName www.kgc.com:80 / / modify domain name

[root@localhost named] # systemctl stop firewalld.service / / turn off the firewall

[root@localhost named] # setenforce 0 / / turn off enhanced security features

[root@localhost html] # systemctl start httpd.service / / start the network service

[root@localhost sbin] # ls / var/log/httpd/ Log files have been available since the start of the service

Accesslog errorlog

Configure the http main configuration file

[root@localhost sbin] # vim / etc/httpd/conf/httpd.conf / / enter and modify the Apache configuration file

# ErrorLog "logs/errorlog"

ErrorLog "| / usr/sbin/rotatelogs-l logs/www.kgc.com.error%Y%m%dlog 86400"

/ / add the absolute path of the tool here, and the time when the log is generated

CustomLog "| / usr/sbin/rotatelogs-l logs/www.kgc.com.access_%Y%m%dlog 86400" combined

/ / add the absolute path of the tool here, and the time when the log is generated

Restart the service to check the log segmentation

[root@localhost conf] # systemctl stop httpd.service / / disable the http service

[root@localhost conf] # systemctl start httpd / / start the http service

[root@localhost conf] # cd / var/log/httpd/ switch to log directory to view

[root@localhost httpd] # ls

Access_log error_log www.kgc.com.error_20191026log / / Today's log file

[root@localhost httpd] # date

Saturday, October 26, 2019, 10:26:24 CST

[root@localhost httpd] # date-s 10-26-19 / / modified to the next day

Sunday, October 27th, 2019, 00:00:00 CST

[root@localhost httpd] # systemctl stop httpd / / restart the service

[root@localhost httpd] # systemctl start httpd

[root@localhost httpd] # ls / / View log segmentation

Access_log www.kgc.com.error_20191026log

Error_log www.kgc.com.error_20191027log

Use third-party tools cronolog1, install http services, and remotely mount third-party tools

[root@localhost ~] # mount.cifs / / 192.168.10.88/LAMP-C7 / mnt

/ / remotely mount the package to the local / mnt directory

[root@localhost ~] # cd / mnt/ switch to / mnt directory

[root@localhost mnt] # ls

Apr-1.6.2.tar.gz cronolog-1.6.2-14.el7.x86_64.rpm LAMP-php5.6.txt

Apr-util-1.6.0.tar.gz Discuz_X2.5_SC_UTF8.zip mysql-5.6.26.tar.gz

Awstats-7.6.tar.gz httpd-2.4.29.tar.bz2 php-5.6.11.tar.bz2

[root@localhost mnt] # rpm-ivh cronolog-1.6.2-14.el7.x86_64.rpm / / installation tool

2. View the tool and modify the http configuration file

[root@localhost mnt] # cd / usr/sbin

[root@localhost sbin] # ls cronolog*

Cronolog

[root@localhost sbin] # vim / etc/httpd/conf/httpd.conf

Listen 192.168.13.128 Listen 80 / / modify the address of the listener to the local address

# Listen 80 / / Note ipv6 listening port

ServerName www.kgc.com:80 / / modify domain name

ErrorLog "| / usr/sbin/cronolog logs/www.kgc.com.error%Y%m%d.log"

CustomLog "| / usr/sbin/cronolog logs/www.kgc.com.access%Y%m%d.log" combined

/ / modify the log file

3. Restart the service and view the log file

[root@localhost sbin] # systemctl restart httpd # # restart the http service

[root@localhost sbin] # ls / var/log/httpd # # View log files

Www.kgc.com.error_20191026.log

Thank you for your reading, the above is the content of the "Apache log segmentation experiment", after the study of this article, I believe you have a deeper understanding of the Apache log segmentation experiment, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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