AWStats日志分析系统

释放双眼,带上耳机,听听看~!

1.什么是AWStats

AWStats是一款功能强大且功能强大的免费工具,可以图形方式生成高级Web,流媒体,ftp或邮件服务器统计信息。此日志分析器用作CGI或命令行, 并在几个图形网页中显示您的日志包含的所有可能信息。
它使用部分信息文件来经常快速地处理大型日志文件。它可以分析来自所有主要服务器工具的日志文件,如Apache日志文件(NCSA组合/ XLF / ELF日志格式或通用/ CLF日志格式),WebStar,IIS(W3C日志格式)以及许多其他Web,代理,wap,流服务器,邮件服务器和一些ftp服务器。
关于AWStats与其他日志分析系统的对比可以查看:https://awstats.sourceforge.io/docs/awstats_compare.html

2.安装AWStats

2.1 获取awstats

AWStats 官网:https://awstats.sourceforge.io/
AWStats 下载地址: https://awstats.sourceforge.io/\#DOWNLOAD

2.2安装awstats

系统版本说明


1
2
3
4
5
1[root@clsn ~]# cat  /etc/redhat-release
2CentOS Linux release 7.5.1804 (Core)
3[root@clsn ~]# uname  -r
43.10.0-862.9.1.el7.x86_64
5

安装步骤


1
2
3
4
5
6
7
1wget https://prdownloads.sourceforge.net/awstats/awstats-7.7.tar.gz
2tar  xf awstats-7.7.tar.gz
3mv  awstats-7.7 /usr/local/
4ln -s /usr/local/awstats-7.7/ /usr/local/awstats
5# 注:awstats默认为www用户,可以根据web环境用户进行修改
6chown -R www.www /usr/local/awstats/
7

3.配置启动AWStats

3.1初始化配置


1
2
1在这次配置中我已站点nmtui.com为例,进行设置。
2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
1[root@clsn tools]# cd /usr/local/awstats/tools
2[root@clsn tools]# ./awstats_configure.pl
3
4----- AWStats awstats_configure 1.0 (build 20140126) (c) Laurent Destailleur -----
5This tool will help you to configure AWStats to analyze statistics for
6one web server. You can try to use it to let it do all that is possible
7in AWStats setup, however following the step by step manual setup
8documentation (docs/index.html) is often a better idea. Above all if:
9- You are not an administrator user,
10- You want to analyze downloaded log files without web server,
11- You want to analyze mail or ftp log files instead of web log files,
12- You need to analyze load balanced servers log files,
13- You want to 'understand' all possible ways to use AWStats...
14Read the AWStats documentation (docs/index.html).
15
16-----> Running OS detected: Linux, BSD or Unix
17Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
18If you want to use standard directory, you should first move all content
19of AWStats distribution from current directory:
20/usr/local/awstats-7.7
21to standard directory:
22/usr/local/awstats
23And then, run configure.pl from this location.
24Do you want to continue setup from this NON standard directory [yN] ? y
25
26-----> Check for web server install
27
28Enter full config file path of your Web server.
29Example: /etc/httpd/httpd.conf
30Example: /usr/local/apache2/conf/httpd.conf
31Example: c:\Program files\apache group\apache\conf\httpd.conf
32Config file path ('none' to skip web server setup): #
33> none
34
35Your web server config file(s) could not be found.
36You will need to setup your web server manually to declare AWStats
37script as a CGI, if you want to build reports dynamically.
38See AWStats setup documentation (file docs/index.html)
39
40-----> Update model config file '/usr/local/awstats-7.7/wwwroot/cgi-bin/awstats.model.conf'
41  File awstats.model.conf updated.
42
43-----> Need to create a new config file ?
44Do you want me to build a new AWStats config/profile
45file (required if first install) [y/N] ? y
46
47-----> Define config file name to create
48What is the name of your web site or profile analysis ?
49Example: www.mysite.com
50Example: demo
51Your web site, virtual server or profile name:
52> nmtui.com
53
54-----> Define config file path
55In which directory do you plan to store your config file(s) ?
56Default: /etc/awstats
57Directory path to store config file(s) (Enter for default):
58>
59
60-----> Create config file '/etc/awstats/awstats.nmtui.com.conf'
61 Config file /etc/awstats/awstats.nmtui.com.conf created.
62
63-----> Add update process inside a scheduler
64Sorry, configure.pl does not support automatic add to cron yet.
65You can do it manually by adding the following command to your cron:
66/usr/local/awstats-7.7/wwwroot/cgi-bin/awstats.pl -update -config=nmtui.com
67Or if you have several config files and prefer having only one command:
68/usr/local/awstats-7.7/tools/awstats_updateall.pl now
69Press ENTER to continue...
70
71
72A SIMPLE config file has been created: /etc/awstats/awstats.nmtui.com.conf
73You should have a look inside to check and change manually main parameters.
74You can then manually update your statistics for 'nmtui.com' with command:
75> perl awstats.pl -update -config=nmtui.com
76You can also build static report pages for 'nmtui.com' with command:
77> perl awstats.pl -output=pagetype -config=nmtui.com
78
79Press ENTER to finish...
80

3.2编辑配置文件

在初始化配置红 nmtui.com 站点的配置文件在 /etc/awstats/awstats.nmtui.com.conf


1
2
3
4
1vi /etc/awstats/awstats.nmtui.com.conf
2# 在配置中寻找【 LogFile 】字段,将其修改为该主机的日志地址。
3LogFile="/www/wwwlogs/nmtui.com.log"
4

3.3配置web站点展示awstats

在使用之前需要搭建nginx或httpd等web服务,可以参考:http://clsn.io/clsn/lx892.html
配置web站点:


1
2
3
4
5
1mkdir  /www/wwwroot/awstats
2cd /usr/local/awstats/wwwroot/
3cp -ar  css icon js  /www/wwwroot/awstats/
4chown  -R www.www  /www/wwwroot/awstats
5

生成分析日志


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
1[root@clsn nginx]# /usr/local/awstats/tools/awstats_buildstaticpages.pl  \
2-config=nmtui.com -update -lang=cn \
3-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl \
4-dir=/www/wwwroot/awstats/
5
6Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -update -configdir=
7Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output
8Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=alldomains
9Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=allhosts
10Build lasthosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=lasthosts
11Build unknownip page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownip
12Build allrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=allrobots
13Build lastrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=lastrobots
14Build session page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=session
15Build urldetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urldetail
16Build urlentry page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urlentry
17Build urlexit page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urlexit
18Build osdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=osdetail
19Build unknownos page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownos
20Build browserdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=browserdetail
21Build unknownbrowser page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownbrowser
22Build downloads page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=downloads
23Build refererse page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=refererse
24Build refererpages page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=refererpages
25Build keyphrases page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=keyphrases
26Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=keywords
27Build errors400 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors400
28Build errors403 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors403
29Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors404
3023 files built.
31Main HTML page is 'awstats.nmtui.com.html'.
32

修改nginx配置(修改完成后重新加载nginx配置文件):


1
2
3
4
5
6
7
8
9
10
11
12
1[root@clsn nginx]# cat   awstats.nmtui.com.conf
2server
3{
4    listen 80;
5    server_name awstats.nmtui.com;
6    index awstats.nmtui.com.html;
7    root /www/wwwroot/awstats/;
8    access_log  /www/wwwlogs/awstats.nmtui.com.log;
9    error_log  /www/wwwlogs/awstats.nmtui.com-error.log;
10}
11[root@clsn nginx]# /etc/init.d/nginx  reload
12

3.4添加定时任务


1
2
3
1# 添加定时任务,定时更新awstats分析日志
2
3

4.安全加固

4.1使用htpasswd生成加密密码


1
2
3
4
5
6
7
8
1[root@clsn nginx]# yum install httpd-tools -y
2[root@clsn nginx]# htpasswd  -c /usr/local/awstats/wwwroot/nmtui.passwd nmtui
3New password:
4Re-type new password:
5Adding password for user nmtui
6[root@clsn nginx]# chown www.www  /usr/local/awstats/wwwroot/nmtui.passwd
7[root@clsn nginx]# chmod 600  /usr/local/awstats/wwwroot/nmtui.passwd
8

4.2添加web访问认证


1
2
3
4
5
6
7
8
9
10
11
12
13
14
1[root@clsn nginx]# vim  awstats.nmtui.com.conf
2server
3{
4    listen 80;
5    server_name awstats.nmtui.com;
6    index awstats.nmtui.com.html;
7    root /www/wwwroot/awstats/;
8    auth_basic "clsn training";
9    auth_basic_user_file /usr/local/awstats/wwwroot/nmtui.passwd;
10    access_log  /www/wwwlogs/301-clsn.io.log;
11    error_log  /www/wwwlogs/301-clsn.io-error.log;
12}
13[root@clsn nginx]# /etc/init.d/nginx  reload
14

5.查看分析日志

5.1安全加固生效

AWStats日志分析系统

5.2 分析日志显示正常

AWStats日志分析系统

6.参考文献

给TA打赏
共{{data.count}}人
人已打赏
安全经验

图解教程:Google Adsense和百度联…

2021-10-11 16:36:11

安全经验

安全咨询服务

2022-1-12 14:11:49

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索