您的位置:首页 > 运维架构 > 反向代理

原创-在Debian 5.0下的使用源代码安装Squid笔记(第二版)

2010-04-18 21:36 447 查看
作者:何祖彬[RobinHe] Mail:zubin.he@gmail.com

Skype ID : pto_robin QQ : 57623579

BLOG : http://blog.csdn.net/zubin006/

Website : http://www.wearelinuxer.com/

始于2009年3月31日 PM

版本号:Debian-Squid-V2.0-20100418, 2009年3月31日首版 2010年4月18日更新至第二版

第一版 : http://www.wearelinuxer.com/?p=68

转载请注明出处,谢谢!

本文中难免有不足、遗漏、错别字和句子不通之处,如发现、或者有更新改变之处,请与我联系以及时修正和完善!

系统环境 : Debian GNU/Linux 5.0

SQUID : 3.1.1

使用Squid做成透时代理,让局域网内的用户只能浏览白名单里面的网站。

参考资料:

Squid中文权威指南 : http://blog.s135.com/book/squid/index.html
一,下载并安装squid:

squid的官方网站:www.squid-cache.org

我下载的是squid-3.1.1版:

xx:~#cd /usr/local/src

xx:/usr/local/src# wget http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.1.tar.gz
解压缩:

xx:/usr/local/src# tar -zxvf squid-3.1.1.tar.gz

xx:/usr/local/src# cd squid-3.1.1

xx:/usr/local/src/squid-3.1.1# ./configure –prefix=/usr/local/squid
–localstatedir=/var/cache/squid-cache –enable-icmp

–enable-icmp : icmp支持,暂时没用,以后用时就不要再重新编译安装。

–localstatedir=/var/cache/squid-cache : 把cache和log文件夹,即数据目录放到空间比较大的硬盘上,因
为做为proxy,需要足够的空间存入这些数据以及log。

–prefix=/usr/local/squid : 把squid安装到/usr/local/squid这个目录下。

xx:/usr/local/src/squid-3.1.1# make

xx:/usr/local/src/squid-3.1.1# make install

二,配置Squid

a,增加一个squid的用户,以便让squid来运行squid服务,以方便标识:

xx:/usr/local/src/squid-3.1.1# adduser squid

xx:/usr/local/src/squid-3.1.1# cd /usr/local/squid/

#更改cache和log的权限,以便让squid用户对这些目录有扫行权限。

xx:/usr/local/squid/# chown squid:squid /var/cache/squid-cache -Rf

#初始化squid的cache

xx:/usr/local/squid/# touch /var/cache/squid-cache/logs/cache.log

xx:/usr/local/squid/# chmod 777 /var/cache/squid-cache/logs/cache.log

#没有做以上步骤,在初始化squid目录时会出现以下的提示,是因为没有权限或者没有某一个文件。

XX:/var/cache/squid-cache/logs# /usr/local/squid/sbin/squid -z
WARNING: Cannot write log file: /var/cache/squid-cache/logs/cache.log

/var/cache/squid-cache/logs/cache.log: Permission denied

messages will be sent to ’stderr’.

xx:/usr/local/squid/# /usr/local/squid/sbin/squid -z

2010/04/18 11:56:09| Creating Swap Directories

#不知为何不会像3.0那样提示和创建很多swap目录,以后继续研究中…

b,更改相关参数:

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

找到:

# cache_effective_user nobody

改成:

cache_effective_user squid

即设置运行squid的用户名。以便对上面的cache和log有完全的权限。

保存退出。

c,在配置文件中配置自已需要的内容:

找到这一行 :

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

我们可以在这一行下面,

在:

http_access deny all

这一行上面编写规则。

要求:只开放内网用户可以使用这个proxy服务,并且只允许访问公司规定访问的网站:

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

# Example rule allowing access from your local networks.

# Adapt localnet in the ACL section to list your (internal) IP networks

# from where browsing should be allowed

#http_access allow localnet

acl sitelist dstdomain .nba.com .baidu.com
 #只将sitelist表定义为nba.com和baidu.com域名

http_access deny !sitelist #禁提除sitelist里面以外的域名,请注意”!”

acl ptolan src 192.168.0.0/24

http_access allow ptolan

# And finally deny all other access to this proxy

http_access deny all

注意:根据squid指南中的:

域名ACL有点深奥,因为相对于匹配域名和子域有点微妙的差别。当ACL域名以”.”开头,squid将它作为通配符,它匹配在该域的任何主机名,甚至域
名自身。相反的,如果ACL域名不以”.”开头,squid使用精确的字符串比较,主机名同样必须被严格检查。

我少了域名前面的”.”,让我伤了好久的脑筋和时间。幸亏回头认真看了手册。

d,启动和停止squid服务:

启动:xx:~# /usr/local/squid/sbin/squid

停止:xx:~# /usr/local/squid/sbin/squid -k shutdown ##这个命令在3.1中好像不起作用.

在你的浏览器或者其软件网络软件中设置这个服务器的IP地址和对应的端口就可以使用proxy上网。

第二版去掉了透明代理的配置,要看请查看第一版:http://www.wearelinuxer.com/?p=68
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: