In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Apache log segmentation
As the number of visits to the website increases, the single log file of Apache becomes larger and larger by default.
● log files take up a lot of disk space.
It is not convenient for ● to view relevant information.
Split the log file
Implementation of ● Apache with rotatelogs Segmentation tool
● third Party tool cronolog Segmentation
Experimental environment
Step 1: install the Apache service
The rotatelogs tool is included with the Apache service, and it is in the / usr/sbin directory
[root@localhost ~] # yum install httpd-y [root@localhost ~] # cd / usr/sbin [root@localhost sbin] # ls rotate* / / search rotatelogs tool rotatelogs
Step 2: configure the DNS service
[root@localhost sbin] # vim / etc/httpd/conf/httpd.conf...Listen 192.168.235.129 Listen 80 / add listener address # Listen 80 / / comment out IPV6 snooping. ServerName www.bdqn.com:80 / / modify domain name [root@localhost httpd] # systemctl stop firewalld.service [root@localhost httpd] # setenforce 0 [root@localhost sbin] # systemctl Start httpd / / start the Apache service
Step 3: view the log file
1. First check to see if access_log and error_log are generated
[root@localhost sbin] # cd / var/log/httpd/ enter the log directory of Apache [root@localhost httpd] # lsaccess_log error_log//access_log is the access log and error_log is the error log
two。 Use the client to view the web page
First change the DNS service address of the client to the IP address of the server 192.168.235.129
Open the browser and enter the IP address of the server to access the web page.
Check the service log again
[root@localhost httpd] # cat access_log / / View access log 192.168.235.140-[25/Oct/2019:09:33:46 + 0800] "GET / HTTP/1.1" 403 4897 "-" Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729 Media Center PC 6.0) ". / / you can see the service records of clients with IP of 192.168.235.140. Because there are too many log files and are not easy to archive and retrieve, we can use the rotatelogs segmentation tool that comes with Apache.
Step 1: modify the main configuration file httpd.conf of Apache
[root@localhost httpd] # cd conf / / enter the conf directory [root@localhost conf] # vim httpd.conf / / Edit the httpd.conf file # ErrorLog "logs/error_log" / / comment out 182 lines ErrorLog "| / usr/sbin/rotatelogs-l logs/www.bdqn.com.error_%Y%m%dlog 86400" / / add this line entry at line 183 CustomLog "| / usr/sbin/rotatelogs-l logs/www.bdqn.com.error_%Y%m%dlog 86400" combined// modify the entry in line 218 to read / usr/sbin/rotatelogs-l logs/www.bdqn.com.error_%Y%m%dlog 86400 in quotation marks to [root@localhost conf] # systemctl stop httpd / / stop the service [root@localhost conf] # systemctl start httpd / / restart Service [root@localhost conf] # ls / var/log/httpd access_log error_log www.bdqn.com.error_20191025log// to view log directory You can see the generated www.bdqn.com.error_20191025log log file / / use the date-s command to modify the date to view [root@localhost httpd] # date-s 10Charger 26nd October 192019 Saturday, 00:00:00 CST [root@localhost httpd] # systemctl stop httpd [root@localhost httpd] # systemctl start httpd [root@localhost httpd] # ls / var/log/httpdaccess_log www.bdqn.com.error_20191025logerror_log www.bdqn.com.error_20191026log
We can also use third-party cronolog tools for log segmentation
Environment preparation: cronolog toolkit sharing address (no password):
Https://pan.baidu.com/s/16kyAuOcocRWJKXyXfSVsLg
1. Share toolkits to Linux
[root@localhost ~] # smbclient-L / / 192.168.10.37 / / remote sharing Sharename Type Comment-ADMIN$ Disk remote management C$ Disk default share D$ Disk default share IPC$ IPC remote IPC LAMP Disk [root@localhost ~] # mount.cifs / / 192.168.10.37/LAMP/ / opt/// mounts the downloaded tool folder [root@localhost ~] # cd / opt [root@localhost opt] # rpm-ivh cronolog-1.6.2-14.el7.x86_64.rpm / / installation kit [root@localhost opt] # cd / usr/sbin / / enter the sbin directory [root@localhost sbin] # ls crono* / / to see if there is a cronolog file cronolog
two。 Modify the configuration file of httpd
[root@localhost sbin] # vim / etc/httpd/conf/httpd.confErrorLog "| / usr/sbin/cronolog logs/www.bdqn.com.error_%Y%m%d.log" / / replace the quotation marks of the entry in line 182 with | / usr/sbin/cronolog logs/www.bdqn.com.error_%Y%m%d.log to CustomLog "| / usr/sbin/cronolog logs/www.bdqn.com.access_%Y%m%d.log" combined// Replace the contents in the quotation marks of the entry in line 217 with | / usr/sbin/cronolog logs/www.bdqn.com.access_%Y%m%d.log
3. View log files
[root@localhost sbin] # systemctl start httpd/ / startup service [root@localhost sbin] # ls / var/log/httpd/ View the log directory to view the generated log files www.bdqn.com.error_20191025.log above are all the contents of our Apache log segmentation. Thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.