- 論壇徽章:
- 0
|
squid 2.5 stable快速安裝指南
原帖由 "iceblood" 發(fā)表:
我要配制遠(yuǎn)程一臺(tái)服務(wù)器的SQUID,但是公司的網(wǎng)絡(luò)嚴(yán)重不穩(wěn)定而且還特別慢,配置起來太痛苦了,所以麻煩誰能發(fā)一個(gè)給我。
可以不必要用戶名驗(yàn)證,謝謝!
squid 2.5 stable快速安裝指南
阿土/Aborigen Yin
http://www.bsdbase.com
目標(biāo):在網(wǎng)關(guān)上為內(nèi)網(wǎng)提供普通代理以及透明代理服務(wù),以ip地址為訪問控制條件,不需要其他訪問控制。
#安裝
#如果是FreeBSD,建議安裝如下ports:
cd /usr/ports/devel/autoconf
make clean
make install clean
cd /usr/ports/devel/automake
make clean
make install clean
#首先,配置好你的網(wǎng)絡(luò),保證安裝squid的主機(jī)能正常上網(wǎng);
ping www.163.com
#用域名是為了測(cè)試DNS解析;
#以下以root身份執(zhí)行。
#獲得最新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
#權(quán)限改變是必要的;參考squid.conf
#cache_effective_user nobody
#cache_effective_group nobody
#默認(rèn)使用
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
#逃避討厭的代理掃描,使用一個(gè)自定義的端口;
#設(shè)置不代理的url,一些動(dòng)態(tài)網(wǎng)頁,比如江湖、聊天室。
# 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
#定義內(nèi)網(wǎng)(假設(shè)有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的默認(rèn)配置是拒絕所有連接;
#Default:
# http_access deny all
#
#對(duì)上述內(nèi)網(wǎng)地址開放
http_access allow lan-a
http_access allow lan-b
http_access allow lan-c
#Recommended minimum configuration:
#
#以下設(shè)置透明代理,如果你不用透明代理,可以跳過。
#在網(wǎng)關(guān)的防火墻上設(shè)置重定向,把內(nèi)網(wǎng)對(duì)80的訪問請(qǐng)求重定向到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
#限定對(duì)指定來源的請(qǐng)求做重定向;
#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
#作透明代理的同時(shí)緩存
#注意下面一行,默認(rèn)是off的.
httpd_accel_uses_host_header on
#初始化緩沖目錄
/usr/local/squid/sbin/squid -z
#開機(jī)關(guān)機(jī)管理腳本
#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
#開機(jī)自動(dòng)執(zhí)行
#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發(fā)行版本默認(rèn)安裝有squid,如果你不喜歡默認(rèn)的,砍吧。 |
|