-
These days, there are big differences in the statistical data of several different traffic statistics tools. At that time, I thought that I should analyze the access log of apache. The data there should be the most authoritative. At the beginning, I wrote a simple analysis tool for emergency purposes and collected some simple data. The open source Awstats should be a tool that is widely used and has complete functions.
The installation and configuration of Awstats are quite simple, but I still took some detours. The most painful lesson among them is: it is best to configure it in the default way. The following records my installation and configuration process. First explain the environment: 64-bit CentOS 5.6 + Apache Httpd 2.2
1. Configure Apache’s log output method.
By default, apache's access.log will be compressed when it reaches a certain size, and some old ones will also be deleted. I haven't found any relevant content about access log management in Apache's documentation. I hope that students who know it can give me some advice. Here I configure it to be one file per day for later analysis and backup. Open httpd.conf, find the location of the access log configuration, and change
CustomLog logs/access_log common
Change to
CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/access_log.%Y%m%d 86400" combined
Among them, rotatelogs is a log tool provided by Apache. You can find out the path of the tool through which rotatelogs. Another change is to change the content of the log from common to combined, so that the log contains more information, which is also needed by Awstats. If the log is configured in Virtual Hosts, just modify it in the same way.
After modifying and restarting the httpd service, you will see a log file similar to access_log.20110612 generated under /var/log/httpd.
2. Install Awstats
First download the Awstats installation package: awstats-7.0.tar.gz. You can also find the installation file suitable for your environment on the download page.
]# wget http://PRdownloads.sourceforge.net/awstats/awstats-7.0.tar.gz
]# tar xzvf awstats-7.0.tar.gz
]# mv awstats-7.0 /var/
You can install it according to the official guide of Awstats: http://awstats.sourceforge.net/docs/awstats_setup.html . There are a few points to note:
(1) When asking about the apache configuration file path, write the real apache configuration file path in the current environment. For example, mine is: /etc/httpd/conf/httpd.conf
(2) When asking for the path where the Awstats configuration file is stored, be sure to use the default path, otherwise there will be unexpected troubles later.
(3) When you want to create a new Awstats configuration file, you will be asked for the name of the configuration file. In fact, this time you are asking which domain name the log to be analyzed belongs to. For example, if your website is www.mysite.com , you can enter: www.mysite .com .
During the installation process, I kept saying yes all the way. At the end of the installation, a new directory awstats will be generated under /etc, and there will be a name named awstats.www.mysite.com.conf below.
This is when I opened httpd.conf again and found that there are some more configurations related to Awstats at the bottom.
Create a new file named awstats under /var/lib to store the data files generated after analyzing the log.
3. Configure Awstats
After the installation is complete, you still need to perform some simple configuration before you can start using Awstats. Open the configuration file awstats.www.mysite.com.conf generated above, find LogFile, and change it to the path of the actual log file. It should be noted that in the first step, the log file has been changed to a name named after the current day, so the configuration here is:
LogFile=/var/log/httpd/access_log.%YYYY-0%MM-%DD
Indicates that the latest log file is being analyzed. Regarding this configuration, please refer to the detailed explanation in its comments.
4. Verify installation
The configuration is basically completed, let’s verify it:
]# cd /var/awstats/wwwroot/cgi-bin
]# perl awstats.pl -config=www.mysite.com -update
If you follow the above steps strictly, there should be no problem in this step, and you can see output similar to the following:
Create/Update database for config "/etc/awstats/awstats.www.mysite.com.conf" by AWStats version 7.0 (build 1.971)
>From data in log file "/var/log/httpd/access_log.20110611"...
Phase 1: First bypass old records, searching new records...
Direct access after last parsed record (after line 545194)
Jumped lines in file: 545194
Found 545194 already parsed records.
Parsed lines in file: 1677
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 0 corrupted records,
Found 0 old records,
Found 1677 new qualified records.
For safety reasons, I did not open the update link on the web page, but configured the crontab to run the above program every 10 minutes:
*/10 * * * * root cd /var/awstats/wwwroot/cgi-bin/;perl awstats.pl -config=www.mysite.com -update
In this way, you can see the statistical results refreshed every 10 minutes on the page.
5. Install the plug-in for IP address conversion
Among the statistical reports of Awstats, one displays the actual address corresponding to the IP. This needs to be implemented through a plug-in. The more common method on the Internet is to use QQWry.dat. But it took a long time to find this plug-in, because many places can only download IP databases, not plug-ins.
The IP database can be downloaded through: http://www.cz88.net/fox/ipdat.shtml . Note: What is downloaded here is an ext installation file. After installation, there will be a qqwry.dat file, which is the IP database to be used. This IP database will be updated frequently, so we must also keep it updated.
Plug-in related files can be downloaded from: http://blogimg.chinaunix.net/blog/upfile/070103141422.rar (I don’t know when this URL will become invalid). After decompression, there are three files in it: qqhostinfo.pm, qqwry.pl and QQWry.Dat. The first is the plug-in file, the second is the real perl program that executes the conversion, and the third is the database. You can use the latest one above The database covers this. Copy these three files to the /var/awstats/wwwroot/cgi-bin/plugins/ directory and make the following modifications:
]# chmod 755 qqhostinfo.pm
]# vim qqwry.pl
Change ./QQWry.Dat to /var/awstats/wwwroot/cgi-bin/plugins/qqwry.dat.
Edit the Awstats configuration file awstats.www.mysite.com.conf and find
#LoadPlugin="hostinfo"
Add a new line after it
LoadPlugin="qqhostinfo"
After completing all the above steps, you should be able to see the statistical results on the web page. Chinese may be displayed as garbled characters, just set the browser language to Chinese.
(Source: CSDN Blog)