日志分析软件awstats的安装使用指南

1. 下载地址

    http://sourceforge.net/projects/awstats/  
    
    http://voxel.dl.sourceforge.net/sourceforge/awstats/awstats-6.4-1.noarch.rpm
2. 安装    
    2.1 rpm安装

[root@web tools]# rpm -ivh awstats-6.4-1.noarch.rpm  
Preparing...                 ########################################### [100%]
    1:awstats                 ########################################### [100%]

----- AWStats 6.4 - Laurent Destailleur -----
AWStats files have been installed in /usr/local/awstats

If first install, follow instructions in documentation
(/usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
Step 1 : Install and Setup with awstats_configure.pl (or manually)
Step 2 : Build/Update Statistics with awstats.pl
Step 3 : Read Statistics
    
    2.2 tar包安装
    
        直接解压就行了,因为awstats是由perl编写的。其实都一样。
        
3. 运行配置脚本生成awstats的配置文件
    cd /usr/local/awstats/tools
    perl awstats_configure.pl  
    配置脚本询问域名等问题,假设回答的域名为www.abcd.com
    3.1 生成的配置文件会放在/etc/awstats/下面
    3.2 生成的配置文件的名称为awstats.www.adcd.com.conf
    3.3 配置脚本只能修改主要的log日志为combined,如果设置了虚拟主机,需要分别修改虚拟主机中的日志配置。
        格式设置 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
         自定义的日志采用什么格式 CustomLog logs/testmysite-access_log combined
         创建日志 TransferLog logs/testmysite-access_log
         
4. 编辑awstats.www.abcd.com.conf,保证awstats的正常运行

    4.1 设置web server的logfile位置
        编辑LogFile为web server的log文件位置
        LogFile=/usr/local/apache2/logs/abcd-access_log
        一定保证和httpd.conf中的log文件保证一致,httpd.conf中log名称为
        logs/abcd-access_log
    4.2 设置要分析的服务日志类型
        LogType=W   
        w表示为WEB日志
    4.3 设置日志格式
        LogFormat=1  
        1表示采用NCSA apache combined/ELF/XLF log format
    4.4 设置所要分析网站域名
        SiteDomain="www.testmysite.com.cn"
        引号中一定要填上域名,或者服务器主机名
    4.5 设置awstats的数据库存放目录
        DirData="/usr/local/awstats/data"
    
5. 创建awstats初始化数据库

    perl awstats.pl -config=www.abcd.com -update  
    
6. 创建awstats的初始化静态统计页面

    perl awstats.pl -config=bbs.testmysite.com.cn -output -staticlinks > awstats.bbs.html  
    
7. 通过浏览器刷新统计页面

    7.1 修改awstats.www.testmysite.com.cn.conf中
        AllowToUpdateStatsFromBrowser=1
    7.2 修改awstats的存放数据目录的属性为apache的运行用户可读写
        chown -R nobody /usr/local/awstats/data
    7.3 检查/usr/local/awstats/wwwroot/cgi-bin/*.pl 是否有执行权限
        chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl     
        
        注:rpm安装包里面的*.pl都具有执行权限,tar包里面的*.pl却没有。
        

8. 设置需要认证才能访问流量统计页面

    8.1 设置用户admin有权访问该页面
        cd /usr/local/apache2/bin
        ./htpasswd   -c /usr/local/apache2/passwords admin
        按提示连续输入两次密码,这样就创建了admin用户才能访问流量统计页面。
        
    8.2 设置httpd.conf中的awstats条目增加如下内容
            AuthType Basic
            AuthName "Restricted Files"
            AuthUserFile /usr/local/apache2/passwords
            Require user admin
            
9. 两种观看日志分析方法的比较
    
    9.1 静态页面分析方法的优点
        a. 安全性高,因为分析过程可以在后台通过crontab来执行,不需要执行cgi.
        b. 统计分析页面响应速度快,因为是自动生成的静态页面,所以速度快过动态生成的页面。
        c. 对服务器的负载影响可控,自动生成的脚本执行次数一定,对服务器的负载影响也是一定的。
    9.2 动态页面分析方法的优点
        a. 实时查看,可以随时在页面动态刷新统计分析结果。
        
    9.3 上面两种方法的缺点就是他们优点的反面。
    
10. awstats在apache虚拟主机下的配置     
        
    10.1 虚拟主机有3个
         www.testmysite.com.cn
         bbs.testmysite.com.cn
         diy.testmysite.com.cn
    10.2 生成并修改对应虚拟主机的配置文件
    
         cd /etc/awstats
         cp awstats.www.testmysite.com.cn.conf awstats.bbs.testmysite.com.cn.conf
         cp awstats.www.testmysite.com.cn.conf awstats.diy.testmysite.com.cn.conf
    10.3 修改配置文件中的下列各项   
         LogFile=/usr/local/apache2/logs/bbs-accesss_log
         修改为实际的虚拟主机的log文件位置
         SiteDomain="bbs.testmysite.com.cn"
         修改为实际各虚拟主机的域名
    10.4 修改httpd.conf各虚拟主机中的配置
         <VirtualHost 202.108.59.23>
         。。。。。。
         CustomLog logs/testmysite-access_log combined
         TransferLog logs/testmysite-access_log
         。。。。。。
         </VirtualHost>  
         主要是修改日志格式保证apache输出的日志格式和awstats配置文件中配置一致。
12. 观看流量统计方法

     12.1 用户名&密码
          admin/testmysiteok
     12.2 在浏览器输入
          
          查看主页流量分析
          http://www.testmysite.com.cn/awstats/awstats.pl?config=www.testmysite.com.cn
          查看bbs流量分析
          http://www.testmysite.com.cn/awstats/awstats.pl?config=bbs.testmysite.com.cn
          查看diy流量分析
          http://www.testmysite.com.cn/awstats/awstats.pl?config=diy.testmysite.com.cn
          
          为了便于使用可以将以上连接加入收藏夹。

问题:awstats and selinux

I have been futzing with this problem all day. I installed "awstats" to
start getting better stats on my web server usage. It worked like a
charm on my test box but failed on my production box. After looking too
long in the wrong places I finally found the problem. It is selinux.

Symptoms were, when I attempted to look at the awstats page, which is a
perl script, I got the following in my Apache error_log:

...(13)Permission denied: exec of
'/usr/local/awstats/wwwroot/cgi-bin/awstats.pl' failed
...Premature end of script headers: awstats.pl

I checked all of the permissions of everything and everything was right.
Finally I found a post that mentioned looking for errors
in /var/log/messages. I look there for other things I don't know I never
thought to look there for this. Anyway, when I looked there I saw:


...kernel: audit(1146243585.213:27): avc: denied { execute } for
pid=20973 comm="httpd" name="awstats.pl" dev=dm-0 ino=1082675
scontext=root:system_r:httpd_t tcontext=system_u:object_r:usr_t
tclass=file


I turned off selinux with the "setenforce 0 " command and it started
working.

Now, the problem here is that I really do not want to run my production
server without selinux turned on and was not able to figure out how to
correct the conflict. Anybody that could offer a pointer in the right
direction will be my new best friend :)

配置都没有问题了。只有只读属性我想是linux中的selinux引起的,你关掉试试好了。
关闭SELinux的方法:
修改/etc/selinux/config文件中的SELINUX="" 为 disabled ,然后重启。
如果不想重启系统,使用命令setenforce 0
注:
setenforce 1 设置SELinux 成为enforcing模式
setenforce 0 设置SELinux 成为permissive模式 
在lilo或者grub的启动参数中增加:selinux=0,也可以关闭selinux 。

猜你喜欢

转载自lwg2001s.iteye.com/blog/1006273