於 Ubuntu 9.04 Server 安裝 AWStats

於 Ubuntu 9.04 要安裝 AWStats, 不過 Ubuntu 的 AWStats 目前版本 6.7, 現在版本已經出到 6.9, 因為某些需求, 需要跟上最新版本, 所以手動安裝(不使用 apt), 但是另外若有新版本也要可以快速升級.

前置準備

  • 監控 Domain: example.com
  • AWStats Domain: awstats.example.com
  • 下載 awstats-6.9

安裝設定

  1. tar xvf awstats-6.9.tar.gz
  2. mv awstats-6.9 /usr/local/awstats # 在此先直接 mv, 之後再做 ln 即可達成之後快速升級的目的
  3. cd /usr/local/awstats/tools
  4. sudo ./awstats_configure.pl # 問題與回答 如下述

    Config file path ('none' to skip web server setup):
    => none # httpd.conf 自己另外設定即可

    Do you want me to build a new AWStats config/profile
    file (required if first install) [y/N] ?
    => y # 這個要選 y

    Your web site, virtual server or profile name:
    => example.com

    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):
    => /etc/awstats # 或 Enter 即可.

  5. 完成後, 就已經建立好 /etc/awstats/example.com.conf
  6. 若有改設定檔 /etc/awstats/example.com.conf, 要測試可以用 下述挑其一執行即可.
    • perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=example.com
    • perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -output=pagetype -config=example.com

設定可快速升級的方式

  1. cd /usr/local
  2. sudo mv awstats awstats-6.9
  3. sudo ln -s awstats-6.9 awstats
  4. 之後若有新版, 解壓縮後, sudo ln -sf awstats-6.10 awstats 即可(可隨時切換新舊版本).

修改設定檔

vim /etc/awstats/awstats.example.com.conf

  1. 修改 Apache access.log 位置

    LogFile="/var/log/httpd/mylog.log"
    改成
    LogFile="/var/log/apache2/access.log" # access log 位置

  2. 修改 AWSTATS 資料存放位置

    DirData="/var/lib/awstats"
    # 若放在這邊, 記得
    # mkdir /var/lib/awstats
    # chown www-data:www-data /var/lib/awstats/

於 Apache 設定 AWStats

  • sudo cp /usr/local/awstats/tools/httpd_conf /etc/apache2/sites-available/awstats.conf
  • 或 使用下面 (VirtualHost)

    <VirtualHost *:80>
        ServerName awstats.example.com
        DocumentRoot /usr/local/awstats/wwwroot/

        Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
        Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
        Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
        #ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
        Alias /icon "/usr/local/awstats/wwwroot/icon/"
        ScriptAlias / "/usr/local/awstats/wwwroot/cgi-bin/"

        <Directory "/usr/local/awstats/wwwroot">
        #Options MultiViews SymLinksIfOwnerMatch
        #AllowOverride FileInfo AuthConfig Limit
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
        </Directory>
    </VirtualHost>

查看 AWStats 網址

  • 預設 http_conf: http://example.com/awstats/awstats.pl?config=example.com
  • VirtualHost: http://awstats.example.com/awstats.pl?config=example.com

AWStats 更新

  • 更新可執行(更新單一網址): /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=example.com
  • /usr/local/awstats/tools/awstats_updateall.pl now # 更新全部

定時執行更新

  1. 於 root 執行 crontab -e
  2. 加入: 0 0 * * * /usr/local/awstats/tools/awstats_updateall.pl now >/dev/null 2>&1 即可.

設定觀看 AWStats 的權限、密碼

若要設定密碼(Apache)

  1. vim /usr/local/awstats/wwwroot/.htaccess

    AuthName "Section Name"
    AuthType Basic
    AuthUserFile /usr/local/awstats/wwwroot/.htpasswd
    Require valid-user

  2. 重新存取網址即可.

相關網頁

相關注意事項

  • 若有舊的 Access Log 或有多台 Web server, AWStats 的更新, 一定得要依照時間更新, 並不會去 access.log.1、access.log.2 .. 等等, >一律都只讀設定的 access.log, 且時間如果是過期的, 就會跳過不會輸入.
  • 所以若要將舊的 Import, 需要慢慢餵資料進去.

查看餵資料的進度

  • cat /proc/16115/status # 註: /proc/pid/status, 16115 是 pid
  • VmPeak:  636908 kB # 記憶體分頁使用量, 容量跟檔案差不多, 就代表快跑完了.

作者: Tsung

對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.

在〈於 Ubuntu 9.04 Server 安裝 AWStats〉中有 4 則留言

  1. 你好,
    我有awstats DirData路徑問題
    我在centos 6.5 安裝7.0 awstats後
    將awstats.xxx.conf內的DirData路徑由原先的/var/lib/awstats 修改到我nfs的磁碟上如/data/var/lib/awstats,但在網頁執行時有問題

    Error: AWStats database directory defined in config file by 'DirData' parameter (/data/var/lib/awstats) does not exist or is not writable.

    Setup ('/etc/awstats/awstats.wimeeting-s.conf' file, web server or permissions) may be wrong.
    Check config file, permissions and AWStats documentation (in 'docs' directory).

    我試過將目錄權限修改,不行.

    可否幫忙,謝謝

    1. 呃, 這個看起來是設定檔問題, 不然你試試看, 設定改回來, 然後用 ln 作這些事情.

      ex: ln /data/var/lib/awstats /var/lib/awstats

Tsung 發表迴響取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料