相关软件及下载地址:
1、 cronolog-1.6.2.tar.gz
2、 awstats-6.95.tar.gz
3、 GeoIP-1.4.6.tar.gz
4、 Geo-IP-1.38.tar.gz
5、 Net-XWhois-0.90.tar.gz
6、 QQWry.Dat
7、 IP解析插件
软件说明:
Cronolog -apache日志分割
Awstats –apace日志分析主程序
GeoIP –IP地址分析,来至某个国家并显示国旗
Xwhois及后面 –IP反向解析
详细安装过程:
一、安装cronolog日志分割软件:
[root@saas soft]# tar zxvf cronolog-1.6.2.tar.gz
[root@saas cronolog-1.6.2]# ./configure &&make &&make install
[root@saas cronolog-1.6.2]# which cronolog
/usr/local/sbin/cronolog
修改httpd.conf文件
<VirtualHost *>
ServerName www.test.cn
DocumentRoot “/opt/lampp/htdocs/newtest”
CustomLog “|/usr/local/sbin/cronolog /opt/lampp/logs/test_%Y%m%d.log” combined
ErrorLog “|/usr/local/sbin/cronolog /opt/lampp/logs/test_error_%Y%m%d.log”
</VirtualHost>
|
重启apache后在/opt/lampp/logs/目录下可以看到以下格式日志:
-rw-r–r– 1 root root 12021 6月 25 15:01 test_20100625.log
-rw-r–r– 1 root root 718 6月 25 15:00 test_error_20100625.log
|
日志分割比较简单。。至此就安装完成了。。。以后每天都会在该目录下生成当日的日志文件。
二、安装awstats主程序
[root@saas local]# tar zxvf awstats-6.95.tar.gz -C /usr/local/
[root@saas local]# mv awstats-6.95/ awstats
[root@saas local]# mkdir /etc/awstats
[root@saas local]# mkdir /var/lib/awstats
[root@saas local]# chown -R apache /var/lib/awstats/
[root@saas local]# chown -R apache /usr/local/awstats/
[root@saas local]# /usr/local/awstats/tools/awstats_configure.pl
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path (‘none’ to skip web server setup):
Ø /opt/lampp/etc/httpd.conf #http.conf文件路径
—–> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y
—–> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
Ø www.test.cn
#生成配置文件的名字
—–> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>配置文件放置地址 默认即可
—–> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.cn
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue…
回车继续
A SIMPLE config file has been created: /etc/awstats/awstats.www.test.cn.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘www.test.cn’ with command:
> perl awstats.pl -update -config=www.test.cn
You can also read your statistics for ‘www.test.cn’ with URL:
> http://localhost/awstats/awstats.pl?config=www.test.cn
Press ENTER to finish…
回车结束
|
Configure.pl配置文件,会将:
CustomLog ……………………..common
改为
CustomLog ……………………..combined #实际上面我们已经更改过来,日志切割的时候
会在apache中增加如下内容:
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/”
<Directory “/usr/local/awstats/wwwroot”>
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
|
当然你也有可能会发现httpd.conf文件会变成这个样子:(每句后面会多出^M)
# Do NOT simply read the instructions in here without understanding^M
# what they do. They’re here only as hints or reminders. If you are unsure^M
# consult the online docs. You have been warned. ^M
#^M
# Configuration and logfile names: If the filenames you specify for many^M
# of the server’s control files begin with “/” (or “drive:/” for Win32), the^M
# server will use that explicit path. If the filenames do *not* begin^M
# with “/”, the value of ServerRoot is prepended — so “logs/foo.log”^M
# with ServerRoot set to “/opt/lampp” will be interpreted by the^M
# server as “/opt/lampp/logs/foo.log”.^M
^M
#^M
|
使用dos2unix命令转换下格式:
[root@saas tools]# file /opt/lampp/etc/httpd.conf
/opt/lampp/etc/httpd.conf: ASCII English text, with CRLF, LF line terminators
[root@saas tools]# dos2unix /opt/lampp/etc/httpd.conf
dos2unix: converting file /opt/lampp/etc/httpd.conf to UNIX format …
[root@saas tools]# file /opt/lampp/etc/httpd.conf
/opt/lampp/etc/httpd.conf: ASCII English text
|
生成的配置文件,配置文件中大概要修改的如下:/etc/awstats/awstats
LogFile=”apache日志文件
DirData=”/var/lib/awstats”
DirCgi=”/awstats”
AllowToUpdateStatsFromBrowser=1
|
注:由于前面我们使用过了日志分割,固每日的日志都会跟上日期。所以在LogFile处可以写定一个日志文件名称如:”/opt/lamp/logs/Test_acc.log” 。每日凌晨的时候利用脚本将其前日的日志复制覆盖掉此文件再做分析。
现为了测试,先将今日的日志先复制一份命名为”Test_acc.log”
更新数据并测试awstats是否网页访问OK
[root@saas ~]# usr/local/awstats/tools/awstats_updateall.pl now
Running
‘”/usr/local/awstats/wwwroot/cgi-bin/awstats.pl” -update
-config=www.test.cn -configdir=”/etc/awstats”‘ to update config
www.test.cn
Create/Update database for config “/etc/awstats/awstats.www.test.cn.conf” by AWStats version 6.95 (build 1.943)
From data in log file “/opt/lampp/logs/test_acc.log”…
Phase 1 : First bypass old records, searching new record…
Direct access after last parsed record (after line 880)
Jumped lines in file: 880
Found 880 already parsed records.
Parsed lines in file: 0
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
|
使用浏览器,察看日志统计情况:http://域名/awstats/awstats.pl?config=配置文件名。。
实例如下:
http://www.test.cn/awstats/awstats.pl?config=www.test.cn
如提示:Forbidden You don’t have permission to access /awstats/awstats.pl on this server.错误。
1、 请确认/usr/local/awstats目录权限
[root@saas ~]# chmod -R 755 /usr/local/awstats
|
2、 检测httpd.conf文件是否应用支持CGI。。改httpd.conf为如下:
[root@OAServer ~]# tail /opt/lampp/etc/httpd.conf
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory “/usr/local/awstats/wwwroot”>
Options FollowSymLinks +ExecCGI
AddHandler cgi-script .pl
AllowOverride None
Order allow,deny
Allow from all
</Directory>
|
三、插件安装:
1、 GeoIP-1.4.6.tar.gz安装
[root@saas soft]# tar zxvf GeoIP-1.4.6.tar.gz
[root@saas GeoIP-1.4.6]#./configure &&make &&make install
|
2、 Geo-IP-1.38.tar.gz安装
[root@saas soft]# tar zxvf Geo-IP-1.38.tar.gz
[root@saas Geo-IP-1.38]# perl Makefile.PL &&make &&make install
[root@saas Geo-IP-1.38]# /usr/local/bin/geoipupdate -v
|
安装好Geoip插件后,在配置文件中启用插件:
[root@saas soft]# grep “geoip ” /etc/awstats/awstats.www.test.cn.conf
# geoip or geoipfree plugin instead of enabled reverse DNS lookup.
LoadPlugin=”geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat” #取消掉本行注释
|
在web页面就能看到如下红色标注部分及国旗了。。
主机 : 0 个解译成功, 763 无法得知(不能反解网域名称)
639 参观者
|
GeoIP
Country
|
网页数
|
文件数
|
字节
|
最近参观日期
|
121.56.215.145
|
China
|
205
|
1070
|
12.29 M字节
|
2010年06月27日 13:41
|
123.179.199.146
|
China
|
108
|
636
|
51.03 M字节
|
2010年06月27日 03:45
|
110.84.174.240
|
Australia
|
105
|
478
|
19.08 M字节
|
2010年06月27日 05:48
|
118.124.2.212
|
China
|
102
|
511
|
71.00 M字节
|
2010年06月27日 16:53
|
|
|
国家或地区
|
网页数
|
文件数
|
字节
|
|
|
China
|
cn
|
4444
|
39202
|
1.83 G字节
|
|
|
Australia
|
au
|
311
|
2174
|
109.83 M字节
|
|
|
|
|
|
|
|
|
|
3、Net-XWhois-0.90.tar.gz 安装(反向地址解析)
[root@saas soft]# tar zxvf Net-XWhois-0.90.tar.gz
[root@saas Net-XWhois-0.90]# perl Makefile.PL &&make &&make install
|
改qqwry.pl文件中
my $ipfile=”./QQWry.Dat”;
为
my $ipfile=”${DIR}/plugins/QQWry.Dat”;
|
复制 QQWry.Dat, qqhostinfo.pm, qqwry.pl 等3个文件到 awstats/wwwroot/cgibin/plugins 下面。并授权755
[root@saas soft]# cp qqhostinfo.pm QQWry.Dat qqwry.pl \
>/usr/local/awstats/wwwroot/cgi-bin/plugins/
[root@saas soft]#chmod 755 /usr/local/awstats/wwwroot/cgi-bin/plugins/*
|
修改配置文件中LoadPlugin如下:
LoadPlugin=”qqhostinfo”
顺带启用以下插件:
LoadPlugin=”tooltips”
LoadPlugin=”decodeutfkeys” #解决搜索关键字乱码问题
|
一切OK后。重新刷新下WEB查看页面。可以看到如下:
主机 : 0 个解译成功, 763 无法得知(不能反解网域名称)
639 参观者
|
GeoIP
Country
|
Location
|
网页数
|
文件数
|
字节
|
最近参观日期
|
121.56.215.145
|
China
|
内蒙古兴安盟 电信
|
205
|
1070
|
12.29 M字节
|
2010年06月27日 13:41
|
123.179.199.146
|
China
|
内蒙古赤峰市 电信
|
108
|
636
|
51.03 M字节
|
2010年06月27日 03:45
|
110.84.174.240
|
Australia
|
福建省福州市 电信
|
105
|
478
|
19.08 M字节
|
2010年06月27日 05:48
|
在页面的最下面可以看到已经启用的插件:
Advanced Web Statistics 6.95 (build 1.943) -
创建者 awstats (插件: qqhostinfo, geoip, decodeutfkeys, tooltips)
|
四、编写简单脚本。并设置定时执行
[root@saas soft]#cat /opt/lampp/logs/awstats.sh
#!/bin/bash
logdir=/opt/lampp/logs
date=`date +%Y%m%d -d “-1 days”`
rmdate=`date +%Y%m%d -d “-7 days”`
\cp $logdir/ksense.com.cn_$date.log $logdir/Test_acc.log
rm -rf $logdir/*_$rmdate.log
/usr/local/awstats/tools/awstats_updateall.pl now
[root@saas soft]]# crontab -l
01 01 * * * /opt/lampp/logs/awstatus.sh #每晚一点处理前一天的日志文件
|
五、关于安全。网上很多都提倡使用密码认证的方式。。我做得比较简单
<Directory “/usr/local/awstats/wwwroot”>
Options FollowSymLinks +ExecCGI
AddHandler cgi-script .pl
AllowOverride None
Order allow,deny
Allow from 192.168.0.12 #只允许本IP访问此页面
</Directory>
|
分享到:
相关推荐
apache日志分割
apache日志分割工具cronolog,本文将以cronolog 1.6.2、apache 2.2.6为例,以CentOS 5为平台,讲述cronolog的安装和设置。
终极解决apache乱码和日志分割问题,LoadModule encoding_module modules/mod_encoding.so Header add MS-Author-Via "DAV" </IfModule>
Linux tomcat下catalina.out日志文件分割 前言: tomcat默认使用Java.util.logging记录日志,默认只记录tomcat的日志,不记录应用的日志。tomcat支持采用log4j进行日志记录,配置方法如下: 1.更新最新的tomcat_juli...
由于以前经常用IIS配置网站,所以现在突然改成使用Apache会有很大的不适应和遇到一些从没见过的困难,相信很多朋友也一样有这个苦恼,于是在各搜索引擎找解决办法。因为自己的经验不足,经常被搜索出来的一些经验所...
本文介绍了apache使用自带的日志分割模块rotatelogs分割日志,rotatelogs 是 Apache 2.2 中自带的管道日志程序,具体使用方法请参考下
一、apache优化之保持连接、网页传输压缩、页面缓存时间; 二、apache优化隐藏版本号; 三、apache优化之防盗链; 四、apache的ab压力测试;...七、apache优化之日志分割; 八、apache实现虚拟主机;
已经封装好,把log4j.appender.fileout=org.apache.log4j.Log4JDateAndSizeSplit 即可,其余和原api一样: log4j.appender.fileout.MaxFileSize=10240KB log4j.appender.fileout.MaxBackupIndex=20
二、apache优化隐藏版本号 三、apache优化之防盗链 五、apache 日志分析工具 六、apache访问控制 七、apache优化之日志分割 八、ap
本文档就IIS、Apache、Tomcat常见Web服务下的日志切割及发布进行说 明。
本文实例为大家分享了python实现日志按天分割的具体代码,供大家参考,具体内容如下 日志格式: 1.1.1.1 – – [30/Apr/2015:00:34:55 +0800] “POST /iDataService/services/MemRoomService HTTP/1.0” 200 405 ...
0:218M日志文件,分析时间为29.147秒,(主要慢在超级列表框,查询IP归属地,读取文件) 1:使用纯真IP数据库查询用户IP归属地 2:鉴定是否为爬虫(非简单查询UA,而是根据行为鉴定) 3:健康评估(根据正常页面,404页面,计算...
zlog+cronolog.tar zlog 是一个可靠、高性能、线程安全、灵活、清晰的模型,纯C日志库。 cronolog 是一个简单的过滤程序,...cronolog 旨在和一个Web服务器一起使用,如Apache,分割访问日志为每天或每月的日志。
tomcat cronolog 日志分割工具,cronolog 是一个简单的过滤程序,读取日志文件条目从标准输入和输出的每个条目并写入指定的日志文件的文件名模板和当前的日期和时间。当扩展文件名的变化,目前的文件是关闭,新开辟的...
代码如下:cut -d- -f 1 /usr/local/apache2/logs/access_log |uniq -c | sort -rn | head -20 原理: 代码如下: cut -d, –delimiter=DELIM use DELIM instead of TAB for field delimiter 表示用-分割,...
AWStats是使用Perl语言开发的一款开源日志分析系统,cronolog是日志分割软件
AWStats是使用Perl语言开发的一款开源日志分析系统,cronolog是日志分割软件
切割apache日志中catalina.out文件,将这个文件根据日期来分割,将每天生成的日志存放在一个独立的文件中。使用教程:https://blog.csdn.net/H2520NY/article/details/79957513
7、集成网页加密等实用工具,不同PHP版本配置区分,日志分割处理等多种实用功能。 8、多功能站点管理,自动定时重启服务器,自动定时重启Apache、mysql等相关服务。 其他功能自行摸索,很简单的可视化界面。...