Squid ACL访问控制与sarg日志

ACL访问控制

ACL(Access Control List,访问控制列表),可以针对源地址、目标地址、访问的URL路径、访问的时间等各种条件进行过滤
ACL访问控制的步骤
使用acl配置项定义需要控制的条件
通过http_access配置项对已定义的列表做允许或拒绝的访问控制
ACL解释
acl 列表名称 列表类型 列表内容
src       源地址
dst      目标地址
port      目标端口
dstdomain   目标域
time     访问时间
maxconn    最大并发连接
url_regex  目标URL地址
urlpath_regex  整个目标URL路径

来吧!展示!!

继承昨天做的透明代理为基础,开始今天的实验
昨天博客地址点这里

[root@localhost ~]# vim /etc/squid.conf
##在acl字段添加
acl win src 192.168.10.20/32

# Deny requests to certain unsafe ports   ##找到这行
http_access deny win  ##添加这行
http_access deny !Safe_ports
[root@localhost ~]# service squid reload

客户机就无法正常访问了,证明策列设置成功
在这里插入图片描述也可以把你的IP或者域名放在一个list里,做策略时使用你创建的list名

Squid日志分析工具Sarg展示!!

在squid服务器上安装sarg

[root@localhost bao]# rz -E
rz waiting to receive.
[root@localhost bao]# ls
sarg-2.3.7.tar.gz  squid-3.4.6  squid-3.4.6.tar.gz
[root@localhost bao]# tar zxvf sarg-2.3.7.tar.gz 
[root@localhost sarg-2.3.7]# ./configure  \
> --prefix=/usr/local/sarg \
> --sysconfdir=/etc/sarg \
> --enable-extraprotection
[root@localhost sarg-2.3.7]# make && make install

对sarg进行配置

[root@localhost sarg-2.3.7]# vim /etc/sarg/sarg.conf
  7 access_log /usr/local/squid/var/logs/access.log  ##取消注释,指定日志文件
 25 title "Squid User Access Reports"	##页面标题
120 output_dir /var/www/html/squid-reports	##报告输出位置
178 user_ip no	##用户名显示
184 topuser_sort_field BYTES reverse	##降序排列
190 #user_sort_field BYTES reverse  ##列表降序
206 exclude_hosts /usr/local/sarg/weizhi	##不计入排序站点位置
257 overwrite_report no	##是否覆盖同名日志
289 mail_utility mailq/postfix	##发送邮件报告
434 charset UTF-8	#字符集UTF-8
518 weekdays 0-6	##星期周期
525 hours 0-23	##小时周期
633 www_document_root /var/www/html	##网页根目录
[root@localhost sarg-2.3.7]# touch /usr/local/sarg/weizhi
[root@localhost sarg-2.3.7]# ln -s /usr/local/sarg/bin/sarg /usr/local/bin/
[root@localhost sarg-2.3.7]# sarg
SARG: 纪录在文件: 419, reading: 100.00%
SARG: 成功的生成报告在 /var/www/html/squid-reports/2020Sep06-2020Sep07
[root@localhost sarg-2.3.7]# cd /var/www/html/squid-reports/
[root@localhost squid-reports]# ls
2020Sep06-2020Sep07  images  index.html
[root@localhost squid-reports]# yum -y install httpd
[root@localhost squid-reports]# systemctl start httpd
[root@localhost squid-reports]# setenforce 0

用客户端访问squid,查看日志(先取消上面的acl访问策略)

[root@localhost squid-reports]# vim /etc/squid.conf
# Deny requests to certain unsafe ports
#http_access deny win
http_access deny !Safe_ports
[root@localhost squid-reports]# service squid reload

在这里插入图片描述执行周期计划性任务,再次查看报告

[root@localhost 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)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Ora_G/article/details/108454085