Squid 反向 Proxycdn搭建配置

來源:互聯網
上載者:User

標籤:linux   squid   伺服器   反向 Proxy   

因為公司業務需要,需要自己在某地搭建一個cdn 節點,通過DNSpod 智能解析和squid 配合可以搭建一個節點

安裝路徑: /usr/local/squid

 

1,安裝squid

下載 http://www.squid-cache.org/Versions/v3/3.4/squid-3.4.8.tar.gz

#yum -y install gcc gcc-c++         #安裝編譯用的外掛程式

# Tar xvf squid-3.4.8.tar.gz

#cd squid-3.4.8

#cd /usr/local

#mkdir squid               # 建立一個名為squid 目錄

#cd  squid-3.4.8

#./configure --prefix=/usr/local/squid      #編譯

#make && make install                 #安裝

 

配置1

建立使用者squid 和使用者組 squid

#groupadd squid

#useradd -g squid -s /sbin//nologin squid

配置squid 檔案

#vi /usr/local/squid/etc/squid.conf   

 

visible_hostname chengdu.sz1card1.com

cache_effective_user squid

cache_effective_group squid

 

http_port 80 accel vhost vport

 

cache_peer 192.168.1.11 parent 80 0 no-query originserver round-robin  name=proxy1

cache_peer 192.168.1.12 parent 80 0 no-query originserver round-robin  name=proxy2

cache_peer 192.168.1.13 parent 80 0 no-query originserver round-robin  name=proxy3

cache_peer_domain proxy1 server.1card1.cn

cache_peer_domain proxy2 www.abc.cn

cache_peer_domain proxy2 www.xxxx.cn

cache_peer_domain proxy3 www.abcd.com

 

http_access allow all

 

cache_log /usr/local/squid/var/logs/cache.log

access_log /usr/local/squid/var/logs/access.log squid

cache_dir ufs /usr/local/squid/var/cache 1000 16 256

 

maximum_object_size 10240 KB

maximum_object_size_in_memory 1024 KB

cache_mem 1024 MB

 

 

配置2

#chown -Rf squid:nobody /usr/local/squid 

初始化squid.conf裡配置的cache目錄,就是建立了一堆的目錄:

#sudo /usr/local/squid/sbin/squid -z

啟動squid後台運行 

sudo /usr/local/squid/sbin/squid -s

檢查一下進程是否存在:ps -ef|grep squid

 

 

 

 

 

Squid日常維護過程中,常用的一些命令:

1,初始化你在 squid.conf 裡配置的 cache 目錄

squid -z

如果有錯誤提示,請檢查你的 cache目錄的許可權。

可以使用使用更改目錄許可權:

chown -R squid:squid /cache目錄

2,對你的squid.conf 排錯,即驗證 squid.conf 的 文法和配置。

squid -k parse

如果squid.conf 有文法或配置錯誤,這裡會返回提示你,如果沒有返回,嘗試啟動squid。

3,在前台啟動squid,並輸出啟動過程。

/usr/local/squid/sbin/squid -N -d1

如果有ready to server reques相關資訊,說明Squid啟動成功。

 

 

Squid 作為系統服務重啟指令碼

 

 

#!/bin/bash # 

chkconfig: 345 61 61

# description: squid is a web cache server

# processname: squid

. /etc/rc.d/init.d/functions

case $1 in

"start") /usr/local/squid/sbin/squid -s

if [ $? == "0" ];then

echo "squid start ok"

else

echo "please check the log"

fi

;;

"stop") /usr/local/squid/sbin/squid -k shutdown

if [ $? == "0" ];then

echo "squid stop ok"

else

echo "please check the log"

fi

;;

"restart")

/usr/local/squid/sbin/squid -k shutdown

if [ $? == "0" ];then

/usr/local/squid/sbin/squid -s

if [ $? == "0" ];then

 echo "squid restart ok"

else

/usr/local/squid/sbin/squid -s

if [ $? == "0" ];then

 echo "squid restart ok"

else

echo "please check the log"

fi

fi

fi

;;

 *)

echo "Usage only start|stop|restart"

;;

esac

把這個檔案放到/etc/init.d/目錄下並命名為squid

chmod +x /etc/init.d/squid

chkconfig --add squid

 

 

如果出現squid 服務不支援 chkconfig

 

則去更改上面的  chkconfig: 345 61 61    這幾個數字

 


 

 

 

 

 

 

 

 

 

 


Squid 反向 Proxycdn搭建配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.