sarg日志 acl从上向下一次匹配,匹配即停止,并执行匹配的动作 所以允许所有或者禁止所有的参数,需要设置在acl的后面 http_access allow all http_access deny all 先了解acl访问控制 src 源地址 dst 目标地址 列表的定义

  • 基于固定ip去进行控制 acl localhos src 192.168.175.136/32
  • 指定某一个网段 acl MYLAN src 192.168.175.0/24
  • 基于目标地址 acl destionhost dst 192.168.175.130/32
  • 设置访问的最大连接数 acl MC20 maxconn 20
  • 支持正则表达式的结构 acl BURL url_regex -i ^rtsp:// ^emule:// acl PURL urlpath_regex -i . mp3$ . rmvb$
  • 基于访问的时间,周一到周日 acl work time MTWHFAC 08:30-17:30 也可以使用文件进行管理,文件内输入目标web地址
  • 禁止某IP地址主机上网 acl nolink src 192.168.90.9 http_access deny nolink
  • 禁止某网段在某时间段上网 acl nolink src 192.168.1.0/24 acl nowang time MTWHF 9:00-11:30 http_access deny nolink nowang
  • 禁止所有人访问某网站 acl nourl dstdomain -i www.qq.com http_access deny nourl
  • 禁止所有人访问含有某些关键字的网站 acl nourl url_regex -i taobao.com http access deny nourl
  • 禁止下载某些类型的文件 acl nof urlpath_regex -i .avi$ .mkv$ http_access deny nof
  • 禁止访问某些类型的网站 acl nop url_regex -i ^emule:// ^thunder http_access_access deny nop 配置sarg日志分析软件,用来分析squid服务的日志 需要在代理服务器上安装httpd
[root@squid network-scripts]# vim /etc/squid.conf
# should be allowed
acl hostlocal src 192.168.10.100/32		#增加
。。。
# Deny requests to certain unsafe ports
http_access deny hostlocal		#增加
[root@squid network-scripts]# service squid reload
[root@squid network-scripts]# netstat -natp | grep 3128tcp        0      0 192.168.10.1:3128       0.0.0.0:*               LISTEN      101064/(squid-1) 

注意,squid的源地址是客户端,目标地址是web端 此时切换到win客户机查看时候被限制(记得随时清空历史记录) /etc/squid.conf文件中的deny/allow是从上而下去读取配置,一旦匹配上,就不执行下面操作 接下来开始配置日志 首先删除刚才的限制,以便于后面的验证

[root@squid network-scripts]# service squid reload
[root@squid network-scripts]# cd /abc
[root@squid abc]# tar zxvf sarg-2.3.7.tar.gz -C /opt
[root@squid abc]# cd /opt/sarg-2.3.7/

安装sarg前需要先安装图像化处理工具,即gd库

[root@squid sarg-2.3.7]# yum install gd gd-devel -y
[root@squid sarg-2.3.7]# ./configure 
--prefix=/usr/local/sarg \
--sysconfdir=/etc/sarg \
--enable-extraprotection
[root@squid sarg-2.3.7]# make && make install
[root@squid sarg-2.3.7]# cd /etc/sarg/
[root@squid sarg]# ls
css.tpl  exclude_codes  sarg.conf  user_limit_block
[root@squid sarg]# vim sarg.conf 
7 access_log /usr/local/squid/var/logs/access.log	//squid的访问日志位置
25 title "Squid User Access Reports"			//网页标题
120 output_dir /var/www/html/squid-reports	//分析报告存放位置
178 user_ip no				//不使用IP代替用户ID
184 topuser_sort_field connect reverse			//升序排列
190 user_sort_field connect reverse
206 exclude_hosts /usr/local/sarg/noreport       #这个文件待会需要创建,里面存放的是不生成报告的主机
257 overwrite_report no
289 mail_utility mailq.postfix			//指定发邮件命令
434 charset UTF-8
518 weekdays 0-6		//指定top排序星期周期
525 hours 0-23			//指定top排序时间周期
633 www_document_root /var/www/html	//网页根目录
[root@squid sarg]# touch /usr/local/sarg/noreport		//建立不生成报告的主机列表文件
[root@squid sarg]# ln -s /usr/local/sarg/bin/sarg /usr/local/bin/		//创建命令软连接
[root@squid sarg]# sarg		//开启
SARG: Records in file: 238, reading: 100.00%
SARG: Successful report generated on /var/www/html/squid-reports/2020Feb02-2020Feb02
[root@squid sarg]# cd /var/www/html/
[root@squid html]# ls
index.php  sarg-php  squid-reports
[root@squid html]# cd squid-reports/
[root@squid squid-reports]# ls
2020Feb02-2020Feb02  images  index.html
[root@squid squid-reports]# rpm -q httpd
httpd-2.4.6-90.el7.centos.x86_64
[root@squid squid-reports]# systemctl restart httpd.service 

可以使用周期性计划任务执行crontab -e,每天生成日志报告

[root@squid squid-reports]# sarg -l /usr/local/squid/var/logs/access.log -o /var/www/html/squid-reports/ -z -d $(date -d "1 day ago" +%d/%m/%Y)-$(date +%d/%m/%Y)