Chinaunix首页 | 论坛 | 博客
  • 博客访问: 500018
  • 博文数量: 110
  • 博客积分: 3971
  • 博客等级: 中校
  • 技术积分: 1175
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-20 23:27
文章分类

全部博文(110)

文章存档

2015年(2)

2014年(1)

2013年(1)

2011年(9)

2010年(28)

2009年(12)

2008年(13)

2007年(23)

2006年(21)

我的朋友

分类: WINDOWS

2010-01-31 23:34:07

  1. 1、建立squid用户和组

    groupadd squid
    useradd -g squid squid

    2、建立squid缓存以及日志目录

    mkdir /var/squidcache1

    mkdir /var/squidcache2

    chown -R squid.squid /var/squidcache1

    chown -R squid.squid /var/squidcache2

    mkdir /var/log/squid

    chown -R squid.squid /var/log/squid/

  2. gltmpfs.sh
  3. mount tmpfs /dev/shm -t tmpfs -o size=2048m
  4. mkdir /dev/shm/tmp
  5. chmod 1777 /dev/shm/tmp
  6. mount --bind /dev/shm/tmp /tmp#!/bin/sh
  7. 1 10 * * 1-4 /etc/tc
    30 23 * * 1-4 /etc/tc2
    1 10 * * 0,5,6 /etc/tc5
    30 3 * * 0,5,6 /etc/tc2
    3 9 * * 2 /sbin/reboot
  8. ifconfig eth0 192.168.1.254 netmask 255.255.255.0 up
    ifconfig eth1 220.165.252.178 netmask 255.255.255.248 up
    route add default gw 220.165.252.177 dev eth1
    echo "1" > /proc/sys/net/ipv4/ip_forward
    iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 220.165.252.178
  9. iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

  10. /usr/sbin/dnsmasq &
    iptables -A PREROUTING -t mangle -p tcp --dport www -j TOS --set-tos Minimize-Delay
    iptables -A PREROUTING -t mangle -p udp --dport domain -j TOS --set-tos Minimize-Delay
  11. 三、设定squid文件(vi /usr/local/squid/etc/squid.conf)

    1、 运行参数

    http_port 192.168.1.254:3128 transparent
    cache_mem 512 MB

    cache_mem设置不用太高一般100多用户只要设置256-512MB就可以了,

    cache_swap_low 85

    cache_swap_high 95

    cache_dir aufs /tmp 2000 16 256

    maximum_object_size 4096 KB  最大缓存文件为4M

    refresh_pattern .               0       20%     4320

    range_offset_limit 0 KB  对于多线程的下载squid默认是不缓存

    coredump_dir /var/log/squid squid挂掉后,临终遗言要放到哪里。不用管,一般人看不懂

    2、控制acl策略
    acl inside src 192.168.1.0/24

    # acl BadSites url_regex "/usr/local/squid/etc/badsites"

    这个是一个文本,主要放不许可的url内容

    # acl worktime time SMTWHFA 7:40-12:00 13:00-21:00 控制时间

    # acl rmfilm url_regex .rmvb

    /usr/local/squid/etc/badsites放需要屏蔽的网站,每个一行,同时这个文件的权限为squid

    # http_access deny BadSites

    http_access allow inside

    http_access deny all

    3、squid的运行用户及组

    pid_filename /var/run/squid.pid

    cache_effective_user squid
    cache_effective_group squid

    4、控制缓存等

    acl QUERY urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi

    acl download urlpath_regex -i \.avi$ \.rmvb$ \.rm$ \.ra$ \.ram$ \.mpe$ \.smi$

    cache deny QUERY

    cache deny download

    (禁止 cgi-bin等动态内容的缓存 禁止常用影视格式的大容量文件缓存)

  12. #禁止缓存
    hierarchy_stoplist cgi-bin ?
    hierarchy_stoplist -i ^https:\\ ?
    acl QUERY urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi
    acl denyssl urlpath_regex -i ^https:\\
    no_cache deny QUERY
    no_cache deny denyssl
    #上面几个就是说遇到URL中有包含cgi-bin和以https:\\开头的都不要缓存,
    #还有asp、cgi、php等动态脚本也不要缓存,
    #因为这些脚本通常都是动态更新的,这样数据不同步。
    #还有https://开通的不缓存是因为一般我们进行电子商务交易,
    #例如银行付款等都是采用这个的,如果把信用卡号什么缓存那不是很危险。

    在squid.conf中添加
    url_rewrite_program /etc/squid/redirect.pl ##重定向perl程序
    redirect_rewrites_host_header off ##禁止squid做host更新
    redirect_children 20 ##启用20个进程
    再看这个redirect.pl
    #!/usr/bin/perl
    $|=1;
            while (<>) {
                    @X = split;
                    $url = $X[0];
                    if ($url =~ /^http:\/\/www\.baidu\.com/) {
                            print “302:https:\/\/www\.google\.com\n”;
                    }
                    elsif ($url =~ /^http:\/\/opvps\.com/) {
                            print “302:http:\/\/www\.opvps\.com\n”;
                    }
                    elsif ($url =~ /^http:\/\/gmail\.com/) {
                            print “302:https:\/\/gmail\.google\.com\n”;
                    }
                    else {
                            print “$url\n”;
                    }
                }
    程序实现如下功能:
    将http://
    转向http://
    及www变成
    变成
    重定向acl匹配:
    正常情况下,squid将每个请求发送往重定向器。可以使用redirector_access规则来有选择的发送某些请求。语法与http_access相同:
    redirector_access allow|deny [!]ACLname
    例如:
    acl opvps src 192.168.1.5
    acl All src 0/0
    redirector_access deny opvps
    redirector_access allow All
    在该情形里,对匹配opvps(来源于192.168.0.5的主机)的请求,Squid跳过重定向器。

    5、日志存储

    debug_options ALL,1

    access_log /var/log/isquid/access.log

    cache_log /var/log/squid/cache.log

    #cache_store_log /var/log/squid/store.log

    cache_store_log none

    logfile_rotate 30

    注释:

    (1)debug_options ALL,1   1详细程度为最低的

    (2)logfile_rotate 30 日志循环为30天(根据每个人自己实际情况定义)

    (3)以下为禁止access.log或者store.log:
    cache_access_log/dev/null
    cache_store_log none
    cache_log /dev/null

    6、相关时间参数

    client_lifetime 15 minutes

    read_timeout 3 minutes

    half_closed_clients off

    request_timeout 1 minutes

    注释: 

    client_lifetime 1 day
    说明:设置客户在与squid建立连接后,可以把该连接保持多长时间。注意,因为客户建立的每个连接都会消耗一定的系统资源,所以如果你是为一个大型网络提供代理服务的话,一定要正确地修改该值。因为如果同一时间的连接数量太大的话,可能会消耗大量的系统资源,从而导致服务器宕机。缺省值为1天,该值太大了,建议根据你自己的情况适当减小该值。
    read_timeout time-units
    说明:如果在指定的时间内squid尚未从被请求的服务器读入任何数据,则squid将终止该客户请求。缺省值为15分钟。

    half_closed_clients on/off
    说明:有时候由于用户的不正常操作,可能会使与squid的TCP连接处于半关闭状态,
    这时候,该TCP连接的发送端已经关闭,而接收端正常工作。缺省地,squid将一直保持这种处于半关闭状态的TCP连接,直到返回套接字的读写错误才将其关闭。如果将该值设为off,则一旦从客户端返回“no more data to read”的信息,squid就立即关闭该连接。

    request_timeout:

    说明:设置在建立与客户的连接后,squid将花多长时间等待客户发出HTTP请求。默认为5分钟,设置为1分钟。

    四、建立缓存并运行

    /usr/local/squid/sbin/squid -z

    /usr/local/squid/sbin/squid -k parse

    看一下 配置是不是正确,如果没有语法错误会没有提示
    /usr/local/squid/sbin/squid -N -d1
    看是否有错。。。。不过当前控制台会死掉的

    另开一个控制台运行

    /usr/local/squid/sbin/squid -k shutdown

    关掉squid相关进程

    ps -aux|grep squid

    一定要没有相关的squid进程才能继续下一步,如果有相关的进程,使用kill –9 吧

    chown squid.squid /usr/local/squid/var/squid.out

    chown squid.squid /var/run/squid.pid

    以后运行squid使用以下语句

    su squid -c "/usr/local/squid/bin/RunCache &"

    并把上述命令加到/etc/rc.local中
    测试一下是否有进程
    ps -aux|grep squid

    循环squid的日志

    crontab -e

    40 23 * * * /usr/local/squid/sbin/squid -k rotate

    每天晚上23:40分开始循环squid的日志

    注释:

    acl myacl src "/path/to/acl/filename" 可以将长的源地址放置在文件里,每个地址一行
       acl myacl2 arp "/path/to/acl/filename"放置网卡的物理地址到一个文件里,每个地址一行
          1.当更改过配置文件后最好验证一下配置文件:squid -k parse
         2.记得创建缓存目录,而且要设置好var的目录权限为cache_effective_user参数中所指定的用户

     

  13. visible_hostname 192.168.34.253

    squid ssl问题

    在网上找了找资料这样设置

    1.生成测试用的证书:

    openssl req -new -keyout /etc/squid/key.pem -nodes -x509 -days 365 -out /etc/squid/cert.pem

    2. 在squid.conf相应地方添加

    https_port 443 cert=/etc/squid/cert.pem /etc/squid/key.pem transparent

    但是设了之后 网易的邮箱可以用了 ,但是支付宝,和网上银行还是不行 ,很不方便,求救了··大家帮帮忙那

老问题重提,关于squid正向透明代理ssl,望大家帮忙!谢谢

#openssl req -new -keyout /etc/squid/key.pem -nodes -x509 -days 365 -out /etc/squid/cert.pem
#$IPT -t nat -A PREROUTING -s $LAN_IP -i $LAN -p tcp --dport 443 -j DNAT --to 10.0.0.3:50402

squid.conf
https_port 10.0.0.3:50402 transparent cert=/etc/squid/cert.pem key=/etc/squid/key.pem
  1. QQ空间无法完全打开
  2. acl qq srcdomain   .qq.com
    always_direct allow qq

    把上面二行加上就可以了

换成2.7,真的解决了。谢谢

acl QUERY urlpath_regex cgi-bin .aspx .php .cgi .asp   -------加到这里
cache deny QUERY

可以直接把不需要缓存的文件加到后边

squid的透明代理无法上传WEB附件问题

局域网使用squid2.6作透明代理,有几个问题一直没有解决。
1.163、126的Web Mail系统,virscan.org无法上传发送附件。
2.hi.baidu.com空间无法编辑现有文章保存内容。
不是使用线路问题,不使用squid代理没有上述问题。

在squid.conf中也设置了
request_body_max_size 0
acl Uploads method PUT POST

还是不行。

squid 所支持的同时使用的用户数量

理论上讲,这个是没有限制的
但对于squid,有两个方面需要注意
1,文件描述符是否够用
2,dns_chinldren是否设置合理

forwarded_for off
header_access Via deny all
header_access All allow all
是这个吧

设置
forwarded_for off
访问ip138得到的值是unknow

 

check_hostnames off 检查主机名
dns_retransmit_interval 1 seconds dns重新查询间隔
url_rewrite_children 1000 重定向数
url_rewrite_concurrency 1

#  TAG: url_rewrite_access
#       If defined, this access list specifies which requests are
#       sent to the redirector processes.  By default all requests
#       are sent.
#
#Default:
# none

如果定义,此访问列表指定哪些请求发送到重定向进程。默认情况下所有的请求
发送。


location_rewrite_children 50 位置重写数。
# quick_abort_min 16 KB
# quick_abort_max 16 KB
# quick_abort_pct 95






 

阅读(998) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~