当前位置:网站首页>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 透明代理的配置;
边栏推荐
- 爱数课实验 | 第六期-金融反欺诈案例研究
- CSDN skill tree experience and product analysis (1)
- 爱数课实验 | 第五期-基于机器学习方法的商品评论情感判定
- Implementation string mystring
- Univision hyperinsight: Nuggets' $16.494 billion "gold hoe" in the observable market?
- "Good voice" has been singing for 10 years. How can the Chinese language in the starry sky sing well in HKEx?
- 1029 Median
- 开启生态新姿势 | 使用 WrodPress 远程附件存储到 COS
- Record a failure caused by a custom redis distributed lock
- Show the comprehensive strength of strong products, and make the first show of 2022 Lincoln aviator in Southwest China
猜你喜欢

难怪大家丢掉了postman而选择 Apifox

展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀

Select auto increment or sequence for primary key selection?

KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架

mysql使用笔记一

What is a low code development platform? Why is it so hot now?

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

灵活的IP网络测试工具——— X-Launch

Summary of redis big key problem handling
Record a failure caused by a custom redis distributed lock
随机推荐
How to reduce the weight transfer of unnecessary pages that users pay attention to?
Flexible IP network test tool -- x-launch
What is a stack?
谈谈我写作生涯的画图技巧
[STL programming] [common competition] [Part 2]
低代码开发平台是什么?为什么现在那么火?
送你12个常用函数公式,用过的都说好
划重点!国产电脑上安装字体小技巧
教程|fNIRS数据处理工具包Homer2下载与安装
分享下我是如何做笔记的
pfSense Plus22.01中文定制版发布
Cocoscreator plays audio and synchronizes progress
Flutter隐藏AppBar的返回按钮
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?
Leetcode 989. Integer addition in array form (simple)
Show the comprehensive strength of strong products, and make the first show of 2022 Lincoln aviator in Southwest China
It took me 6 months to complete the excellent graduation project of undergraduate course. What have I done?
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
动物养殖生产虚拟仿真教学系统|华锐互动
MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)