squid代理服務器介紹與配置(理論+實踐)一-創(chuàng)新互聯(lián)

緩存的概述

Web代理的工作機制

  • 緩存網頁對象,減少重復請求
    squid代理服務器介紹與配置(理論+實踐)一

    印江網站建設公司成都創(chuàng)新互聯(lián),印江網站設計制作,有大型網站制作公司豐富經驗。已為印江數千家提供企業(yè)網站建設服務。企業(yè)網站搭建\成都外貿網站建設公司要多少錢,請找那個售后服務好的印江做網站的公司定做!

    代理的基本類型

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

使用代理的好處

  • 提高Web訪問速度
  • 隱藏客戶機的真實IP地址

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

實驗環(huán)境

squid服務器IP地址:192.168.80.179
web服務器IP地址:192.168.80.151
client測試機IP地址:192.168.80.135

在squid服務器上安裝squid服務

[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 \                         //支持網絡篩選
--enable-linux-tproxy \                           //支持透明
--enable-async-io=100 \                          //IO優(yōu)化
--enable-err-language="Simplify_Chinese" \         //報錯顯示簡體中文
--enable-underscore \
--enable-poll \
--enable-gnuregex                                 //支持正則表達
[root@squid squid-3.4.6]# make && make install    //編譯安裝
[root@squid squid-3.4.6]# ln -s /usr/local/squid/sbin/* /usr/local/sbin/     //復制命令便于系統(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/        //給目錄所有文件屬主屬組權限

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

[root@squid squid-3.4.6]# vim /etc/squid.conf         //進入修改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                  //開啟服務
[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服務的腳本文件
#!/bin/bash
#chkconfig: 2345 90 25
PID="/usr/local/squid/var/run/squid.pid"              //PID文件進程號文件路徑
CONF="/etc/squid.conf"                                  //主配置文件路徑
CMD="/usr/local/squid/sbin/squid"                       //服務啟動命令路徑

case "$1" in
start)
                netstat -ntap | grep squid &> /dev/null
                if [ $? -eq 0 ]
                then 
                 echo "squid is running"
                 else
                 echo "正在啟動 squid...." 
                 $CMD
                fi
                ;;
stop)
                $CMD -k kill &> /dev/null               //關閉squid服務
                rm -rf $PID &> /dev/null                //刪除PID文件
                ;;
status)
                [ -f $PID ] &> /dev/null
                 if [ $? -eq 0 ]
                                then
                                 netstat -ntap | grep squid
                                else
                                 echo "squid is not running"
                fi
                ;;
restart)
                $0 stop &> /dev/null
                echo "正在關閉 squid..."
                $0 start &> /dev/null
                echo "正在啟動 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í)行權限
[root@squid init.d]# chkconfig --add squid              //添加到service管理中
[root@squid init.d]# chkconfig --level 35 squid on        //設置開機自啟

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

[root@squid init.d]# vim /etc/squid.conf         //修改主配置文件
# Squid normally listens to port 3128
http_port 3128
cache_mem 64 MB                                //內存空間大小
reply_body_max_size 10 MB                      //允許下載大文件大小
maximum_object_size 4096 KB                    //允許保存緩存空間大對象大小
[root@squid init.d]# service squid restart
[root@squid init.d]# iptables -L                //查看表內容
[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服務器上安裝apache服務

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

使用client訪問web網頁

squid代理服務器介紹與配置(理論+實踐)一

在web服務器日志文件中查看訪問日志文件

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

修改客戶機瀏覽器代理設置

squid代理服務器介紹與配置(理論+實踐)一

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

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

透明代理實驗搭建

實驗環(huán)境

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

在squid服務器上添加一塊網卡,并配置IP地址

squid代理服務器介紹與配置(理論+實踐)一

[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                                 //設置靜態(tài)                     
IPADDR=192.168.10.1
NETMASK=255.255.255.0  
[root@squid network-scripts]# service network restart           //重啟網絡服務
[root@squid network-scripts]# vim /etc/sysctl.conf             //開啟路由轉發(fā)
net.ipv4.ip_forward=1
[root@squid network-scripts]# sysctl -p                         //加載

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

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

在squid服務器上設置透明代理

root@squid network-scripts]# vim /etc/squid.conf           //設置配置文件
http_port 192.168.10.1:3128 transparent                  //設置透明代理
cache_effective_user squid
cache_effective_group squid
[root@squid network-scripts]# service squid stop            //關閉開啟squid服務
[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客戶端測試

squid代理服務器介紹與配置(理論+實踐)一

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

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

網頁題目:squid代理服務器介紹與配置(理論+實踐)一-創(chuàng)新互聯(lián)
新聞來源:http://bm7419.com/article4/dschoe.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供外貿建站、自適應網站響應式網站、電子商務搜索引擎優(yōu)化、域名注冊

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網站建設