AWStatsを利用してApacheのアクセスログを解析し、Webサイトへのアクセス統計をWebブラウザから参照できるようにする。
[root@localhost ~]# wget http://prdownloads.sourceforge.net/awstats/awstats-7.3-1.noarch.rpm ← AWStatsダウンロード |
※最新版のURLはダウンロードページで確認すること |
[root@localhost ~]# rpm -ivh awstats-7.3-1.noarch.rpm ← AWStatsインストール |
[root@localhost ~]# rm -f awstats-7.3-1.noarch.rpm ← ダウンロードしたファイルを削除 |
[root@localhost ~]# vi `rpm -ql awstats | grep "awstats\.pl"` ← awstats.pl編集 |
※レポートの日付形式を「月 2月 2010」から「2010年 2月」へ変更 if ( $MonthRequired eq 'all' ) { print "$Message[6] $YearRequired"; } else { #"$Message[5] $MonthNumLib{$MonthRequired} $YearRequired"; ← 行頭に#を追加してコメントアウト "$YearRequired$Message[6] ".$MonthNumLib{$MonthRequired}; ← 追加(日付をYYYY年 MM月形式にする) } print( $MonthRequired eq 'all' ? "$Message[6] $YearRequired" #: "$Message[5] " ← 行頭に#を追加してコメントアウト #. $MonthNumLib{$MonthRequired} ← 行頭に#を追加してコメントアウト #. " $YearRequired" ← 行頭に#を追加してコメントアウト : "$YearRequired$Message[6] $MonthNumLib{$MonthRequired}" ← 追加(日付をYYYY年 MM月形式にする) ); #print "$MonthNumLib{$monthix}<br />$YearRequired"; ← 行頭に#を追加してコメントアウト print "$YearRequired$Message[6]<br />$MonthNumLib{$monthix}"; ← 追加(日付をYYYY年 MM月形式にする) #print "$MonthNumLib{$monthix} $YearRequired"; ← 行頭に#を追加してコメントアウト print "$YearRequired$Message[6] $MonthNumLib{$monthix}"; ← 追加(日付をYYYY年 MM月形式にする) |
[root@localhost ~]# touch /etc/httpd/conf.d/awstats.conf ← Apache用AWStats設定ファイル作成 |
[root@localhost ~]# cd /usr/local/awstats/ ← AWStats設定スクリプト格納ディレクトリへ移動 |
[root@centos awstats]# perl /usr/local/awstats/tools/awstats_configure.pl ← AWStats設定スクリプト実行 |
----- 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 -----> 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.d/awstats.conf ← Apache用AWStats設定ファイル名応答 -----> Check and complete web server config file '/etc/httpd/conf.d/awstats.conf' Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"' Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"' Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"' Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"' Add '' directive AWStats directives added to Apache config file. -----> Update model config file '/etc/awstats/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応答(AWStats設定ファイル作成) -----> 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: > centossrv.com ← サイト名応答(例:centossrv.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): > ← 空ENTER(AWStats設定ファイル作成先はデフォルト=/etc/awstats) -----> Create config file '/etc/awstats/awstats.centossrv.com.conf' Config file /etc/awstats/awstats.centossrv.com.conf created. -----> Restart Web server with '/sbin/service httpd restart' Redirecting to /bin/systemctl restart httpd.service -----> 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/wwwroot/cgi-bin/awstats.pl -update -config=centossrv.com Or if you have several config files and prefer having only one command: /usr/local/awstats/tools/awstats_updateall.pl now Press ENTER to continue... ← 空ENTER A SIMPLE config file has been created: /etc/awstats/awstats.centossrv.com.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'centossrv.com' with command: > perl awstats.pl -update -config=centossrv.com You can also read your statistics for 'centossrv.com' with URL: > http://localhost/awstats/awstats.pl?config=centossrv.com Press ENTER to finish... ← 空ENTER |
[root@centos awstats]# cd ← ディレクトリ移動(ホームへ戻る) |
[root@localhost ~]# vi /etc/awstats/awstats.centossrv.com.conf ← 設定ファイル編集 |
# "LogFile" contains the web, ftp or mail server log file to analyze. # Possible values: A full path, or a relative path from awstats.pl directory. # Example: "/var/log/apache/access.log" # Example: "../logs/mycombinedlog.log" # You can also use tags in this filename if you need a dynamic file name # depending on date or time (Replacement is made by AWStats at the beginning # of its execution). This is available tags : # %YYYY-n is replaced with 4 digits year we were n hours ago # %YY-n is replaced with 2 digits year we were n hours ago # %MM-n is replaced with 2 digits month we were n hours ago # %MO-n is replaced with 3 letters month we were n hours ago # %DD-n is replaced with day we were n hours ago # %HH-n is replaced with hour we were n hours ago # %NS-n is replaced with number of seconds at 00:00 since 1970 # %WM-n is replaced with the week number in month (1-5) # %Wm-n is replaced with the week number in month (0-4) # %WY-n is replaced with the week number in year (01-52) # %Wy-n is replaced with the week number in year (00-51) # %DW-n is replaced with the day number in week (1-7, 1=sunday) # use n=24 if you need (1-7, 1=monday) # %Dw-n is replaced with the day number in week (0-6, 0=sunday) # use n=24 if you need (0-6, 0=monday) # Use 0 for n if you need current year, month, day, hour... # Example: "/var/log/access_log.%YYYY-0%MM-0%DD-0.log" # Example: "C:/WINNT/system32/LogFiles/W3SVC1/ex%YY-24%MM-24%DD-24.log" # You can also use a pipe if log file come from a pipe : # Example: "gzip -d </var/log/apache/access.log.gz | " # If there are several log files from load balancing servers : # Example: "/pathtotools/logresolvemerge.pl *.log | " # LogFile="/var/log/httpd/access_log" ← Apacheアクセスログファイル名を指定 # Enter here all other possible domain names, addresses or virtual host # aliases someone can use to access your site. Try to keep only the minimum # number of possible names/addresses to have the best performances. # You can repeat the "SiteDomain" value in this list. # This parameter is used to analyze referer field in log file and to help # AWStats to know if a referer URL is a local URL of same site or an URL of # another site. # Note: Use space between each value. # Note: You can use regular expression values writing value with REGEX[value]. # Note: You can also use @/mypath/myfile if list of aliases are in a file. # Example: "www.myserver.com localhost 127.0.0.1 REGEX[mydomain\.(net | org)$]" # HostAliases="127.0.0.1 localhost REGEX[^192\.168\.1\.]" ← 自ホストおよび内部(例:192.168.1.x)からのアクセスをアクセス元(リファラ)から除外する # Do not include access from clients that match following criteria. # If your log file contains IP addresses in host field, you must enter here # matching IP addresses criteria. # If DNS lookup is already done in your log file, you must enter here hostname # criteria, else enter ip address criteria. # The opposite parameter of "SkipHosts" is "OnlyHosts". # Note: Use space between each value. This parameter is not case sensitive. # Note: You can use regular expression values writing value with REGEX[value]. # Change : Effective for new updates only # Example: "127.0.0.1 REGEX[^192\.168\.] REGEX[^10\.]" # Example: "localhost REGEX[^.*\.localdomain$]" # Default: "" # SkipHosts="127.0.0.1 localhost REGEX[^192\.168\.1\.]" ← 自ホストおよび内部(例:192.168.1.x)からのアクセスをアクセス元(クライアント)から除外する # If you want to have hosts reported by name instead of ip address, AWStats # need to make reverse DNS lookups (if not already done in your log file). # With DNSLookup to 0, all hosts will be reported by their IP addresses and # not by the full hostname of visitors (except if names are already available # in log file). # If you want/need to set DNSLookup to 1, don't forget that this will reduce # dramatically AWStats update process speed. Do not use on large web sites. # Note: Reverse DNS lookup is done on IPv4 only (Enable ipv6 plugin for IPv6). # Note: Result of DNS Lookup can be used to build the Country report. However # it is highly recommanded to enable the plugin 'geoipfree' or 'geoip' to # have an accurate Country report with no need of DNS Lookup. # Possible values: # 0 - No DNS Lookup # 1 - DNS Lookup is fully enabled # 2 - DNS Lookup is made only from static DNS cache file (if it exists) # Default: 2 # DNSLookup=2 ↓ DNSLookup=1 ← アクセス元の名前解決を行う(アクセス元をIPアドレスではなくホスト名で表示する) # Plugin: GeoIPfree # Perl modules required: Geo::IPfree version 0.2+ (from Graciliano M.P.) # Country chart is built from an Internet IP-Country database. # This plugin is useless for intranet only log files. # Note: You must choose between using this plugin (need Perl Geo::IPfree # module, database less up to date) or the GeoIP plugin (need Perl Geo::IP # module from Maxmind, database more up to date). # Note: Activestate provide a corrupted version of Geo::IPfree 0.2 Perl # module, so install it from elsewhere (from www.cpan.org for example). # This plugin reduces AWStats speed of 10% ! # #LoadPlugin="geoipfree" ↓ LoadPlugin="geoipfree" ← コメント解除(アクセス元国情報を詳細に取得) # When AWStats builds HTML links in its report pages, it starts those links # with "http://". However some links might be HTTPS links, so you can enter # here the root of all your HTTPS links. If all your site is a SSL web site, # just enter "/". # This parameter is not used if ShowLinksOnUrl is 0. # Example: "/shopping" # Example: "/" # Default: "" # UseHTTPSLinkForUrl="/" ← /を指定※Webサーバー間通信内容暗号化を導入している場合のみ |
[root@localhost ~]# yum -y install perl-CPAN ← perl-CPANインストール |
[root@localhost ~]# perl -MCPAN -e shell ← perl-CPAN起動 |
CPAN.pm requires configuration, but most of it can be done automatically. If you answer 'no' below, you will enter an interactive dialog for each configuration option instead. Would you like to configure as much as possible automatically? [yes] ← 空ENTER Autoconfigured everything but 'urllist'. Now you need to choose your CPAN mirror sites. You can let me pick mirrors for you, you can select them from a list or you can enter them by hand. Would you like me to automatically choose some CPAN mirror sites for you? (This means connecting to the Internet) [yes] ← 空ENTER Trying to fetch a mirror list from the Internet Fetching with LWP: http://www.perl.org/CPAN/MIRRORED.BY Looking for CPAN mirrors near you (please be patient) .......................... done! New urllist http://www.msg.com.mx/CPAN/ http://ftp.osuosl.org/pub/CPAN/ http://cpan.knowledgematters.net/ Autoconfiguration complete. commit: wrote '/root/.cpan/CPAN/MyConfig.pm' You can re-run configuration any time with 'o conf init' in the CPAN shell Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v1.9800) Enter 'h' for help. |
cpan[1]> install Geo::IPfree ← Geo::IPfreeモジュールインストール |
cpan[2]> quit ← perl-CPAN終了 |
Terminal does not support GetHistory. Lockfile removed. |