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

Log Management of Apache

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Main points of content:

Log Segmentation of apache

Apache log segmentation system

I. Log segmentation

1. As the number of visits to the website increases, the single log file of Apache will become larger and larger by default.

Log files take up a lot of disk space.

It is not convenient to view relevant information

2. Split the log files

Apache comes with rotatelogs, which is implemented by segmentation tool.

Third-party tool cronolog segmentation

2. Segmentation tools:

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

2. The configuration format is

| ErrorLog "| absolute path of the rotatelogs command-l log file path / website name-error% Y%m%d.log 86400" CustomLog "| rotatelogs command path-l log file path / website name-access% Y%m%d.log 86400" combined

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

[root@www ~] # vim / etc/httpd/conf/httpd.confErrorLog "| / usr/local/bin/rotatelogs-l/var/log/httpd/error% Y%m%d.log 86400" CustomLog "/ usr/local/bin/rotatelogs-1/var/log/httpd/access% Y%m%d.log 86400" combined [root@www ~] # systemctl restart httpd [root@www httpd] # II Total amount 80 RWLV-1 root root RTV-1 root root July 7 17:54 Access 20180707.10g Pwm error 20180707.log Pwi Tmuri-1 root root 584 July 7 17:55 error 20180707.log

Third, third-party tool cronolog

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 cronolog command log file path / website name-error_% Y%m%d.log" CustomLog "| absolute path of cronolog command log file path / site name _% log" combined

IV. Introduction of AWStats log analysis system

1. AWStats log analysis system

An open source log analysis system developed by Perl language

It can be used to analyze the access logs of Apache, Samba, Vsftpd, IIS and other servers.

Combined with crond and other scheduled task services, the log content can be analyzed regularly.

2. Install AWStats software package

[root@www ~] # tar zxf awstats-7.7.tar.gz [root@www ~] # mv awstats-7.7 / usr/local/awstats

3. Establish a configuration file for the site to be counted

[root@www ~] # cd / usr/local/awstats/tools/ [root@www tools] # chmod + x awstats_ roomre.pl. root @ www tools] #. / awstats_configure.pl.Config file path ('none' to skip web server setup): > / etc/httpd/conf/httpd.confDo you want me to build a new AWStats config/profilefile (required if first install) [y y.Your web site N]? y.Your web site, virtual server or profile name: > www.kgc.com

4. Modify the site statistics configuration file

[root@www tools] # vim / etc/awstats/awstats.www.kcce.com.confLogFile= "/ var/log/httpd/access log" DirData= "/ var/lib/awstats". / / omit part [root@www tools] # mkdir / var/lib/awstats

5. Perform log analysis and set up cron scheduling tasks

[root@www tools] # chmod + x awstats_ updateall.pl [root @ www tools] #. / awstats_updateall.pl now [root@www ~] # crontab-eBay systemctl enable crond 5 * / usr/local/awstats/tools/awstats_updateall.pl now [root@www ~] # systemctl start crond [root@www ~] # systemctl enable crond

Access to the AWStats analysis system

View the statistics page

Set the web page to jump automatically for easy access

[root@www ~] # vim / var/www/html/awb.html

Here are two experiments to configure apache log segmentation and log analysis system

Apache log segmentation

First, use rotatelogs, the segmentation tool that comes with apache, to set up the experimental environment, install httpd service, configure httpd service, and give the log files to rotatelogs segmentation.

[root@localhost named] # yum install-y httpd/ / install httpd service [root@localhost ~] # vim / etc/httpd/conf/httpd.conf / / configure httpd service

[root@localhost ~] # vim / etc/httpd/conf/httpd.conf / / configure httpd service ServerName Listen 192.168.64.158:80#Listen 80 / / configure service listening port and service name [root@localhost named] # systemctl start httpd.service / / start service [root@localhost named] # systemctl stop firewalld.service / / off Close the firewall [root@localhost named] # setenforce 0

[root@localhost ~] # vim / etc/httpd/conf/httpd.conf / / enter the configuration file and hand over the log file to rotatelogs for processing

Second, use the third-party tool cronolog to split, install httpd and install cronolog

[root@localhost ~] # mkdir / abc/ / create mount point [root@localhost ~] # mount.cifs / / 192.168.10.23/LAMP-C7 / abc/ mount package Password for root@//192.168.10.23/LAMP-C7: * [root@localhost ~] # cd abc/ [root@localhost abc] # rpm-ivh cronolog-1.6.2-14.el7.x86_64.rpm / / install cronolog

2. View the directory where the log files are located

[root@localhost bin] # cd / usr/bin [root@localhost bin] # ls cronolog*ls: cannot access cronolog*: without that file or directory [root@localhost bin] # cd / usr/sbin / / log directory generated in / usr/sbin directory [root@localhost sbin] # ls cronolog*cronolog

3. Modify the httpd service configuration file, add the listening port, add the service name, and give the log to cronolog for processing.

[root@localhost ~] # vim / etc/httpd/conf/httpd.confServerName www.kgc.com:80Listen 192.168.64.161:80ErrorLog "| / usr/sbin/cronolog logs/www.kgc.com.error_%Y%m%dlog" CustomLog "| / usr/sbin/cronolog logs/www.kgc.com.access_%Y%m%d.log" combined

4. Verify the configuration result, and the configuration is successful.

[root@localhost sbin] # systemctl restart httpd [root@localhost sbin] # ls / var/log/httpdwww.kgc.com.error_ 20191025 log [root @ localhost sbin] # date-s 10 Charger 26 October 192019 Saturday, 00:00:00 CST [root@localhost sbin] # systemctl restart httpd [root@localhost sbin] # ls / var/log/httpdwww.kgc.com.error_20191025log www.kgc.com.error_20191026log

Configure Log Analysis system experiment

Install the required software packages and configure the dns service

[root@localhost var] # yum install-y dhcp bind [root@localhost var] # vim / etc/named.conf / / configuration main configuration file [root@localhost ~] # vim / etc/named.rfc1912.zones / / configuration area profile zone "kgc.com" IN {type master; file "kgc.com.zone"; allow-update {none;} [root@localhost named] # cp-p named.localhost kgc.com.zone / / copy the zone data configuration template to kgc.com.zone [root@localhost ~] # cd / var/named/ [root@localhost named] # vim kgc.com.zone$TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.64.158 [root@localhost named] # systemctl start named / / start the service

2. Configure apache service, configure listening port, and dns service name

[root@localhost ~] # vim / etc/httpd/conf/httpd.conf / / enter Listen 192.168.64.158 Listen 80 / / configure listening port # Listen 80.... ServerName www.kgc.com:80 / / configure the service Name [root@localhost named] # systemctl stop firewalld.service [root@localhost named] # setenforce 0 / / close the firewall [root@localhost named] # systemctl start httpd / / start the httpd service

3. Install AWStart software package. Get from the shared folder of the host

[root@localhost httpd] # mkdir / abc [root@localhost httpd] # mount.cifs / / 192.168.100.3/rhe16 / abc / / Mount installation package Password for root@/ / 192.168.100.3/rhe16: [root@localhost LAMP] # tar zxvf awstats-7.6.tar.gz-C / opt/ decompression package [root@localhost tools] # / awstats_ configure.p1 / / configure the apache configuration file path and domain name [root@localhost ~] # vim / etc/httpd/conf/httpd.conf / / modify the access right [root@localhost conf] # vim / etc/awstats/awstats at the last line. / / modify the log directory where the listening log directory is httpd [root@localhost ~] # cd / var/lib [root@localhost ~] # mkdir awstats / / manually create the log saving path directory [root@localhost tools] # / awstats_ updateall.pl now / / update the data. It needs to be updated every time you check it.

4. Copy the link and verify the experimental results in win10.

5. Experimental optimization:

A. Update the data automatically through scheduled tasks to avoid manual data updates before each view.

B. Access link simplification

[root@localhost tools] # crontab-eSplash 5 * / usr/1ocal/awstats/too1s/awstats_ updateall.pl now / / Edit the scheduled task of automatically updating data every five minutes [root@localhost tools] # vim / var/www/html/aws.html / / create new website configuration information to simplify access to links

So the configuration is complete. For more apache optimizations, go to my home page to get

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

Network Security

Wechat

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

12
Report