当前位置:网站首页>squid代理服務器
squid代理服務器
2022-06-27 21:14: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 透明代理的配置;
边栏推荐
- I haven't thought about the source for some time. After upgrading to the latest version 24, the data encryption problem is repeatedly displayed
- Love math experiment | Issue 8 - building of Singapore house price prediction model
- 难怪大家丢掉了postman而选择 Apifox
- At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
- 元宇宙虚拟数字人离我们更近了|华锐互动
- 一套系统,减轻人流集中地10倍的通行压力
- Flexible IP network test tool -- x-launch
- 【STL编程】【竞赛常用】【part 3】
- 爱数课实验 | 第六期-金融反欺诈案例研究
- Original translation | comparison of machine learning model service tools: kserve, Seldon core and bentoml
猜你喜欢

Recommended practice sharing of Zhilian recruitment based on Nebula graph

#夏日挑战赛# OpenHarmony HiSysEvent打点调用实践(L2)

海量数据出席兰州openGauss Meetup(生态全国行)活动,以企业级数据库赋能用户应用升级

The meta universe virtual digital human is closer to us | Sinovel interaction

Univision hyperinsight: Nuggets' $16.494 billion "gold hoe" in the observable market?

谈谈我写作生涯的画图技巧
Record a failure caused by a custom redis distributed lock

Cloud native Security Guide: learn kubernetes attack and defense from scratch

Massive data attended the Lanzhou opengauss meetup (ECOLOGICAL NATIONAL trip) activity, enabling users to upgrade their applications with enterprise level databases

通过CE修改器修改大型网络游戏
随机推荐
Share an experience of self positioning + problem solving
非常全面的DolphinScheduler(海豚调度)安装使用文档
How to reduce the weight transfer of unnecessary pages that users pay attention to?
Unity3D Button根据文本内容自适应大小
事件相关电位ERP的皮层溯源分析
1030 Travel Plan
教程|fNIRS数据处理工具包Homer2下载与安装
Unity3d button adapts the size according to the text content
1029 Median
爱数课实验 | 第八期-新加坡房价预测模型构建
SQL Server for循环用法
Openharmony hisysevent dotting and calling practice of # Summer Challenge (L2)
Leetcode 989. Integer addition in array form (simple)
Shell script controls the startup and shutdown of services - with detailed cases
爱数课实验 | 第九期-利用机器学习方法进行健康智能诊断
【STL编程】【竞赛常用】【part 2】
Practice of combining rook CEPH and rainbow, a cloud native storage solution
Oracle architecture summary
Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison
一段时间没用思源,升级到最新的 24 版后反复显示数据加密问题