squid缓存服务器————sarg日志

news/2024/7/23 8:54:49 标签: linux, squid, 缓存服务器, 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)

刷新验证
在这里插入图片描述


http://www.niftyadmin.cn/n/1397516.html

相关文章

squid缓存服务器————反向代理

如果 Squid 反向代理服务器中缓存了该请求的资源,则将该请求的资源直接返回给客户端, 否则反向代理服务器将向后台的 WEB 服务器请求资源,然后将请求的应答返回给客户端, 同时也将该应答缓存在本地,供下一个请求者使用…

理论+实操:NoSQL之redis概述+部署+演示基本操作

NoSQL之Redis配置与优化 文章目录一:关系型数据库与非关系型数据库1.1 关系型数据库1.2 非关系型数据库1.3 非关系型数据库产生背景二:Redis简介三:redis 的优点四:部署redis安装编译工具,解压redis,make安…

理论+实操:NoSQL之redis配置参数+持久化详解

一:参数配置 [rootlocalhost redis]# vim /etc/redis/6379.conf 219 save 900 1 #900秒进行一次写操作,也就是保存一次220 save 300 10 #执行10次写操作,300秒一次221 save 60 10000 #执行10000次写操作,60秒一次242 rdbcompres…

实验:haproxy搭建nginx配合nginx群集实现高并发访问

三台服务器,一台做代理服务器,两台做web [rootlamp ~]# hostnamectl set-hostname haproxy [rootlamp ~]# su[rootnginx ~]# hostnamectl set-hostname nginx1 [rootnginx ~]# su [rootnginx1 ~]# [rootlocalhost ~]# hostnamectl set-hostname nginx2 …

cobbler自动装机

挂载共享目录,安装epel源环境 [rootnginx ~]# mkdir /abc [rootnginx ~]# mount.cifs //192.168.254.10/linuxs /abc Password for root//192.168.254.10/linuxs: [rootnginx ~]# rpm -ivh /abc/epel-release-latest-7.noarch.rpm 警告:/abc/epel-re…

BGP-ISIS实验

(控制层面)ISIS 主要功能跑底层框架路由网段:直连、环回地址 (数据层面)IBGP 直接宣告的方式,将业务网段发布 业务网段不在ISIS里面跑 BARS/SR中,它是有好多条业务网段,上万条 如…

理论+实操华为防火墙

华为防火墙 文章目录一:华为防火墙产品介绍二:防火墙的工作原理2.1 防火墙的工作模式2.2 华为防火墙安全区域划分2.3 防火墙Inbound和Outbound2.4 状态化信息2.5 安全策略三:设备管理方式3.1 AAA(Authentication Authorization Ac…

理论+实操:防火墙NAT策略

文章目录一:NAT概述1.1 NAT分类1.1.1 NAT No-PAT1.1.2 NAPT(Network Address and Port Translation,网络地址和端口转换)1.1.3 出接口地址 (Easy-IP)1.1.4 NAT Server1.1.5 Smart NAT (智能转换…