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. [root@clsn ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.5.1804 (Core)
  3. [root@clsn ~]# uname -r
  4. 3.10.0-862.9.1.el7.x86_64

安装步骤

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

3、配置启动AWStats

3.1初始化配置

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

3.2编辑配置文件

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

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

3.3配置web站点展示awstats

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

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

生成分析日志

  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. Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -update -configdir=
  6. Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output
  7. Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=alldomains
  8. Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=allhosts
  9. Build lasthosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=lasthosts
  10. Build unknownip page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownip
  11. Build allrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=allrobots
  12. Build lastrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=lastrobots
  13. Build session page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=session
  14. Build urldetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urldetail
  15. Build urlentry page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urlentry
  16. Build urlexit page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urlexit
  17. Build osdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=osdetail
  18. Build unknownos page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownos
  19. Build browserdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=browserdetail
  20. Build unknownbrowser page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownbrowser
  21. Build downloads page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=downloads
  22. Build refererse page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=refererse
  23. Build refererpages page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=refererpages
  24. Build keyphrases page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=keyphrases
  25. Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=keywords
  26. Build errors400 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors400
  27. Build errors403 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors403
  28. Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors404
  29. 23 files built.
  30. Main HTML page is 'awstats.nmtui.com.html'.

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

  1. [root@clsn nginx]# cat awstats.nmtui.com.conf
  2. server
  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

3.4添加定时任务

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

4、安全加固

4.1使用htpasswd生成加密密码

  1. [root@clsn nginx]# yum install httpd-tools -y
  2. [root@clsn nginx]# htpasswd -c /usr/local/awstats/wwwroot/nmtui.passwd nmtui
  3. New password:
  4. Re-type new password:
  5. Adding 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

4.2添加web访问认证

  1. [root@clsn nginx]# vim awstats.nmtui.com.conf
  2. server
  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

5、查看分析日志

5.1安全加固生效


AWStats日志分析系统 - 图1

5.2 分析日志显示正常

AWStats日志分析系统 - 图2

6、参考文献

https://awstats.sourceforge.io/docs

https://www.cnblogs.com/weiji100/p/3845255.html

https://www.cnblogs.com/liangml/p/6421426.html

http://clsn.io/clsn-ops/ops-linux/