本文共 4484 字,大约阅读时间需要 14 分钟。
Squid提供了强大的代理控制机制,通过合理设置ACL(Access Control List,访问控制列表)并进行限制,可以针对源地址、目标地址、访问的URL路径、访问的时间等各种条件进行过滤。
定义格式:acl 列表名称 列表类型 列表内容 …
2.1、直接在squid的配置文件里修改
vim /etc/squid.confacl localhost src 192.168.158.10/32 #针对固定的源ip地址acl MYLAN src 192.168.158.0/24 #针对某一网段acl destionhost dst 192.168.158.30/32 #针对具体的目标ip地址acl MC20 maxconn 20 #访问的最大并发连接数量acl BURL url_regex -i ^rtsp:// ^emule:// #正则表达式的访问协议acl PURL urlpath_regex -i \.mp3$ \.mp4$ \.rmvb$ #访问的文件资源末尾acl work time MTWHF 08:30-17:30 #访问时间MTWHF:周一到周五MTWHFAS:周一到周日http_access deny localhost #拒绝列表 (注意置顶)
mkdir /etc/squid #启用对象列表管理vim dest.list 192.168.158.10 192.168.158.20 192.168.158.30 #目标webvim /etc/squid.conf acl destionhost dst "/etc/squid/dest.list" http_access deny destionhost #拒绝列表 (注意置顶)
sarg软件用来分析squid服务的日志
在上篇博客的基础上做squid反向代理实验,安装squid的具体步骤见上篇博客链接:squid代理介绍----传统代理、squid代理-----透明代理模式//图像处理yum -y install gd gd-devel httpd //解压安装包tar zxvf sarg-2.3.7.tar.gz -C /opt/cd /opt/sarg-2.3.7/./configure --prefix=/usr/local/sarg \--sysconfdir=/etc/sarg \--enable-extraprotection #额外安全防护 make && make install
vim /etc/squid.confacl localhost src 192.168.10.10/32 #针对固定的源ip地址acl MYLAN src 192.168.220.0/24 #针对某一网段acl destionhost dst 192.168.220.130/32 #针对具体的目标ip地址acl MC20 maxconn 20 #访问的最大并发连接数量acl BURL url_regex -i ^rtsp:// ^emule:// #正则表达式的访问协议acl PURL urlpath_regex -i \.mp3$ \.mp4$ \.rmvb$ #访问的文件资源末尾acl work time MTWHF 08:30-17:30 #访问时间MTWHF:周一到周五MTWHFAS:周一到周日http_access deny localhost #拒绝列表 (注意置顶)
sarg软件用来分析squid服务的日志
在上篇博客的基础上做squid反向代理实验,安装squid的具体步骤见上篇博客链接:squid代理介绍----传统代理、squid代理-----透明代理模式//图像处理yum -y install gd gd-devel httpd //解压安装包tar zxvf sarg-2.3.7.tar.gz -C /opt/cd /opt/sarg-2.3.7/./configure --prefix=/usr/local/sarg \--sysconfdir=/etc/sarg \--enable-extraprotection #额外安全防护 make && make install
vi /etc/sarg/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代替用户ID184 topuser_sort_field BYTES reverse ###升序排列190 user_sort_field BYTES reverse 206 exclude_hosts /usr/local/sarg/noreport ###设置不生成报告的主机257 overwrite_report no289 mail_utility mailx ###指定发邮件命令434 charset UTF-8518 weekdays 0-6 ###指定top排序星期周期523 hours 7-12,14,16,18-20 ###指定top排序时间周期633 www_document_root /var/www/html ###网页根目录touch /usr/local/sarg/noreport ###建立不生成报告的主机列表文件ln -s /usr/local/sarg/bin/sarg /usr/local/bin///启动sarg日志分析和squid网页服务sargsystemctl start httpd
在客户端机浏览器输入:http://192.168.158.10/squid-reports/index.htmlsquid服务器设置周期性任务crontab -e */1 * * * * /usr/local/bin/sarg #这里为了效果快速呈现出,设置了每隔1分钟
传统和透明是为客户端服务的,借助squid加快访问web服务的速度,或者是公司内部对员工上网行为做限制使用的。
反向代理模式下的squid的服务对象是web服务器,通过squid来隐藏真实web服务器IP,加快客户的访问速度,还有负载均衡的功能。 反向代理的设置,需要通过三个步骤来完成:一台squid服务器
两台web服务器,web1:192.168.158.20 web2:192.168.158.30 一台win10客户端//安装httpdyum install httpd -y//设置网页内容echo "this is test02 web" > /var/www/html/index.html #web1换一下数字route add -net 192.168.100.0/24 gw 192.168.158.10 #静态路由//开启web服务systemctl start httpd
//设置防火墙规则systemctl start firewalldiptables -L #查看防火墙规则iptables -Fiptables -t nat -Fiptables -I INPUT -p tcp --dport 3128 -j ACCEPTvim /etc/squid.conf#去掉透明代理设置反向代理http_port 192.168.158.10:80 accel vhost vport#节点服务器1最大访问30,权重1,别名web1cache_peer 192.168.158.20 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1#节点服务器2最大访问30,权重1,别名web2cache_peer 192.168.158.30 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web2#访问yun.com匹配web1,web2节点cache_peer_domain web1 web2 www.yun.comservice squid restart
转载地址:http://gydaf.baihongyu.com/