日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

squid 不缓存特定页面_【零基础学云计算】squid代理服务器介绍与配置(理论+实践)一...

發(fā)布時間:2024/9/15 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 squid 不缓存特定页面_【零基础学云计算】squid代理服务器介绍与配置(理论+实践)一... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

緩存的概述

Web代理的工作機(jī)制

  • 緩存網(wǎng)頁對象,減少重復(fù)請求


代理的基本類型

  • 傳統(tǒng)代理:適用于Internet,需明確指定服務(wù)端
  • 透明代理:客戶機(jī)不需要指定代理服務(wù) 器的地址和端口,而是通過默認(rèn)路由、防火墻策略將Web訪問重定向給代理服務(wù)器處理

使用代理的好處

  • 提高Web訪問速度
  • 隱藏客戶機(jī)的真實(shí)IP地址

傳統(tǒng)代理實(shí)驗搭建

實(shí)驗環(huán)境

squid服務(wù)器IP地址:192.168.80.179 web服務(wù)器IP地址:192.168.80.151 client測試機(jī)IP地址:192.168.80.135

在squid服務(wù)器上安裝squid服務(wù)

[root@squid ~]# mkdir /abc [root@squid ~]# mount.cifs //192.168.80.2/LNMP-C7 /abc/ //掛載 [root@squid ~]# cd /abc/ [root@squid abc]# tar zxvf squid-3.4.6.tar.gz -C /opt //解壓 [root@squid abc]# yum install gcc gcc-c++ make -y //安裝環(huán)境組件 [root@squid abc]# cd /opt/squid-3.4.6 [root@squid squid-3.4.6]# ./configure --prefix=/usr/local/squid //指定安裝路徑 --sysconfdir=/etc //配置文件目錄 --enable-arp-acl //支持acl訪問控制列表 --enable-linux-netfilter //支持網(wǎng)絡(luò)篩選 --enable-linux-tproxy //支持透明 --enable-async-io=100 //IO優(yōu)化 --enable-err-language="Simplify_Chinese" //報錯顯示簡體中文 --enable-underscore --enable-poll --enable-gnuregex //支持正則表達(dá) [root@squid squid-3.4.6]# make && make install //編譯安裝 [root@squid squid-3.4.6]# ln -s /usr/local/squid/sbin/* /usr/local/sbin/ //復(fù)制命令便于系統(tǒng)識別 [root@squid squid-3.4.6]# useradd -M -s /sbin/nologin squid //創(chuàng)建系統(tǒng)用戶 [root@squid squid-3.4.6]# chown -R squid.squid /usr/local/squid/var/ //給目錄所有文件屬主屬組權(quán)限

修改squid服務(wù)配置文件,配置優(yōu)化啟動方式

[root@squid squid-3.4.6]# vim /etc/squid.conf //進(jìn)入修改squid配置文件 # And finally deny all other access to this proxy http_access allow all //添加此項 #http_access deny all //注釋,允許終端訪問# Squid normally listens to port 3128 http_port 3128 cache_effective_user squid //指定用戶squid cache_effective_group squid //指定組 [root@squid squid-3.4.6]# squid -k parse //檢查配置文件語法 [root@squid squid-3.4.6]# squid -z //初始化緩存目錄 [root@squid squid-3.4.6]# squid //開啟服務(wù) [root@squid squid-3.4.6]# netstat -ntap | grep 3128 //查看squid端口 [root@squid squid-3.4.6]# cd /etc/init.d/ [root@squid init.d]# vim squid //編輯service啟動squid服務(wù)的腳本文件 #!/bin/bash #chkconfig: 2345 90 25 PID="/usr/local/squid/var/run/squid.pid" //PID文件進(jìn)程號文件路徑 CONF="/etc/squid.conf" //主配置文件路徑 CMD="/usr/local/squid/sbin/squid" //服務(wù)啟動命令路徑case "$1" in start)netstat -ntap | grep squid &> /dev/nullif [ $? -eq 0 ]then echo "squid is running"elseecho "正在啟動 squid...." $CMDfi;; stop)$CMD -k kill &> /dev/null //關(guān)閉squid服務(wù)rm -rf $PID &> /dev/null //刪除PID文件;; status)[ -f $PID ] &> /dev/nullif [ $? -eq 0 ]thennetstat -ntap | grep squidelseecho "squid is not running"fi;; restart)$0 stop &> /dev/nullecho "正在關(guān)閉 squid..."$0 start &> /dev/nullecho "正在啟動 squid...";; reload)$CMD -k reconfigure //重載配置文件;; check)$CMD -k parse //檢查語法;; *)echo "用法:$0{start|stop|reload|status|check|restart}";; esac [root@squid init.d]# chmod +x squid //給執(zhí)行權(quán)限 [root@squid init.d]# chkconfig --add squid //添加到service管理中 [root@squid init.d]# chkconfig --level 35 squid on //設(shè)置開機(jī)自啟

設(shè)置傳統(tǒng)代理配置

[root@squid init.d]# vim /etc/squid.conf //修改主配置文件 # Squid normally listens to port 3128 http_port 3128 cache_mem 64 MB //內(nèi)存空間大小 reply_body_max_size 10 MB //允許下載最大文件大小 maximum_object_size 4096 KB //允許保存緩存空間最大對象大小 [root@squid init.d]# service squid restart [root@squid init.d]# iptables -L //查看表內(nèi)容 [root@squid init.d]# iptables -F //清空表緩存 [root@squid init.d]# setenforce 0 [root@squid init.d]# iptables -I INPUT -p tcp --dport 3128 -j ACCEPT //允許3128端口 [root@squid init.d]# service squid reload //重載配置文件

在web服務(wù)器上安裝apache服務(wù)

[root@web ~]# systemctl stop firewalld.service //關(guān)閉防火墻 [root@web ~]# setenforce 0 [root@web ~]# yum install httpd -y //安裝apache服務(wù) [root@web ~]# systemctl start httpd.service //啟動服務(wù)

使用client訪問web網(wǎng)頁

在web服務(wù)器日志文件中查看訪問日志文件

[root@web ~]# cd /etc/httpd/logs/ //查看日志文件 [root@web logs]# vim access_log //此時是135地址訪問的

修改客戶機(jī)瀏覽器代理設(shè)置

再次回到web服務(wù)器日志文件中查看訪問日志文件

[root@web ~]# cd /etc/httpd/logs/ //查看日志文件 [root@web logs]# vim access_log //此時是179代理服務(wù)器訪問的

透明代理實(shí)驗搭建

實(shí)驗環(huán)境

quid服務(wù)器IP地址:ens33:192.168.80.184ens36:192.168.10.1 (僅主機(jī)模式) web服務(wù)器IP地址: 192.168.80.151 clientIP地址:192.168.10.10 (僅主機(jī)模式)

在squid服務(wù)器上添加一塊網(wǎng)卡,并配置IP地址

[root@squid ~]# cd /etc/sysconfig/network-scripts/ [root@squid network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36 [root@squid network-scripts]# vim ifcfg-ens36 //修改ens36IP信息 刪除uuid修改33為36 BOOTPROTO=static //設(shè)置靜態(tài) IPADDR=192.168.10.1 NETMASK=255.255.255.0 [root@squid network-scripts]# service network restart //重啟網(wǎng)絡(luò)服務(wù) [root@squid network-scripts]# vim /etc/sysctl.conf //開啟路由轉(zhuǎn)發(fā) net.ipv4.ip_forward=1 [root@squid network-scripts]# sysctl -p //加載

在web服務(wù)器上指定靜態(tài)路由

[root@web ~]# route add -net 192.168.10.0/24 gw 192.168.80.184 ##添加靜態(tài)路由

在squid服務(wù)器上設(shè)置透明代理

root@squid network-scripts]# vim /etc/squid.conf //設(shè)置配置文件 http_port 192.168.10.1:3128 transparent //設(shè)置透明代理 cache_effective_user squid cache_effective_group squid [root@squid network-scripts]# service squid stop //關(guān)閉開啟squid服務(wù) [root@squid network-scripts]# service squid start [root@squid network-scripts]# iptables -F //清空表緩存 [root@squid network-scripts]# iptables -t nat -F [root@squid network-scripts]# iptables -t nat -I PREROUTING -i ens36 -s 192.168.10.0/24 -p tcp --dport 80 -j REDIRECT --to 3128 //定義規(guī)則入口ens36,80端口重定向到3128 [root@squid network-scripts]# iptables -t nat -I PREROUTING -i ens36 -s 192.168.10.0/24 -p tcp --dport 443 -j REDIRECT --to 3128 //https443端口 [root@squid network-scripts]# iptables -I INPUT -p tcp --dport 3128 -j ACCEPT //允許3128端口訪問

client客戶端測試

[root@web ~]# cd /var/log/httpd/ [root@web httpd]# vim access_log ##查看訪問日志信息,此時訪問地址變?yōu)?84訪問web服務(wù)

寫在最后:

本專欄所有文章均為南京課工場學(xué)員投稿,如有問題歡迎指出討論,未經(jīng)允許,禁止轉(zhuǎn)載!

總結(jié)

以上是生活随笔為你收集整理的squid 不缓存特定页面_【零基础学云计算】squid代理服务器介绍与配置(理论+实践)一...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。