Squid ACL访问控制与sarg日志、反向代理

ACL访问控制

访问控制列表(ACL)是一种基于包过滤的访问控制技术,它可以根据设定的条件对接口上的数据包进行过滤,允许其通过或丢弃。访问控制列表被广泛地应用于路由器和三层交换机,借助于访问控制列表,可以有效地控制用户对网络的访问,从而最大程度地保障网络安全。

ACL访问控制的步骤
使用acl配置项定义需要控制的条件
通过http_access配置项对已定义的列表做允许或拒绝的访问控制

ACL解释
acl:列表名称 列表类型 列表内容
src:源地址
dst:目标地址
port: 目标端口
dstdomain:目标域
time:访问时间
maxconn:最大并发连接
url_regex:目标URL地址
urlpath_regex:整个目标URL路径

访问控制配置

根据源地址、目标URL、文件类型等定义列表
acl 列表名称 列表类型 列表内容

针对已定义的acl列表进行限制
http_access allow或deny 列表名称...
[root@localhost ~]# vim /etc/squid.conf
#在acl字段添加
acl win src 192.168.100.100/32	#添加该IP后该地址无法正常访问

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

acl netlocal dst "/etc/squid/IP.list" #添加绝对路径
也可指定一个存放多个IP地址的文件进行群禁止

Squid日志分析工具Sarg

Sarg(Squid Analysis Report Generator),是一款Squid 日志分析工具,采用HTML 格式,详细列出每一位用户访问Internet 的站点信息、时间占用信息、排名、连接次数、访问量等。

squid服务器上安装sarg

[root@localhost bao]# tar zxvf sarg-2.3.7.tar.gz 
[root@localhost sarg-2.3.7]# ./configure  \
> --prefix=/usr/local/sarg \	#指定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/aaa	#不计入排序站点位置
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/aaa
[root@localhost sarg-2.3.7]# ln -s /usr/local/sarg/bin/sarg /usr/local/bin/
[root@localhost sarg-2.3.7]# sarg
SARG: 纪录在文件: 126, reading: 100.00%
SARG: 成功的生成报告在 /var/www/html/squid-reports/2020Sep06-2020Sep06
[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

在这里插入图片描述

反向代理

反向代理服务器位于用户与目标服务器之间,但是对于用户而言,反向代理服务器就相当于目标服务器,即用户直接访问反向代理服务器就可以获得目标服务器的资源。同时,用户不需要知道目标服务器的地址,也无须在用户端作任何设定。反向代理服务器通常可用来作为Web加速,即使用反向代理作为Web服务器的前置机来降低网络和服务器的负载,提高访问效率。

反向代理作用

  • 缓存网页对象,减少重复请求
  • 将互联网请求轮训或按权重分配到内网Web服务器
  • 代理用户请求,避免用户直接访问Web服务器,提高安全
搭建两台web服务器
192.168.110.20	192.168.110.25
修改squid服务器配置文件
[root@squid sarg]# vim /etc/squid.conf
# Squid normally listens to port 3128
http_port 192.168.110.15:80 accel vhost vport #监控本机80端口
cache_peer 192.168.110.20parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1 #节点服务器1最大访问30,权重1,别名web1
cache_peer 192.168.110.25 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web2 #节点服务器2最大访问30,权重1,别名web1
[root@squid sarg]# service squid restart 
正在关闭 squid...
正在启动 squid...
[root@squid sarg]# netstat -ntap |grep 80
tcp        0      0 192.168.179.124:80      0.0.0.0:*               LISTEN      24528/(squid-1) 

在这里插入图片描述

扫描二维码关注公众号,回复: 11667945 查看本文章

猜你喜欢

转载自blog.csdn.net/CN_PanHao/article/details/108454483