Apache
Apache Server Log Analysis application example
Rhinux Posted: 2004-11-28 22:11
The rapid development of the Internet, whether it is a traditional enterprise website, or Internet enterprises, in order to understand their own customer sources, CTR and other information, the analysis of the site log is particularly important, the following I do the log analysis system to share with you, I hope to be helpful.
Welcome to copy, but please keep the integrity of this article, thank you!!
One, the software and tools used
1,apache Server Official website: http://www.apache.org
2,awstats Log Analysis Software official website: http://awstats.sourceforge.net/
3,cronolog log Interception Software official website: http://www.cronolog.org
Second, the environmental framework
1,redhat as 3
2,apache
./configure–prefix=/usr/local/apache2/--enable-so
Make
Make install
3, Awstats
Direct tar to/usr/local/awstats
4,cronolog
./configure–prefix=/usr/local/cronolog
Make
Make install
Three, configure
1, Apache
A, let a virtual host in Apache generate the log:
Global environment variable settings:
Code:
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined
Setenvif Request_uri \.gif$ Gif-image
Setenvif request_uri \. gif$ Gif-image
Setenvif Request_uri \.jpg$ Gif-image
Setenvif request_uri \. jpg$ Gif-image
Setenvif Request_uri \.png$ Gif-image
Setenvif Request_uri \.swf$ Gif-image
Setenvif request_uri \. swf$ Gif-image
Setenvif Request_uri \.css$ Gif-image
Setenvif request_uri \. css$ Gif-image
Setenvif Request_uri \.js$ Gif-image
Setenvif request_uri \. js$ Gif-image
Setenvif Request_uri \.ico$ Gif-image
Generate logs but do not include pictures.
Virtual Host Log Settings
Code:
ServerAdmin webmaster@abc.net
Documentroot/db/htdocs/www
ServerName www.abc.net
Customlog "|/usr/local/cronolog/sbin/cronolog/db/logs/www.%y-%m-%d.log" combined Env=!gif-image
Apache log files by date #用cronolog截取存放在/db/logs/
Note: Log files are generated for each virtual host so you can configure log analysis for multiple virtual hosts on a single server
B, alias settings
Code:
#
# directives to allow use of AWStats as a CGI
#
Alias/awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias/awstatscss "/usr/local/awstats/wwwroot/css/"
Alias/awstatsicons "/usr/local/awstats/wwwroot/icon/"
scriptalias/awstats/"/usr/local/awstats/wwwroot/cgi-bin/"
#
# This is the to permit URL for access to Scripts/files in AWStats directory.
#
Options None
AllowOverride None
Order Allow,deny
Allow from all
This configuration is automatically generated after running awstats/tools/awstats_configure.pl so you do not have to add it manually.
C,awstats requires CGI support if not added CGI can now be added
Code:
./apxs-c-I/USR/LOCAL/SRC/HTTPD-2.0.50/MODULES/GENERATORS/MOD_CGI.C
and add it to the httpd.conf.
Code:
LoadModule Cgi_module modules/mod_cgi.so
D in order to protect log statistics requires authentication settings for certain directories, support for authentication modules is required
Code:
./apxs-c-I/USR/LOCAL/SRC/HTTPD-2.0.50/..../MOD_AUTH.C
and add it to the httpd.conf.
Code:
LoadModule Auth_module modules/mod_auth.so
To configure a directory that requires authentication:
Code:
AuthType Basic
AuthName "Restricted Files"
Authuserfile/usr/local/apache2/passwd/passwords
Require User LogUser
Where the passwords password file is generated under/usr/local/apache2/passwd/
Run the following code to generate the user named LogUser User and their password
Code:
/usr/local/apache2/bin/htpasswd-c/usr/local/apache2/passwd/passwords LogUser
Note: The passwd directory must be built under/usr/local/apache2/
2,awstats
Run/usr/local/awstats/tools/awstats_configure.pl
The main setting is the name of the hostname that needs to be entered for statistics such as: www.abc.net
Then modify the default location of the Awstats configuration file that was just configured to be generated:
/etc/awstats/awstats.www.abc.net.con main do specify log position
Code:
Logfile= "/db/logs/www.%yyyy-4-%mm-2-%dd-2.log"
Create directory: mkdir/var/lib/awstats/
Perform:
Code:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl-update-config=www.abc.net
Update, you can enter http://www.abc.net/awstats/awstats.pl to access it in the browser after update.
3,cronolog (basic without any modification)
Modification of 4,crontab
Add the following command to the crontab to ensure a 15-minute update, or you can modify the update interval according to your own needs
Code:
*/15 * * * */usr/local/awstats/wwwroot/cgi-bin/awstats.pl-update-config=www.abc.net
Four, security considerations
1, the above settings due to CGI support, but also increased security risks can be used awstats awstats_buildstaticpages.pl to generate static pages can be added to Crontab
Code:
*/15 * * * */usr/local/awstats/tools/awstats_buildstaticpages.pl-update-config=www.abc.net-lang=cn-dir=/db/htdocs/ www/awstat/-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
It won't be 15 minutes. Generate various static pages under/db/htdocs/www/awstat/
2, protect/db/htdocs/www/awstat/prohibit unauthorized user access
Add in httpd.conf
Code:
AuthType Basic
AuthName "Restricted Files"
Authuserfile/usr/local/apache2/passwd/passwords
Require User LogUser
If the www.abc.net virtual host home directory is/db/htdocs/www/, enter http://www.abc.net/awstat/awstats.www.abc.net.html in the browser to access the static page carefully
3, if you use a static page, do not forget to comment out
LoadModule Cgi_module modules/mod_cgi.so
Five, dedicated to my favorite flying fly.
Six, because I am a beginner, this article slightly rough, if there are any guidance and questions welcome and I contact, we communicate with each other improve: hoash2003@hotmail.com
Welcome to copy, but please keep the integrity of this article, thank you!!