Разбор squid log через LightSquid

Итак нам необходимо разобрать squid log.
Будем делать это через LightSquid

Ставим на Apache.
==========================

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/monitor
sudo nano /etc/apache2/sites-available/monitor
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName monitor
        ServerAlias www.monitor

        DocumentRoot /var/www/monitor
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/monitor/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        <Directory "/var/www/monitor/">
                <strong>AddHandler cgi-script .cgi</strong>
                <strong>AllowOverride All</strong>
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>
sudo a2ensite monitor
sudo nano /etc/hosts
127.0.1.3       monitor                 www.monitor

Создаем папку

sudo mkdir /var/www/monitor

Применяем конфигурацию Apache

sudo service apache2 reload

Качаем сам LightSquid http://lightsquid.sourceforge.net/

Распаковываем и перемещаем в папку с сайтом

tar xfv lightsquid-1.8.tgz 
sudo mv lightsquid-1.8/* /var/www/monitor/

Даем права пользователю www-data

sudo chown -Rv www-data /var/www/monitor/

Делаем исполняемыми скрипты LightSquid

sudo chmod +x /var/www/monitor/*.cgi
sudo chmod +x /var/www/monitor/*.pl

Правим конфигурацию LightSquid

sudo nano /var/www/monitor/lightsquid.cfg
#path to additional `cfg` files
$cfgpath             ="/var/www/monitor";
#path to `tpl` folder
$tplpath             ="/var/www/monitor/tpl";
#path to `lang` folder
$langpath            ="/var/www/monitor/lang";
#path to `report` folder
$reportpath          ="/var/www/monitor/report";
#path to access.log
$logpath             ="/var/log/squid";
#path to `ip2name` folder
$ip2namepath         ="/var/www/monitor/ip2name";

#language
#see `lang` folder (avaible: bg,eng,fr,hu,it,pt_br,ru,sp)
$lang                ="ru";

Проверяем конфигурацию LightSquid

sudo /var/www/monitor/check-setup.pl
LightSquid Config Checker, (c) 2005-9 Sergey Erokhin GNU GPL

LogPath   : /var/log/squid
reportpath: /var/www/monitor/report
Lang      : /var/www/monitor/lang/ru
Template  : /var/www/monitor/tpl/base
Ip2Name   : /var/www/monitor/ip2name/ip2name.simple

<strong>no: GD.PM found, please install or set $graphreport=0 to disable</strong>

Нет поддержки графиков. Будем ставить

sudo perl -MCPAN -e shell
cpan[1]> install GD
cpan[2]> exit

Если вылетает с ошибкой.

**UNRECOVERABLE ERROR**
<strong>Could not find gdlib-config in the search path. Please install libgd 2.0.28 or higher.</strong>
If you want to try to compile anyway, please rerun this script with the option --ignore_missing_gd.
Warning: No success on command[/usr/bin/perl Makefile.PL INSTALLDIRS=site]
'YAML' not installed, will not store persistent state
  LDS/GD-2.49.tar.gz
  /usr/bin/perl Makefile.PL INSTALLDIRS=site -- NOT OK
Running make test
  Make had some problems, won't test
Running make install
  Make had some problems, won't install
Failed during this command:
 LDS/GD-2.49.tar.gz                           : writemakefile NO '/usr/bin/perl Makefile.PL INSTALLDIRS=site' returned status 512

Фиксим

sudo apt-get -y install libgd2-xpm-dev build-essential

Пытаемся ставить по новой. В результате пишет.

Appending installation info to /usr/local/lib/perl/5.12.4/perllocal.pod
  LDS/GD-2.49.tar.gz
  /usr/bin/make install  -- OK

cpan[2]> exit

Еще раз проверяем нашу конфигурацию

sudo /var/www/monitor/check-setup.pl
LightSquid Config Checker, (c) 2005-9 Sergey Erokhin GNU GPL

LogPath   : /var/log/squid
reportpath: /var/www/monitor/report
Lang      : /var/www/monitor/lang/ru
Template  : /var/www/monitor/tpl/base
Ip2Name   : /var/www/monitor/ip2name/ip2name.simple

all check passed, now try access to cgi part in browser

Проверям работу сайта http://www.monitor/

Запускаем парсер логов

sudo /var/www/monitor/lightparser.pl 

Смотрим что получилось в браузере http://www.monitor/

Прописываем автоматический разбор логов SQID каждый день в 23.00

sudo EDITOR=nano crontab -e
00 23 * * * /var/www/monitor/lightparser.pl # Парсим логи сквида

Ну и далее можно редакировать на свой вкус и запросы.

One comment

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *