Squidcache(簡稱squid) 是一個流行的自由軟件(GNU 通用公共許可證)的代理服務器和Web緩存服務器. Squid有廣泛的用途.從作爲網頁服務器的前置cache服務器緩存相關請求來提高Web服務器的速度到爲一組人共享網絡資源而緩存萬維網,域名系統和其它網絡搜索,到通過過濾流量幫助網絡安全,到局域網通過代理上網. squid主要涉及用於unix一類系統運行
模式: c/s 模式
squid服務端安裝:
1002 rpm -ivh/mnt/Packages/squid-3.1.10-19.el6_4.x86_64.rpm
1003 ls/etc/squid/squid.conf
1004 /etc/init.d/squid start
1005 netstat -auntp | grep 3128 也可以用lsof -i:3128 顯示所有打開3128端口的進程
配置 squid 正向代理服務器 局域網--外部
搭建squid代理服務器 使內網主機192.168.2.2 能夠通過 oca上的squid代理服務器加速上網
配置服務端網絡:oca 添加eth1 配置 ip 192.168.2.1 vmnet4
客戶端 client 添加eth1 配置ip 192.168.2.2 網關 192.168.2.1 vmnet4
用 setup 命令在網絡配置 配上 ip 掩碼 dns
servicesquid start
chkconfigsquid on
測試:
在瀏覽器中打開百度可以訪問
ping www.baidu.com 是不通的
例2: 配置透明squid 代理提升訪問速度
客戶端不用在瀏覽器裏指定代理服務器的ip地址和端口號,就可以直接訪問公網上的網站服務器
透明代理= squid +iptables
打開透明代理功能
vim/etc/squid/squid.conf
加上 transparent
servicesquid restart
開啓路由轉發功能
vim/et/sysctl.conf
配置 iptables
iptables-t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to 192.9.100.84
iptables-t nat -A PREROUTING -s 192.168.2.0/24 -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
測試:
把網頁代理取消
訪問www.baidu.com
例3 :配置 squid 反向代理加速內網web 服務器訪問速度
反向代理:cdn 藍汛 網宿
反向代理服務器: 要求內存足夠大,硬盤要夠快 不需要太大
阿里 凌動處理器 atom ssd
回源 多長時間跟源更新
讓外網中192.168.1.224/24 訪問192.168.1.63 代理服務器
192.168.1.63代理服務器緩存 192.168.2.2web服務器中的數據
實現 oca 給 client 加速80 和 81 兩個服務
只加速靜態頁面 或視頻 。用戶登錄 註冊碼 不能加速
新開一個虛擬機windows系統
在c:\windows\system32\driver\etc\hosts 文件裏加入兩行
192.9.100.84 www.serverA.com
192.9.100.84 www.serverB.com
http_accessallow all
#http_accessdeny all
#Squid normally listens to port 3128
#http_port3128 transparent
http_port8000 vhost 打開虛擬主機支持
cache_peer 192.168.2.2 parent 800 no-query originserver weight=1 name=a
cache_peer 192.168.2.2 parent 810 no-query originserver weight=1 name=b
cache_peer_domain awww.serverA.com
cache_peer_domain bwww.serverB.com
#讓squuid 服務器知道
從客戶端發來的請求 如果是www.serverA。com 則 squid向 192.168.2.2的端口80發送請求;
從客戶端發來的請求 如果是www.serverB。com 則 squid向 192.168.2.2的端口81發送請求;
cache_peer_accessa allow all
cache_peer_accessb allow all
#cache_peer設置: 允許其他cache機 訪問a和b
servicesquid restart