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

系統版本說明

[root@clsn ~]# cat  /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@clsn ~]# uname  -r
3.10.0-862.9.1.el7.x86_64

安裝步驟

wget https://prdownloads.sourceforge.net/awstats/awstats-7.7.tar.gz
tar  xf awstats-7.7.tar.gz 
mv  awstats-7.7 /usr/local/
ln -s /usr/local/awstats-7.7/ /usr/local/awstats
# 注:awstats默認爲www用戶,可以根據web環境用戶進行修改
chown -R www.www /usr/local/awstats/

3.配置啓動AWStats

3.1初始化配置

在這次配置中我已站點nmtui.com爲例,進行設置。
[root@clsn tools]# cd /usr/local/awstats/tools
[root@clsn tools]# ./awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 20140126) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).

-----> Running OS detected: Linux, BSD or Unix
Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/usr/local/awstats-7.7
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ? y

-----> Check for web server install

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): #
> none

Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)

-----> Update model config file '/usr/local/awstats-7.7/wwwroot/cgi-bin/awstats.model.conf'
  File awstats.model.conf updated.

-----> 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:
> nmtui.com

-----> 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):
>

-----> Create config file '/etc/awstats/awstats.nmtui.com.conf'
 Config file /etc/awstats/awstats.nmtui.com.conf created.

-----> 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-7.7/wwwroot/cgi-bin/awstats.pl -update -config=nmtui.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats-7.7/tools/awstats_updateall.pl now
Press ENTER to continue...


A SIMPLE config file has been created: /etc/awstats/awstats.nmtui.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'nmtui.com' with command:
> perl awstats.pl -update -config=nmtui.com
You can also build static report pages for 'nmtui.com' with command:
> perl awstats.pl -output=pagetype -config=nmtui.com

Press ENTER to finish...

3.2編輯配置文件

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

vi /etc/awstats/awstats.nmtui.com.conf
# 在配置中尋找【 LogFile 】字段,將其修改爲該主機的日誌地址。
LogFile="/www/wwwlogs/nmtui.com.log"

3.3配置web站點展示awstats

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

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

生成分析日誌

[root@clsn nginx]# /usr/local/awstats/tools/awstats_buildstaticpages.pl  \
-config=nmtui.com -update -lang=cn \
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl \
-dir=/www/wwwroot/awstats/

Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -update -configdir=
Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output
Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=alldomains
Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=allhosts
Build lasthosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=lasthosts
Build unknownip page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownip
Build allrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=allrobots
Build lastrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=lastrobots
Build session page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=session
Build urldetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urldetail
Build urlentry page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urlentry
Build urlexit page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=urlexit
Build osdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=osdetail
Build unknownos page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownos
Build browserdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=browserdetail
Build unknownbrowser page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=unknownbrowser
Build downloads page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=downloads
Build refererse page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=refererse
Build refererpages page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=refererpages
Build keyphrases page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=keyphrases
Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=keywords
Build errors400 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors400
Build errors403 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors403
Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=nmtui.com -staticlinks -lang=cn -output=errors404
23 files built.
Main HTML page is 'awstats.nmtui.com.html'.

修改nginx配置(修改完成後重新加載nginx配置文件):

[root@clsn nginx]# cat   awstats.nmtui.com.conf
server
{
    listen 80;
    server_name awstats.nmtui.com;
    index awstats.nmtui.com.html;
    root /www/wwwroot/awstats/;
    access_log  /www/wwwlogs/awstats.nmtui.com.log;
    error_log  /www/wwwlogs/awstats.nmtui.com-error.log;
}
[root@clsn nginx]# /etc/init.d/nginx  reload

3.4添加定時任務

# 添加定時任務,定時更新awstats分析日誌

4.安全加固

4.1使用htpasswd生成加密密碼

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

4.2添加web訪問認證

[root@clsn nginx]# vim  awstats.nmtui.com.conf
server
{
    listen 80;
    server_name awstats.nmtui.com;
    index awstats.nmtui.com.html;
    root /www/wwwroot/awstats/;
    auth_basic "clsn training";
    auth_basic_user_file /usr/local/awstats/wwwroot/nmtui.passwd;
    access_log  /www/wwwlogs/301-clsn.io.log;
    error_log  /www/wwwlogs/301-clsn.io-error.log;
}
[root@clsn nginx]# /etc/init.d/nginx  reload

5.查看分析日誌

5.1安全加固生效

5.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/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章