Squid -- Ubuntu 缓存与反向代理
时间:2009-07-24 来源:ygl23
版本:squid-2.6.STABLE14-20070810
1. 安装
$> tar xzvf squid-2.6.STABLE1-20060726.tar.gz
$> cd squid-2.6.STABLE1-20060726
$> ./configure --prefix=/opt/squid --enable-dlmalloc --with-pthreads --enable-poll --disable-internal-dns --enable-stacktrace --enable-removal-policies="heap,lru" --enable-delay-pools --enable-storeio="aufs,coss,diskd,ufs"
$> make
$> make install
2.修改squid.conf
假定xx.xx.xx.xx为IP地址,需写所代理的服务器的真实IP地址
配置监听的IP与端口http_port xx.xx.xx.xx:80 vhost vport
设置代理本机的81端口的请求cache_peer 127.0.0.1 parent 81 0 no-query originserver
设置缓存内存大小cache_mem 400 MB
去掉注释cache_swap_low 40
去掉注释cache_swap_high 50
设置最大缓存文件大小 maximum_object_size 20000 KB
设置内存中对大缓存的文件大小 maximum_object_size_in_memory 5120 KB
磁盘缓存设置 cache_dir ufs /opt/squid/var/cache 10000 16 256
设置日志格式 emulate_httpd_log on
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
添加限制同一IP客户端的最大连接数acl OverConnLimit maxconn 10000
http_access deny OverConnLimit
注释掉http_access deny all
增加http_access allow all
去掉注释 cache_effective_user nobody
去掉注释 cache_effective_group nobody
添加 visible_hostname squid.test.net
3.配置完成首次启动前的初始化
chown -R nobody:nobody /opt/squid
/opt/squid/sbin/squid -z
echo "65535" > /proc/sys/fs/file-max
ulimit -HSn 65535
4.配置开机自动启动
1、脚本
#!/bin/sh
#
# Linux startup script for Squid
#
# chkconfig: 345 85 15
# description: Squid is a Cache server.
# processname: wrapper.pl
#
# To install, configure this file as needed and copy init.squid
# to /etc/rc.d/init.d as squid. Then use "# /sbin/chkconfig squid reset"
#
SQUID_HOME=/opt/squid export SQUID_HOME
#
# If you want to start the entire Resin process as a different user,
# set this to the user name. If you need to bind to a protected port,
# e.g. port 80, you can't use USER, but will need to use bin/squid.
#
USER=
#
# You can change this to $SQUID_HOME/sbin/squid if you need squid to
# bind to port 80, but run as a different user.
#
EXE=$SQUID_HOME/sbin/squid
#
# Sets the commandline arguments.
#
ARGS="" case "$1" in
start)
echo -n "Starting squid: "
if test -n "$USER"; then
su $USER -c "$EXE start $ARGS"
else
$EXE start $ARGS
fi
echo
;;
stop)
echo -n "Shutting down squid: "
$EXE -k shutdown
echo
# rm -f $PID
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac exit 0 3、配置squid 至启动项
$> update-rc.d squid start 93 2 3 4 5 . stop 07 0 6 .
(记得别忘了最后的一个 . ) 相关文章: 代理QQ: http://www.linuxsir.org/bbs/archive/index.php/t-2884.html 透明代理 : http://www.diybl.com/course/6_system/linux/Linuxjs/20090318/163208.html
相关阅读 更多 +