среда, 19 августа 2009 г.

Инсталляция awstats на FreeBSD.

Инсталляцию рассматриваем на:
# uname -prs
FreeBSD 7.2-RELEASE i386
Ищем нужный порт:
# cd /usr/ports
# make search name=awstats

Port: awstats-6.9,1
Path: /usr/ports/www/awstats
Info: Free real-time logfile analyzer to get advanced web statistics
Согласно этому фрагменту вывода делаем следующее:
# cd /usr/ports/www/awstats
# make && make install

make clean не делаем, потому что нам пригодится содержание директории work.

Приведу наиболее полезные части вывода (с моей точки зрения) в конце инсталляции:
* Rename /usr/local/www/awstats/cgi-bin/awstats.model.conf to awstats.site.conf to setup awstats
* Documentation has been installed in /usr/local/share/doc/awstats
*****************************************************************
Please add the following to your apache config, and restart.
#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses "/usr/local/www/awstats/classes/"
Alias /awstatscss "/usr/local/www/awstats/css/"
Alias /awstatsicons "/usr/local/www/awstats/icons/"
ScriptAlias /awstats/ "/usr/local/www/awstats/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
Directory "/usr/local/www/awstats/"
Options None
AllowOverride None
Order allow,deny
Allow from all
/Directory
*****************************************************************


Забегая вперед, скажу, что конфигурационный скрипт, который мы будем запускать вручную, тоже будет спрашивать разрешения на редактирование конфигурационного файла апача. То есть имеется некая избыточность. Доверяем больше собственным рукам и делаем необходимые изменения конфигурации апача самостоятельно, пропуская соответствующий автоматический шаг. Добавляем, согласно вышеприведенным инструкциям, следующие строки в конфигурацию веб-сервера:


Alias /awstatsclasses "/usr/local/www/awstats/classes/"
Alias /awstatscss "/usr/local/www/awstats/css/"
Alias /awstatsicons "/usr/local/www/awstats/icons/"
ScriptAlias /awstats/ "/usr/local/www/awstats/cgi-bin/"

Directory "/usr/local/www/awstats/"
Options None
AllowOverride None
Order deny,allow
Deny from all
Allow from IP адреса, с которых разрешен доступ к статистике
/Directory


Далее выполняем следующие действия:
# mkdir /usr/local/etc/awstats
# cp -r /usr/ports/www/awstats/work/awstats-6.9/tools/* /usr/local/etc/awstats/
# cp -r /usr/ports/www/awstats/work/awstats-6.9/wwwroot/* /usr/local/www/awstats
# chmod +x /usr/local/etc/awstats
# chown www /usr/local/etc/awstats
# mkdir /var/db/awstats
# chown www:www /var/db/awstats/

www - это имя пользователя, под которым крутится апач.
И запускаем конфигурационный скрипт
#/usr/local/etc/awstats/awstats_configure.pl

Видим его "приглашение":
----- AWStats awstats_configure 1.0 (build 1.8) (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).

Далее поочередно отвечаем на его вопросы:

1)
-----> 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/ports/www/awstats
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

Отвечаем утвердительно.

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

Файл httpd.conf редактировали вручную. Отвечаем "нет".

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/ports/www/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.


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

Отвечаем утвердительно.

4)
-----> 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:
>
my.site.ua
ввели имя нашего сата.

5)
-----> 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):
>
/usr/local/etc/awstats
ввели имя только что созданной директории.

6)
-----> Create config file '/usr/local/etc/awstats/awstats.my.site.ua.conf'
Config file /usr/local/etc/awstats/awstats.my.site.ua.conf created.


7)
-----> 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/ports/www/awstats/wwwroot/cgi-bin/awstats.pl -update -config=my.site.ua
Or if you have several config files and prefer having only one command:
/usr/ports/www/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...


8)
-----> Create config file '/usr/local/etc/awstats/awstats.my.site.ua.conf'
Config file /usr/local/etc/awstats/awstats.my.site.ua.conf created.

9)
-----> 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/ports/www/awstats/wwwroot/cgi-bin/awstats.pl -update -config=my.site.ua
Or if you have several config files and prefer having only one command:
/usr/ports/www/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...
A SIMPLE config file has been created: /usr/local/etc/awstats/my.site.ua.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'ra.iop.kiev.ua' with command:
> perl awstats.pl -update -config=my.site.ua
You can also build static report pages for 'my.site.ua' with command:
> perl awstats.pl -output=pagetype -config=my.site.ua

Press ENTER to finish...



Добавляем строчку /usr/local/www/awstats/cgi-bin/awstats.pl -update -config=my.site.ua в крон.
Далее правим конфигурационный файл:
#vim /usr/local/etc/awstats/awstats.ra.iop.kiev.ua.conf
Присваиваем следующим параметрам соответствующие значения:
DirData="/var/db/awstats"
LogFile="/var/log/httpd/my.site.ua-access.log"

awstats понимает несколько типов логов. Поэтому ему надо указать, что он будет парсить логи апача:
LogFormat=4
# 4 - Apache or Squid native common log format (NCSA common/CLF log format)
Собственно говоря - все.
Теперь мы можем смотреть статистику сайта из браузера, набрав вот такой url:
http://my.site.ua/awstats/awstats.pl?config=my.site.ua&update
Осталось заметить, что строчки my.site.ua в имени сайта и значении CGI параметра config совпадать не обязаны. То есть мы можем организовать сбор статистики с нескольких виртуальных хостов на одном адресе http://my.site.ua/ и смотреть каждую отдельную статистику меняя значение параметра config.
Оригинал статьи находится тут. Комментарии приветствуются.

Комментариев нет: