当前位置:网站首页>squid代理服务器
squid代理服务器
2022-06-27 18:55:00 【墨天轮】
一、squid代理服务器概述;
二、squid代理服务器模式;
三、案例:搭建squid代理传统代理服务器;
一、squid代理服务器概述;
概述:Squid Cache(简称为Squid)是http代理服务器软件。Squid用途广泛,可以作为缓存服务器也可以作为缓存代理服务器,代理用户向web服务器请求数据并进行缓存,可以过滤流量帮助网络安全,也可以作为代理服务器链中的一环,向上级代理转发数据或直接连接互联网。还也可以用在局域网中,使局域网用户通过代理上网;
Squid将数据缓存在内存中,同时也缓存DNS查寻的结果,除此之外,它还支持非模块化的DNS查询,对失败的请求进行消极缓存。Squid支持SSL,支持访问控制;
优势:
1.提高客户端访问速度;
2.隐蔽内部主机的ip地址;
3.部署简单,可以实现访问控制;
二、squid代理服务器模式;
传统代理:

透明代理:

反向代理:

三、案例:搭建squid传统代理服务器;
案例拓扑:

案例环境:
系统类型 | IP地址 | 主机名 | 所需软件 |
Centos 6.5 | 192.168.100.100 | lwh.linuxfan.cn | iptables规则 |
Centos 7.4 1708 64bit | 192.168.100.101 | squid.linuxfan.cn | squid-3.4.6.tar.gz |
win7-1 | 192.168.100.200 | IE浏览器 |
案例步骤:
Ø搭建基础环境,配置拓扑图(网络参数、防火墙规则等);
Ø安装squid节点的squid服务;
Ø配置squid节点的squid服务并启动;
Ø测试内网win7客户端是否能够正常上网;
Ø配置内网win7客户端的代理服务器;
Ø测试内网win7客户端是否能够正常上网;
Ø扩展:当内部客户端主机为linux系统,设置代理方法如下:
Ø自主学习:1.squid ACL的配置,实现访问控制;
Ø自主学习:2.squid 透明代理的配置;
Ø搭建基础环境,配置拓扑图(网络参数、防火墙规则等);
[[email protected] ~]# ip a|grep 192.168.100.101
inet 192.168.100.101/24 brd 192.168.100.255 scope global eth0
[[email protected] ~]# ip r|grep 192.168.100.100
default via 192.168.100.100 dev eth0 proto static metric 100
[[email protected] ~]# ping -c 2 www.baidu.com
PING www.a.shifen.com (111.13.100.92) 56(84) bytes of data.
64 bytes from 111.13.100.92 (111.13.100.92): icmp_seq=1 ttl=127 time=16.1 ms
64 bytes from 111.13.100.92 (111.13.100.92): icmp_seq=2 ttl=127 time=17.7 ms




Ø安装squid节点的squid服务;
[[email protected] ~]# ls squid-3.4.6.tar.gz
squid-3.4.6.tar.gz
[[email protected] ~]# tar zxvf root/squid-3.4.6.tar.gz -C usr/src/
[[email protected] ~]# cd usr/src/squid-3.4.6
[[email protected] ~]# ./configure --prefix=/usr/local/squid --sysconfdir=/etc --enable-arp-acl --enable-linux-netfilter --enable--linux-tproxy --enable-async-io=100 --enable-err-language="Simplify_Chinese" --enable-underscore --enable-poll --enable-gnuregex
[[email protected] ~]# make &&make install
注解:
--prefix:指定安装路径
--sysconfdir:指定配置文件路径
--enable-arp-acl :可以在配置文件中指定acl规则,实现访问控制
--enable-linux-netfilter:可以使用iptables的内核过滤
--enable-linux-tproxy:支持透明模式
--enable-async-io:异步I/O,提升存储性能,指定缓存空间大小
--enable-err-language:错误信息显示的语言
--enable-underscore:允许URL中有下划线
--enable-poll:使用Poll模式,提升性能
--enable-gnregex:使用GNU正则表达式
Ø配置squid节点的squid服务并启动;
[[email protected] ~]# ln -s usr/local/squid/sbin/* usr/local/sbin/
[[email protected] ~]# useradd -M -s sbin/nologin squid
[[email protected] ~]# chown -R squid:squid /usr/local/squid/var/ ##将squid缓存路径设置归属
[[email protected] ~]# vi /etc/squid.conf ##在末尾追加
visible_hostname squid.linuxfan.cn ##主机名,避免启动过程中的反向解析
cache_mem 64 MB ##额外提供给squid使用的内存,squid的内存总占用为 X *10+15+“cache_mem”,其中X为squid的cache占用的容量(以GB为单位),比如下面的cache大小是100M,即0.1GB,则内存总占用为0.1*10+15+64=80M,推荐大小为物理内存的1/3-1/2或更多。
maximum_object_size 4 MB ##设置squid磁盘缓存最大文件,超过4M文件不保存硬盘
minimum_object_size 0 KB ##设置squid磁盘缓存最小文件
maximum_object_size_in_memory 4096 KB ##设置squid内存缓存最大文件,超过4M的文件不保存到内存
cache_dir ufs /usr/local/squid/var/cache/squid 100 16 256 ##定义squid的cache存放路径 、cache目录容量(单位M)、一级缓存目录数量、二级缓存目录数量
:wq
[[email protected] ~]# sed -i '/^http_port/a cache_effective_user squid\ncache_effective_group squid' /etc/squid.conf
[[email protected] ~]# sed -i '55ahttp_access allow all' /etc/squid.conf ##设置acl策略为允许所有,必须在deny前
[[email protected] ~]# sed -i '59areply_body_max_size 10 MB' /etc/squid.conf ##允许下载最大文件大小为10M
[[email protected] ~]# vi /etc/init.d/squid
#!/bin/bash
# chkconfig: 35 90 25
# config file:/etc/squid.conf
# Description: squid - internet object cache.
PID="/usr/local/squid/var/run/squid.pid"
CONF="/etc/squid.conf"
CMD="/usr/local/squid/sbin/squid"
case "$1" in
start)
netstat -utpln |grep squid &>/dev/null
if [ $? -eq 0 ];then
echo "squid is running."
else
echo "squid is starting."
$CMD
fi
;;
stop)
$CMD -k kill &>/dev/null
rm -rf $PID &>/dev/null
echo "squid is stoped."
;;
status)
[ -f $PID ] &>/dev/null
if [ $? -eq 0 ];then
netstat -anpt |grep squid
else
echo "squid is not running" &&/bin/false
fi
;;
restart)
$0 stop
$0 start
;;
reload)
$CMD -k reconfigure
;;
check)
$CMD -k parse
;;
*)
echo "Usage:$0 {start|stop|restart|reload|check|status}"
exit 1
;;
esac
[[email protected] ~]# chmod +x /etc/init.d/squid
[[email protected] ~]# chkconfig --add squid
[[email protected] ~]# chkconfig squid on
[[email protected] ~]# squid -z ##初始化缓存目录
[[email protected] ~]# squid ##启动服务
[[email protected] ~]# netstat -utpln |grep 3128
tcp 0 0 :::3128 :::* LISTEN 35833/(squid-1)
Ø测试内网win7客户端是否能够正常上网;

Ø配置内网win7客户端的代理服务器;

Ø测试内网win7客户端是否能够正常上网;


Ø扩展:当内部客户端主机为linux系统,设置代理方法如下:
[[email protected] ~]# cat <
HTTP_PROXY=http://192.168.100.101:3128
HTTPS_PROXY=http://192.168.100.101:3128
FTP_PROXY=http://192.168.100.101:3128
NO_PROXY=192.168.100.100
export HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY
END
[[email protected] ~]# source /etc/profile
Ø自主学习:1.squid ACL的配置,实现访问控制;
Ø自主学习:2.squid 透明代理的配置;
边栏推荐
- CSDN 技能树使用体验与产品分析(1)
- Share how I take notes
- shell脚本控制服务的启动和关闭 - 具备详细案例
- 1029 Median
- 2021全球独角兽榜发布:中国301家独角兽企业全名单来了!
- Explore gaussdb and listen to what customers and partners say
- How to reduce the weight transfer of unnecessary pages that users pay attention to?
- Navicat Premium连接问题--- Host ‘xxxxxxxx‘ is not allowed to connect to this MySQL server
- 探秘GaussDB,听听客户和伙伴怎么说
- 优维HyperInsight:掘金164.94亿美元可观测市场的“金锄头”?
猜你喜欢

How to do a good job of gateway high availability protection in the big promotion scenario
I haven't thought about the source for some time. After upgrading to the latest version 24, the data encryption problem is repeatedly displayed

Show the comprehensive strength of strong products, and make the first show of 2022 Lincoln aviator in Southwest China

智联招聘的基于 Nebula Graph 的推荐实践分享

Postman Chinese tutorial (postman Chinese version)
![[STL programming] [common competition] [Part 3]](/img/15/0c397d74128268e17897615ad1c84e.png)
[STL programming] [common competition] [Part 3]
一段时间没用思源,升级到最新的 24 版后反复显示数据加密问题

BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比

Unity3d button adapts the size according to the text content

Unity3D Button根据文本内容自适应大小
随机推荐
Csdn Skills Tree use Experience and Product Analysis (1)
1029 Median
教程|fNIRS数据处理工具包Homer2下载与安装
基于微信小程序的高校党员之家服务管理系统系统小程序#毕业设计,党员,积极分子,学习,打卡,论坛
pfSense Plus22.01中文定制版发布
一套系统,减轻人流集中地10倍的通行压力
SQL reported an unusual error, which confused the new interns
Is it safe to open an account and buy stocks on the Internet? New to stocks, no guidance
SQL reported an unusual error, which confused the new interns
Love math experiment | phase 9 - intelligent health diagnosis using machine learning method
Character interception triplets of data warehouse: substrb, substr, substring
When developing digital collections, how should cultural and Museum institutions grasp the scale of public welfare and Commerce? How to ensure the security of cultural relics data?
[array]bm99 clockwise rotation matrix - simple
体验Navicat Premium 16,无限重置试用14天方法(附源码)
Navicat premium connection problem --- host 'XXXXXXXX' is not allowed to connect to this MySQL server
It took me 6 months to complete the excellent graduation project of undergraduate course. What have I done?
Flood fighting and disaster relief, overcoming difficulties, and City United premium products rushed to the aid of Yingde to donate loving materials
分享一次自己定位 + 解决问题的经历
#yyds干货盘点#SQL 子查询
Installation and configuration of grayog new generation log collection early warning system