Squid安装

来源:互联网 发布:成都软件开发外包 编辑:程序博客网 时间:2024/06/09 17:34

#获得最新stable源码
http://www.squid-cache.org

bunzip2 squid-2.5.STABLE1.tar.bz2
tar xvf squid-2.5.STABLE1.tar
cd squid-2.5.STABLE1
vi config.sh
#!/bin/sh
./configure
--prefix=/usr/local/squid /
--sysconfdir=/etc/squid /
--enable-default-err-language=Simplify_Chinese /
--enable-ipf-transparent /  //ipf防火墙
--disable-hostname-checks /
--disable-internal-dns /
--enable-storeio=ufs,null
#使用的文件系统通常是默认的ufs,不过如果想要做一个不缓存任何文件的代理服
务器,就需要加上null文件系统。
--enable-arp-acl
#这样可以在规则设置中直接通过客户端的MAC地址进行管理,防止客户使用IP欺骗。
--enable-underscore
#允许解析的URL中出现下划线,因为默认情况下Squid会认为带下划线的URL是
非法的,并拒绝访问该地址。
#--enable-linux-netfilter
#允许使用Linux的透明代理功能。
##用户/密码认证为Squid管理提供了更多便利,最常用的认证方式是NCSA。从Squid 2.5版本开始,NCSA认证包含在了basic中,
##而非以前单独的认证模块。下面来看看实现认证的具体操作。
##首先在编译时配置选项应包括以下配置:
##--enable-auth="basic" --enable-basic-auth-helpers="NCSA"
##“make install”以后,需要将“helpers/basic_auth/NCSA/ncsa_auth”拷贝到用户可执行目录中,
##如/usr/bin(如果在该目录中找不到这个执行文件,在编译时请使用make all而不是make,或者直接在该目录中执行make),
##然后需要借助Apache的密码管理程序htpasswd来生成用户名/密码对应的文件,就像下面这行代码:
##htpasswd -c /var/squid/etc/password guest


  在输入两遍guest用户的密码后,一个guest用户就生成了。如果以后需要添加用户,把上面的命令去掉-c参数再运行即可。


make
make install
#首先,配置好你的网络,保证安装squid的主机能正常上网;
cp /etc/nsswitch.dns /etc/nsswitch.conf

vi /etc/resolv.conf
nameserver 219.141.136.10
nameserver 202.99.8.1
nameserver mail.zcomadmin.com

ping www.sina.com //表示能够通过DNS解析

cd /usr/local/squid/etc
vi squid.conf
# vi /usr/local/squid/etc/squid.conf
===================== squid.conf ====================
1 在这个例子中,代理服务器同时也是网关,内部网络接口eth0的IP地址为192.168.0.1,
外部网络接口eth1的IP地址为202.103.x.x。下面是一个基本的代理所需要配置选项:


http_port 192.168.0.1:3128 //默认端口是3128,当然也可以是任何其它端口
只要不与其它服务发生冲突即可。为了安全起见,在前面加上IP地址,Squid就不会监听外部的网络接口
2 //下面的配置选项是服务器管理者的电子邮件,
当错误发生时,该地址会显示在错误页面上,便于用户联系:
cache_mgr test@zcomadmin.com

error_directory /usr/local/squid/share/errors/Simplify_Chinese
dns_nameservers 202.99.160.68 202.99.168.8
3 //下面这行配置是在较新版本中出现的参数,告诉Squid在错误页面中显示的服务器名称:
visible_hostname mail.zcomadmin.com
4 //如果是普通代理服务器,以上的配置已经足够。但是很多Squid都被用来做透明代理。所谓透明代理,
就是客户端不知道有代理服务器的存在,当然也不需要进行任何与代理有关的设置,从而大大方便了系统管理员。
相关的选项有以下几个:
httpd_accel_uses_host_header on
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_single_host off
httpd_accel_with_proxy on
##在Linux上,可以用iptables/ipchains直接将对Web端口80的请求直接转发到Squid端口3128,
##由Squid接手,而用户浏览器仍然认为它访问的是对方的80端口。例如以下这条命令:
##iptables -t nat -A PREROUTING -s 192.168.0.200/32 -p tcp --dport 80 -j REDIRECT 3128
5 //以下这些参数告诉Squid缓存的文件系统、位置和缓存策略:
cache_mem 48 MB
maximum_object_size 4096 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 30 KB
minimum_object_size_in_memory 0 KB
cache_swap_low 85
cache_swap_high 90
##//Squid会将/var/squid目录作为保存缓存数据的目录,每次处理的缓存大小是32兆字节,当缓存空间使用达到95%时,
##新的内容将取代旧的而不直接添加到目录中,直到空间又下降到90%才停止这一活动。如果不想Squid缓存任何文件,
##如某些存储空间有限的专有系统,可以使用null文件系统(这样不需要那些缓存策略):
##cache_dir null /tmp
cache_dir ufs /var/squid
cache_effective_user squid
cache_effective_group squid
cache_access_log /var/squid/access.log
cache_log /var/squid/cache.log
cache_store_log /var/squid/store.log


6 //以下配置告诉Squid如何处理用户,对每个请求的IP地址作为单独地址处理:
client_mask 255.255.255.255

7 //或者为了保证高级用户的带宽,希望每个用户的并发连接不能太多,以免影响他人,也可以通过Squid控制,代码如下:
acl conncount maxconn 3
http_access deny conncount normal
http_access allow normal

8 //还有一种比较广泛的控制是文件类型。如果不希望普通用户通过代理服务器下载MP3、AVI等文件,
完全可以对他们进行限制,代码如下:
acl mmxfile urlpath_regex /.mp3$ /.avi$ /.exe$
http_access deny mmxfile

9 //设置不代理的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
10 //Squid可以通过IP地址、主机名、MAC地址、用户/密码认证等识别用户,
也可以通过域名、域后缀、文件类型、IP地址、端口、URL匹配等控制用户的访问,
还可以使用时间区间对用户进行管理,所以访问控制是Squid配置中的重点。
Squid用ACL(Access Control List,访问控制列表)对访问类型进行划分,用http_access deny 或allow进行控制。
根据需求首先定义两组用户advance和normal,还有代表所有未指明的用户组all及不允许上网的baduser,
##配置代码如下:
##acl advance 192.168.0.2-192.168.0.10/32
##acl normal src 192.168.0.11-192.168.0.200/32
##acl baduser src 192.168.0.100/32
##acl baddst dst www.soocol.com
##acl all src 0.0.0.0/0

##http_access deny baduser
##http_access allow advance
##http_access allow normal

//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:
#
11 ##//如果想让普通用户只在上班时间可以上网,而且是每周的工作日,用Squid应当如何处理呢?看看下面的ACL定义:

##acl worktime time MTWHF 8:30-12:00 14:00-18:00
##http_access deny !worktime
12 //##该选项指出了认证方式(basic)、需要的程序(ncsa_auth)和
##对应的密码文件(password)
##auth_param basic program /usr/bin/ncsa_auth /var/squid/etc/password
## 指定认证程序的进程数
##auth_param basic children 5
## 浏览器显示输入用户/密码对话框时的领域内容
##auth_param basic realm My Proxy Caching Domain
## 基本的认证有效时间
##auth_param basic credentialsttl 2 hours
## 普通用户需要通过认证才能访问Internet
##acl normal proxy_auth REQUIRED
##http_access allow normal


##通过以上的配置即可完成认证工作。有的读者可能要问:认证只针对普通用户,而高级用户是直接上网的,
##该怎么处理呢?其实,这两种用户是可以共存的。如前所述,Squid是顺序处理http_access的,所以在http_access处理过程中,
##如果先处理normal用户,那么当前用户无论是否属于高级用户,都会被要求进行认证;相反如果先处理高级用户,
##剩下的就只有需要认证的普通用户了。例如以下配置代码:

##...
##http_access allow normal (需要认证)
##http_access allow advance (不需要认证)
##...
##不管是否为noauth用户,都要求进行用户名/密码验证。正确的方法是将二者位置交换,代码如下:

##...
##http_access allow advance
##http_access allow normal
##...


===================== squid.conf ====================
exp:
# 服务器配置
http_port 192.168.1.238:3128
cache_mgr test@zcomadmin.com
#cache_dir ufs /usr/local/squid/var/cache/
cache_access_log /var/squid/access.log
cache_log /var/squid/cache.log
cache_store_log /var/squid/store.log
visible_hostname No1.proxy
#client_mask 255.255.255.255
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
#httpd_accel_user_host_header on

# 用户分类
#acl advance arp 00:01:02:1f:2c:3e 00:01:02:3c:1a:8b ...
#acl normal proxy_auth REQUIED
#acl all src 0.0.0.0

# 行为分类
acl mmxfile urlpath_regex /.mp3$ /.avi$ /.exe$
acl conncount maxconn 3
acl worktime time MTWHF 8:30-12:00 14:00-18:00
acl sinapage dstdomain ok.sina.com.cn
acl qq dstdomain .tcccent.com.cn

# 处理
http_access allow advance
http_access deny conncount normal
http_access deny !worktime
http_access deny mmxfile
http_access deny sinapage
http_access deny qq
http_access allow normal

mkdir /usr/local/squid/var/cache

chown –R squid:squid /usr/local/squid/var/

chmod -R /usr/local/squid/var/cache

mkdir /var/squid

cd /var/squid

chown -R squid:squid .

chmod -R 777 .

//该命令会产生Squid所有的缓存目录。
/usr/local/squid/sbin/squid -z
//如果你想前台执行Squid,接着执行命令:
/usr/local/squid/bin/squid -NCd1 
##该命令正式启动Squid。如果一切正常,你会看到一行输出
##Ready to serve requests.
/usr/local/squid/sbin/squid -k check

//输出会告诉你Squid的当前状态。


4. SQUID启动脚本

# vi /etc/rc3.d/S78squid
====================== S78squid =====================
#!/sbin/sh
#
# Copyright (c) 2005 by llzqq Inc
# All rights reserved.
#
#ident  "@(#)squid    1.1     04/05/24 SMI"

case "$1" in
start)
        /usr/local/squid/sbin/squid -D
        ;;
stop)
        /usr/local/squid/sbin/squid -k shutdown
        pkill squid
        ;;
restart)
        /usr/local/squid/sbin/squid –k reconfigure
        ;;
*)
        echo "Usage: $0 { start | stop | restart }"
        exit 1
        ;;
esac
exit 0
====================== S78squid =====================

# chown root:sys /etc/rc3.d/S78squid
# chmod 744 /etc/rc3.d/S78squid
# ln -s /etc/rc3.d/S78squid /etc/rc2.d/K78squid


1.1安装防火墙IPF(FOR X86):

# wget http://archive.cert.uni-stuttgar ... il3.4.33pre2.tar.gz
# gzip -d ip-fil3.4.33pre2.tar.gz
# tar vxf ip-fil3.4.33pre2.tar
# cd ip_fil3.4.33pre2
# /usr/ccs/bin/make solaris
# cd SunOS5
# /usr/ccs/bin/make package
# cd i386-5.9
# pkgadd -d ipf.pkg

 


1.2安装防火墙IPF(FOR SPARC):

# wget http://anders.fix.no/solaris/pkg/ipf-3.4.33pre2-sol9-sparc.gz
# gzip –d ipf-3.4.33pre2-sol9-sparc.gz
# pkgadd –d ipf-3.4.33pre2-sol9-sparc


安装SQUID出错可以是没有安装必要的系统编译环境

GCC工具:
# gzip -d libiconv-1.8-sol9-sparc-local.gz
# gzip -d gcc-3.4.1-sol9-sparc-local.gz
# gzip -d libgcc-3.4.1-sol9-sparc-local.gz
# pkgadd -d gcc-3.4.1-sol9-sparc-local
# pkgadd -d libiconv-1.8-sol9-sparc-local
# pkgadd -d libgcc-3.4.1-sol9-sparc-local
# ln –s /usr/local/bin/gcc /usr/bin/cc

OTHERS:
# pkgadd -d expat-1.95.5-sol9-sparc-local
# pkgadd -d gdbm-1.8.3-sol9-sparc-local
# pkgadd -d openssl-0.9.7e-sol9-sparc-local
# pkgadd -d bison-1.875d-sol9-sparc-local
# pkgadd -d autoconf-2.59-sol9-sparc-local
# pkgadd -d lsof-4.68-sol9-intel-local

MAKE工具:
# gzip -d make-3.80-sol9-sparc-local.gz
# gzip -d automake-1.9-sol9-sparc-local.gz
# pkgadd -d make-3.80-sol9-sparc-local
# pkgadd -d automake-1.9-sol9-sparc-local
 配置IPF防火墙

# vi /etc/opt/ipf/ipf.conf

===============================ipf.conf============================
#
# +------------------+   +---------------------+   +------------------+
# | Internet Network |---| hme0  NAT+IPF   rf0 |---| Internal Network |
# +------------------+   +---------------------+   +------------------+
#
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Interface: all
# Block all incoming and outgoing packets unless they're allowed later.
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# block all frist
block in all
block out all

# packets with ip-options, short and fragmented packets
block in quick all with short
block in quick all with ipopts
block in quick all with frag
block in quick all with opt lsrr
block in quick all with opt ssrr

# disable nmap scan
block in quick on hme0 proto tcp from any to any flags FUP
block in quick on hme0 proto tcp from any to any flags SF/SFRA
block in quick on hme0 proto tcp from any to any flags /SFRA

# Local network traffic is allowed
pass out quick on lo0
pass in quick on lo0
pass in quick on rf0
pass out quick on rf0

# The pass rules to enable Services
pass in on hme0 proto icmp from any to any icmp-type echo
pass in on hme0 proto tcp from any to any port = 20 flags S keep state
pass in on hme0 proto tcp from any to any port = 21 flags S keep state
pass in on hme0 proto tcp from any to any port = 22 flags S keep state
pass in on hme0 proto tcp from any to any port = 80 flags S keep state
pass in on hme0 proto tcp from any to any port = 443 flags S keep state
pass in on hme0 proto tcp from any to any port 55000 >< 55100 flags S keep state

# The general pass rules.
pass out quick on hme0 proto tcp from any to any flags S/SAFR keep state keep frags
pass out quick on hme0 proto udp from any to any keep state keep frags
pass out quick on hme0 proto icmp from any to any keep state keep frags
===============================ipf.conf============================

# vi /etc/opt/ipf/ipnat.conf

==============================ipnat.conf===========================
map hme0 192.168.100.0/24 -> 192.168.10.14/32 proxy port ftp ftp/tcp
map hme0 192.168.100.0/24 -> 192.168.10.14/32 portmap tcp/udp auto
map hme0 192.168.100.0/24 -> 192.168.10.14/32

rdr rf0 0.0.0.0/0 port 80 -> 192.168.100.1 port 3128
==============================ipnat.conf===========================

6. 打开IP转发:

# touch /etc/gateways

原创粉丝点击