温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

squid代理服务器介绍与配置(理论+实践)二

发布时间:2020-06-24 16:05:01 来源:网络 阅读:132 作者:SiceLc 栏目:系统运维

ACL访问控制

ACL访问控制方式

  • 根据源地址、目标URL、文件类型等定义列表
    • acl 列表名称 列表类型 列表内容 ...
  • 针对已定义的acl列表进行限制
    • http_access allow或deny 列表名称 ...

ACL规则优先级

  • 当一个用户访问代理服务器时, Squid会顺序匹配Squid中定义的所有规则列表,一旦匹配成功,立即停止匹配。当所有规则都不匹配时,Squid会使用与最后一条相反的规则

常用的ACL列表类型

  • src → 源地址
  • dst → 目标地址
  • port → 目标地址
  • dstdomain → 目标域
  • time → 访问时间
  • maxconn → 最大并发连接
  • url_regex → 目标URL地址
  • Urlpath_regex → 整个目标URL路径

实验搭建

实验环境

squid服务器IP地址:ens33:192.168.80.184
                  ens36:192.168.10.1 (仅主机模式)
web服务器IP地址:192.168.80.151
client客户端IP地址:192.168.10.10  (仅主机模式)

在squid服务器上修改配置文件

root@squid ~]# vim /etc/squid.conf      //修改配置文件
# should be allowed
acl hostlocal src 192.168.10.10/32        //控制hostlocal10.10的主机
# Deny requests to certain unsafe ports
http_access deny hostlocal                //拒绝访问
[root@squid ~]# service squid reload       //重启squid服务

在测试机上访问web网页

squid代理服务器介绍与配置(理论+实践)二

sarg日志配置

在squid服务器上安装sarg

[root@squid ~]# mount.cifs //192.168.80.2/LNMP-C7 /mnt/      //挂载
Password for root@//192.168.80.2/LNMP-C7:  
[root@squid ~]# cd /mnt/
[root@squid mnt]# tar zxvf sarg-2.3.7.tar.gz -C /opt/        //解压
[root@squid mnt]# cd /opt/sarg-2.3.7/
[root@squid sarg-2.3.7]# yum install gd gd-devel -y       //安装gd库
[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       //编译安装

修改sarg配置文件

[root@squid sarg-2.3.7]# vim /etc/sarg/sarg.conf      //修改sarg配置文件
access_log /usr/local/squid/var/logs/access.log    //开启指定访问日志文件
title "Squid User Access Reports"                  //网页标题
output_dir /var/www/html/squid-reports             //报告输出目录
user_ip no                                        //使用用户名显示
exclude_hosts /usr/local/sarg/noreport            //不计入排序的站点列表文件
topuser_sort_field connect reverse               //top排序中有连接次数,访问字节,降序排列,升序是normal
overwrite_report no                        //同名日志是否覆盖
mail_utility mailq.postfix                //发送邮件报告命令
charset UTF-8                             //使用字符集
weekdays 0-6                              //top排行的时间周期
hours 0-23                               //top排行的时间周期
www_document_root /var/www/html           //网页根目录
[root@squid ~]# sarg                       //生成报告
SARG: 纪录在文件: 91, reading: 100.00%
SARG: 成功的生成报告在 /var/www/html/squid-reports/2019Dec11-2019Dec12
[root@squid sarg-2.3.7]# cd /var/www/html/squid-reports/        //切换到html目录下
[root@squid squid-reports]# ls
2019Dec11-2019Dec12   images  index.html
[root@squid squid-reports]# yum install httpd -y               //安装httpd服务
[root@squid squid-reports]# systemctl start httpd.service     //开启服务
[root@squid squid-reports]# systemctl stop firewalld.service      //关闭防火墙
[root@squid squid-reports]# setenforce 0                       //关闭selinux

在client客户机访问网页查看访问记录

squid代理服务器介绍与配置(理论+实践)二

在squid服务器上配置周期性计划任务,每天收集访问信息

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)

再次在client客户机访问网页查看访问记录

squid代理服务器介绍与配置(理论+实践)二

squid反向代理配置

实验环境

squid服务器IP地址:ens33:192.168.80.184
                  ens36:192.168.10.1 (仅主机模式)
web1服务器IP地址:192.168.80.151
web2服务器IP地址: 192.168.80.185
client客户端IP地址:192.168.10.10  (仅主机模式)

在web1服务器上编辑网页内容

root@web ~]# cd /var/www/html/
[root@web html]# echo "<h2>this is test web!</h2>" > index.html

client客户机上访问网页

squid代理服务器介绍与配置(理论+实践)二

在web2服务器上编辑网页内容

[root@web2 ~]# systemctl stop firewalld.service       //关闭防火墙
[root@web2 ~]# setenforce 0
[root@web2 ~]# yum install httpd -y                  //安装httpd服务
[root@web2 ~]# cd /var/www/html/                     //创建网页内容
[root@web2 html]# echo "<h2>this is test2 web!</h2>" > index.html 
[root@web2 html]# systemctl start httpd.service 

在squid服务器上配置反向代理

[root@localhost squid]# vim /etc/squid.conf
# Squid normally listens to port 3128
http_port 192.168.80.184:80 accel vhost vport        //监控本机80端口
cache_peer 192.168.80.151 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1        //节点服务器1最大访问30,权重1,别名web1
cache_peer 192.168.80.185 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1
cache_peer_domain web1 web2 www.yun.com     //访问yun.com匹配web1,web2节点
[root@localhost squid]# service squid restart      //重启squid服务

在client客户机的admin用户下配置解析域名地址,并设置代理

squid代理服务器介绍与配置(理论+实践)二
squid代理服务器介绍与配置(理论+实践)二
squid代理服务器介绍与配置(理论+实践)二squid代理服务器介绍与配置(理论+实践)二

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI