溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Apache配置與應(yīng)用之AWstats日志分析實(shí)驗(yàn)流程

發(fā)布時(shí)間:2020-03-30 00:49:20 來(lái)源:網(wǎng)絡(luò) 閱讀:358 作者:wx5d8a17c45cb5b 欄目:系統(tǒng)運(yùn)維

Apache配置與應(yīng)用之AWstats日志分析實(shí)驗(yàn)流程

實(shí)驗(yàn)環(huán)境:centos7操作系統(tǒng)、一臺(tái)win10虛擬機(jī)操作系統(tǒng),需要軟件包:

bind.x86_64 32:9.11.4-9.P2.el7 httpd.x86_64 0:2.4.6-90.el7.centos(這里為了方便使用yum直接安裝)

awstats-7.6.tar.gz(需要自己準(zhǔn)備,鏈接:https://pan.baidu.com/s/1apCEUdFoAoUTVeWwYyJaow
提取碼:wt6u )

具體操作流程如下:

1)解壓縮awstats軟件包

tar zxvf awstats-7.6.tar.gz -C /usr/local

ls /usr/local/

2)安裝bind和httpd服務(wù)配置bind相關(guān)文件

yum install -y bind httpd

[root@localhost tools]# vim /etc/named.conf 
[root@localhost tools]# head -21 /etc/named.conf  | tail 
options {
        listen-on port 53 { any; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        recursing-file  "/var/named/data/named.recursing";
        secroots-file   "/var/named/data/named.secroots";
        allow-query     { any; };
[root@localhost tools]# vim /etc/named.rfc1912.zones 
[root@localhost tools]# head -29 /etc/named.rfc1912.zones  | tail -5
zone "lcc.com" IN {
        type master;
        file "lcc.com.zone";
        allow-update { none; };
};
[root@localhost tools]# cd /var/named/
[root@localhost named]# ls
data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves
[root@localhost named]# cp -p named.localhost lcc.com.zone
[root@localhost named]# vim lcc.com.zone 
[root@localhost named]# cat lcc.com.zone 
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
www IN  A       192.168.68.145
[root@localhost named]# systemctl stop firewalld.service 
[root@localhost named]# setenforce 0
[root@localhost named]# systemctl start named
[root@localhost named]# systemctl start httpd
[root@localhost named]# netstat -antp | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      88534/httpd         
[root@localhost named]# netstat -antp | grep named
tcp        0      0 192.168.68.145:53       0.0.0.0:*               LISTEN      88258/named         
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      88258/named         
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      88258/named         
tcp6       0      0 ::1:53                  :::*                    LISTEN      88258/named         
tcp6       0      0 ::1:953                 :::*                    LISTEN      88258/named  

在win10的虛擬機(jī)上測(cè)試一下是否可以成功解析方才設(shè)置的域名

Apache配置與應(yīng)用之AWstats日志分析實(shí)驗(yàn)流程

3)為要統(tǒng)計(jì)的站點(diǎn)建立配置文件

指定httpd主配置文件的路徑——》設(shè)置日志類型——》為指定web站點(diǎn)創(chuàng)建配置文件

[root@localhost tar]# cd /usr/local/awstats-7.6/tools/
[root@localhost tools]# ls
awstats_buildstaticpages.pl  logresolvemerge.pl
awstats_configure.pl         maillogconvert.pl
awstats_exportlib.pl         nginx
awstats_updateall.pl         urlaliasbuilder.pl
dolibarr                     webmin
geoip_generator.pl           xslt
httpd_conf
[root@localhost 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.6
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   //輸入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):
> /etc/httpd/conf/httpd.conf       //HTTPd的主配置文件的路徑

-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
  All AWStats directives are already present.

-----> Update model config file '/usr/local/awstats-7.6/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             //輸入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.lcc.com                                       //自己設(shè)置的域名

-----> 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):
>                                                                      //默認(rèn)下面全都回車即可

-----> Create config file '/etc/awstats/awstats.www.lcc.com.conf'
 Config file /etc/awstats/awstats.www.lcc.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:  //執(zhí)行日志分析的方法(兩種)
/usr/local/awstats-7.6/wwwroot/cgi-bin/awstats.pl -update -config=www.lcc.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats-7.6/tools/awstats_updateall.pl now      //會(huì)報(bào)錯(cuò),解決方法在文末
Press ENTER to continue...  

A SIMPLE config file has been created: /etc/awstats/awstats.www.lcc.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.lcc.com' with command:
> perl awstats.pl -update -config=www.lcc.com
You can also read your statistics for 'www.lcc.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.lcc.com   //這里就是我們要測(cè)試的地址,需要將localhost換為www.lcc.com

Press ENTER to finish...

[root@localhost tools]# systemctl restart httpd

4)修改Apache 2.4以上版本自動(dòng)生成的awstats訪問(wèn)權(quán)限

[root@localhost tools]# vim /etc/httpd/conf/httpd.conf 
[root@localhost tools]# tail /etc/httpd/conf/httpd.conf 
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats-7.6/wwwroot">
    Options None
    AllowOverride None
    #Order allow,deny            //注釋掉
    #Allow from all             //注釋掉
    Require all granted         //添加(所有權(quán)限)
</Directory>

5)修改站點(diǎn)統(tǒng)計(jì)配置文件

[root@localhost tools]# vim /etc/awstats/awstats.www.lcc.com.conf 
[root@localhost tools]# head -50 /etc/awstats/awstats.www.lcc.com.conf  | tail -1
LogFile="/var/log/httpd/access_log"
[root@localhost tools]# head -220 /etc/awstats/awstats.www.lcc.com.conf  | tail -1
DirData="/var/lib/awstats"
[root@localhost tools]# cd /var/lib/               //創(chuàng)建上面路徑的文件夾awstats
[root@localhost lib]# mkdir awstats

6)執(zhí)行日志分析

//在上面的第三步過(guò)程中是給出方法來(lái)執(zhí)行日志分析的方式的,而且也可以通過(guò)執(zhí)行周期性計(jì)劃任務(wù)來(lái)方便管理日志
//每執(zhí)行一次該命令,刷新訪問(wèn)頁(yè)面就會(huì)對(duì)相關(guān)數(shù)據(jù)進(jìn)行統(tǒng)計(jì)顯示出來(lái)
[root@localhost tools]# /usr/local/awstats-7.6/wwwroot/cgi-bin/awstats.pl -update -config=www.lcc.com
Create/Update database for config "/etc/awstats/awstats.www.lcc.com.conf" by AWStats version 7.6 (build 20161204)
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 0 new qualified records.

Apache配置與應(yīng)用之AWstats日志分析實(shí)驗(yàn)流程

Apache配置與應(yīng)用之AWstats日志分析實(shí)驗(yàn)流程

為了方便管理,那么我們可以使用周期性任務(wù)計(jì)劃來(lái)管理執(zhí)行有興趣可以使用crontab -e 命令來(lái)創(chuàng)建周期性任務(wù)計(jì)劃表

小結(jié)

本次實(shí)驗(yàn)是為了實(shí)現(xiàn)使用awstats進(jìn)行日志分析,過(guò)程并不復(fù)雜,但是需要注意的地方還是需要留意的,對(duì)應(yīng)之處本人稍作了一些注釋。

當(dāng)然該實(shí)驗(yàn)有兩個(gè)問(wèn)題,這邊仔細(xì)講述一下:

1.使用http://www.lcc.com/awstats/awstats.pl?config=www.lcc.com 進(jìn)行訪問(wèn)不容易讓人記住,所有需要優(yōu)化一下

[root@localhost html]#  cd /usr/local/awstats-7.6/tools/
[root@localhost tools]# cd -
/var/www/html
[root@localhost html]# vim aws.html
[root@localhost html]# cat aws.html 
<html>
<head>
<meta http-equiv=refresh content="0;
url=http://www.lcc.com/awstats/awstats.pl?config=www.lcc.com">
</head>
<body>
</body>
</html>

這樣設(shè)置之后可以使用http://www.lcc.com/aws.html進(jìn)行訪問(wèn)

2.在執(zhí)行日志分析命令時(shí)使用第二種方法會(huì)遇到如下error

[root@localhost tools]# /usr/local/awstats-7.6/tools/awstats_updateall.pl now
Error: Can't find AWStats program ('awstats.pl').
Use -awstatsprog option to solve this.

這個(gè)原因是因?yàn)槲粗付╝wstats.pl的絕對(duì)路徑,根據(jù)如下操作即可

[root@localhost tools]# find /usr/local/ -name awstats.pl
/usr/local/awstats-7.6/wwwroot/cgi-bin/awstats.pl
[root@localhost tools]# cd ../wwwroot/cgi-bin/
[root@localhost cgi-bin]# ls
awdownloadcsv.pl  awredir.pl  awstats.model.conf  awstats.pl  lang  lib  plugins
[root@localhost tools]# /usr/local/awstats-7.6/tools/awstats_updateall.pl now -awstatsprog="../wwwroot/cgi-bin/awstats.pl"
Running '"../wwwroot/cgi-bin/awstats.pl" -update -config=www.lcc.com -configdir="/etc/awstats"' to update config www.lcc.com
Create/Update database for config "/etc/awstats/awstats.www.lcc.com.conf" by AWStats version 7.6 (build 20161204)
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 101)
Jumped lines in file: 101
 Found 101 already parsed records.
Parsed lines in file: 236
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 2 corrupted records,
 Found 0 old records,
 Found 234 new qualified records.
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI