Apache Log Management and statistical analysis knowledge _linux

Source: Internet
Author: User
Tags apache log
For all companies or ICP, in the guarantee of stable normal operation of the site, but also need to understand the site visits and analysis of reports, which for understanding and monitoring the operation of the site, for the improvement of the site's service capabilities and service level seems essential. By analyzing and statistics the log files of Web server, it can effectively master the situation of system operation and the visit of site content, and strengthen the maintenance and management of the whole station and its content;

The Apache server has the powerful log function, the administrator may be convenient, prepares, the timely understanding server condition, can guard against Hacker's attack better.

Apache provides 4 types of logs: error log, access log, transfer log, and cookie log. The error log and access log are set by default in Apache2.0, and if additional logs need to be analyzed, the related configuration is required.

1. Error log

The error log is the standard log file for the Apache server, which records the various errors encountered during the server's run and when some servers started.

In this file, the administrator can accurately and clearly see the various error prompts: File not found, user authentication errors or PHP, CGI syntax errors. With these accurate descriptions of errors, administrators can solve these problems more smoothly.

2. Configure Access Log

Apache access logs can be used to understand the information about access to the server, such as who has access to the server, what they have access to, and other relevant information. The Apache server will automatically generate access logs once it is started (/var/log/httpd/access_log file)

Managing Web sites requires monitoring their speed, Web content delivery, server throughput per day, and external access to Web sites to understand the pages of the site
To improve the content and quality of the page, to improve the readability of the content, to track the steps involved in business transactions, and to manage the data behind the Web site.

1, the classification of the log
The Apache standard provides 4 types of logs;
* ERROR Log
* Access Log
* Transfer Log
*cookie Log
Where the transfer log and the cookie log were canceled at apache2.0, only error logs and access logs were discussed;
2, log-related configuration instructions;
The following 4 log-related configuration directives are available in Apache;
Instruction Format Description
-----------------------------------------------------------------------------
ErrorLog error log file name; Specify error log storage path
-----------------------------------------------------------------------------
LogLevel error log record level; Specify the record level of the error log
-----------------------------------------------------------------------------
Logformat record Format description string, format nickname; Name a log record format
-------------------------------------------------------------------------------
Customlog access log filename format nickname specifies access log storage path and record format;
"| program name access log filename" format nickname specify access log has the specified program build and format (pipe log)
-------------------------------------------------------------------------------
The first two are configuration error logs, and the last two are configuration access logs
3, configuration error log;
1), Apache default error log Configuration
ErrorLog "Logs/error_log"
LogLevel warn
The configuration error log only needs to explain the log file path and log record registration;
2), logging level;

Degree of urgency level description
-----------------------------------------------------------------
1 Emerg system is not available when emergency occurs, such as system downtime, etc.
------------------------------------------------------------------
2 A Lert need immediate attention
------------------------------------------------------------------
3 Crit warning of dangerous situation
-----------------------------------------------------------------
4 error other than Emerg, alert, crit;
--------------------------------------------------------------
5 Warn warning message
---------------------------------------------------------------
6 notice need to draw attention to the situation, but not as important as the error warn
------------------------------------------------------------------
7 Info worth Reporting general information
-------------------------------------------------------------------
8 debug messages generated by programs running with debug mode
---------------------------------------------------------------

If a registration warn is specified, all information of an emergency level of 1 to 5 is recorded;

[Fri May 07 10:32:00 2010] [ERROR] [Client 192.168.0.10] File does not exist:/usr/local/apache2/htdocs/favicon.ico
[Fri May 07 10:32:03 2010] [ERROR] [Client 192.168.0.10] File does not exist:/usr/local/apache2/htdocs/favicon.ico

The error log for each row has
Date and time error level error message

4. Configure access Log
1), access to the log classification;
To facilitate the analysis of Apache access logs, the apace's default profile is divided into 4 categories by record information, and the Logformat directive defines a nickname
Format Categories format NicknameDescription
--------------------------------------------------------------------
Normal log format CommonMost log analysis software supports this format
(Common log format.) CLF)
--------------------------------------------------------------------
Reference log Format Referer   Record the user identity of the customer's access site
(referer log format)
--------------------------------------------------------------------
Agent Log Format AgentRecord the requested user agent
(Agent log format)
--------------------------------------------------------------------
Integrated log Format combinedCombined with the above three kinds of log information
(combined log format)
--------------------------------------------------------------------
Because the composite log format combines 3 kinds of log information simply, when configuring an access log, either 3 files are logged separately or a single consolidated file record is used.
5, log scrolling
To enable the system to reuse an empty log file, you can execute the following command
#cd/usr/loca/apache2/log
# MV Error_log error_log.01
#mv Access_log access_log.01
When you restart Apache's error_log and Access_log
Below we use log analysis software Webalizer to Count
1), Installation Webalizer
# yum Install Webalizer
# Rpm-qa |grep Webalizer
webalizer-2.01_10-30.1
# Rpm-qa |grep Webalizer
webalizer-2.01_10-30.1
[Root@dns logs]# RPM-QL Webalizer
/etc/cron.daily/00webalizer
/etc/httpd/conf.d/webalizer.conf
/etc/webalizer.conf
/usr/bin/webalizer
/usr/bin/webazolver
/usr/share/doc/webalizer-2.01_10
/usr/share/doc/webalizer-2.01_10/readme
/usr/share/man/man1/webalizer.1.gz
/var/lib/webalizer
* The generated HTML file is stored in the following path
/var/www/usage
/var/www/usage/msfree.png
/var/www/usage/webalizer.png

2), Configuration Webalizer
#ln-S/var/www/usage/usr/local/www/usage
# Webalizer/usr/local/apache2/logs/access_log
Http://ip/usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.