歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> squid 2.5 stable快速安裝指南

squid 2.5 stable快速安裝指南

日期:2017/2/27 14:20:59   编辑:更多Linux
  目標:在網關上為內網提供普通代理以及透明代理服務,以ip地址為訪問控制條件,不需要其他訪問控制。 #安裝 #如果是FreeBSD,建議安裝如下ports: cd /usr/ports/devel/autoconf make clean make install clean cd /usr/ports/devel/automake make clean make install clean #首先,配置好你的網絡,保證安裝squid的主機能正常上網; ping www.163.com #用域名是為了測試DNS解析; #以下以root身份執行。 #獲得最新stable源碼 http://www.squid-cache.org mkdir -p /usr/local/src/distfiles cd /usr/local/src/distfiles #FreeBSD fetch http://www.squid-cache.org/Versions/v2/2.5/squid-2.5.STABLE1.tar.gz #Linux wget http://www.squid-cache.org/Versions/v2/2.5/squid-2.5.STABLE1.tar.gz tar xfz squid-2.5.STABLE1.tar.gz -C .. cd ../squid-2.5.STABLE1 ./configure --prefix=/usr/local/squid make make install #權限改變是必要的;參考squid.conf #cache_effective_user nobody #cache_effective_group nobody #默認使用 chown -R nobody:nobody /usr/local/squid/var #按照你的需要配置; #vi /usr/local/squid/etc/squid.conf # TAG: http_port # Usage: port # hostname:port # 1.2.3.4:port #Default: # http_port 3128 http_port 60080 #逃避討厭的代理掃描,使用一個自定義的端口; #設置不代理的url,一些動態網頁,比如江湖、聊天室。 # TAG: no_cache # A list of ACL elements which, if matched, cause the request to # not be satisfied from the cache and the reply to not be cached. # In other Words, use this to force certain objects to never be cached. # # You must use the word 'DENY' to indicate the ACL names which should # NOT be cached. # #We recommend you to use the following two lines. acl QUERY urlpath_regex cgi-bin ? ASP PHP sHtml php3 cgi no_cache deny QUERY # Access CONTROLS # ----------------------------------------------------------------------------- # TAG: acl # Defining an Access List # # acl aclname acltype string1 ...


# acl aclname acltype "file" ... # # when using "file", the file should contain one item per line #定義內網(假設有172.16.0.0/16;192.168.0.0/16;10.0.0.0/8); acl lan-a src 172.16.0.0/16 acl lan-b src 192.168.0.0/16 acl lan-c src 10.0.0.0/8 #squid的默認配置是拒絕所有連接; #Default: # http_access deny all # #對上述內網地址開放 http_access allow lan-a http_access allow lan-b http_access allow lan-c #Recommended minimum configuration: # #以下設置透明代理,如果你不用透明代理,可以跳過。 #在網關的防火牆上設置重定向,把內網對80的訪問請求重定向到squid: #Ipfilter rules #rdr $LAN_NIC 0/0 port 80 -> $SQUID_HOST_ADDR port $SQUID_PROXY_PORT tcp #Iptables rules #iptables -t nat -A PREROUTING -i $LAN_NIC -p tcp -m tcp --dport 80 -j DNAT --to $SQUID_HOST_ADDR:$SQUID_PROXY_PORT #限定對指定來源的請求做重定向; #iptables -t nat -A PREROUTING -i $LAN_NIC -p tcp -m tcp -s $INTERNAL_NETWORK/$INTERNAL_MASK --dport 80 -j DNAT --to $SQUID_HOST_ADDR:$SQUID_PROXY_PORT #啟用透明代理 httpd_accel_host virtual httpd_accel_port 80 httpd_accel_with_proxy on #作透明代理的同時緩存 #注意下面一行,默認是off的. httpd_accel_uses_host_header on #初始化緩沖目錄 /usr/local/squid/sbin/squid -z #開機關機管理腳本 #vi /usr/local/sbin/squid.sh #!/bin/sh case "$1" in start) if [ -x /usr/local/squid/sbin/squid ]; then /usr/local/squid/sbin/squid && echo . && echo 'Squid proxy server started.' fi ;; stop) killall squid && echo . && echo 'Squid proxy server stopped.' ;; restart) echo . echo "Restart Squid proxy server ......" $0 stop sleep 30 $0 start ;; *) echo "$0 start stop restart" ;; esac #end of /usr/local/sbin/squid.sh chmod 700 /usr/local/sbin/squid.sh #開機自動執行 #FreeBSD ln -s /usr/local/sbin/squid.sh /usr/local/etc/rc.d #Linux ln -s /usr/local/sbin/squid.sh /etc/rc.d/rc3.d/S99Squid-prxoy #注意:有些linux發行版本默認安裝有squid,如果你不喜歡默認的,砍吧。 我覺得很容易配,在SQUID.CONF中,主要的改一行 http_port 3128 ,將這行的前面的#去掉, 然後在客戶端的浏覽器的連接設置成這個主機的地址和這個端口就可以了, 當然這個端口可以由你定一個與系統不沖突的端口. 在執行squid -NCd1 前,別忘了執行squid -z



然後在客戶端的浏覽器的連接設置成這個主機的地址和這個端口就可以了, 當然這個端口可以由你定一個與系統不沖突的端口. 在執行squid -NCd1 前,別忘了執行squid -z



Copyright © Linux教程網 All Rights Reserved