Sistemas‎ > ‎Linux‎ > ‎

SARG - Squid

# cd /root
# wget http://sourceforge.net/projects/sarg/files/sarg/sarg-2.3.7/sarg-2.3.7.tar.gz/download
# tar -vzxf sarg-2.3.7.tar.gz
# cd sarg-2.3.5
# ./configure
# make
# make install
# crontab -e
  # Agendamento do SARG
  00 05 * * * /usr/local/bin/sarg -d `date --date "1 day ago" +\%d/\%m/\%Y`
  00 04 * * 1 /usr/local/bin/sarg -d `date --date "1 week ago" +\%d/\%m/\%Y`-`date --date "1 day ago" +\%d/\%m/\%Y`
  00 03 1 * * /usr/local/bin/sarg -d `date --date "1 month ago" +\%d/\%m/\%Y`-`date --date "1 day ago" +\%d/\%m/\%Y`

Os logs serão salvos em "http://servidor/squid-reports/"

-----------------

# vi /root/compactar_reports.sh

#!/bin/bash

# compacta arquivos antigos
find /var/www/html/squid-reports/* -maxdepth 0 -type d -mtime +30 | cut -d"/" -f6 | grep "-" > /tmp/lista.sarg
cd /var/www/html/squid-reports
for i in `/bin/cat /tmp/lista.sarg`
do
   tar chfvz $i.tar.gz $i > /dev/null
   rm -rf /var/www/html/squid-reports/$i
done


find /var/www/html/squid-reports/*.tar.gz -mtime +60 -exec rm -rf {} \;

# chmod 755 /root/compactar_reports.sh

-----------------


# vi /etc/logrotate.d/squid 

/var/log/squid/*.log {
    weekly
    rotate 6
    #compress
    notifempty
    missingok
    nocreate
    sharedscripts
    postrotate
      # Asks squid to reopen its logs. (logfile_rotate 0 is set in squid.conf)
      # errors redirected to make it silent if squid is not running
      /usr/sbin/squid -k rotate 2>/dev/null
      # Wait a little to allow Squid to catch up before the logs is compressed
      sleep 1
    endscript
}
    

----------------i------

# cd /var/www/html
htpasswd -c .htpasswd root

# vi /var/www/html/squid-reports/.htaccess

AuthName "Acesso Restrito"
AuthType Basic
AuthUserFile /var/www/html/.htpasswd
require user root

# vi /etc/httpd/conf/httpd.conf

...
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All
...


# service httpd restart
Comments