本文共 3477 字,大约阅读时间需要 11 分钟。
Squid提供了强大的代理控制机制,通过合理设置ACL(Access Control List,访问控制列表)并进行限制,可以针对源地址、目标地址、访问的URL路径、访问的时间等各种条件进行过滤。
ACL访问控制的步骤:
vim /etc/squid.confacl localhost src 192.168.127.10/32 #针对固定的源ip地址acl MYLAN src 192.168.127.0/24 #针对某一网段acl destionhost dst 10.0.0.20/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 10.0.0.10 10.0.0.20 10.0.0.30 #目标webvim /etc/squid.conf acl destionhost dst "/etc/squid/dest.list" http_access deny destionhost #拒绝列表 (注意置顶)
sarg软件用来分析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
1、在客户端机浏览器输入:http://10.0.0.10/squid-reports/index.html
2、squid服务器设置周期性任务
crontab -e */1 * * * * /usr/local/bin/sarg #这里为了效果快速呈现出,设置了每隔1分钟
传统和透明是为客户端服务的,借助squid加快访问web服务的速度,或者是公司内部对员工上网行为做限制使用的。
反向代理模式下的squid的服务对象是web服务器,通过squid来隐藏真实web服务器IP,加快客户的访问速度,还有负载均衡的功能。 反向代理的设置,需要通过三个步骤来完成: DNS解析 SQUID配置 端口转发一台squid服务器 10.0.0.20
两台web服务器,web1:10.0.0.10 web2:10.0.0.301、web服务器部署
#安装httpdyum install httpd -y#设置网页内容echo "this is test02 web" > /var/www/html/index.html #web1换一下数字#开启web服务systemctl start httpd
2、squid反向代理配置
#设置防火墙规则systemctl start firewalldiptables -L #查看防火墙规则iptables -Fiptables -t nat -Fiptables -I INPUT -p tcp --dport 3128 -j ACCEPTvim /etc/squid.conf#去掉透明代理设置反向代理http_port 10.0.0.20:80 accel vhost vport#节点服务器1最大访问30,权重1,别名web1cache_peer 10.0.0.10 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1#节点服务器2最大访问30,权重1,别名web2cache_peer 10.0.0.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
3、客户端验证
在客户端的浏览器输入web的两个IP地址可以访问代理服务器。客户机添加hosts文件映射
172.16.1.10 www.hhy.com
转载地址:http://oekgf.baihongyu.com/