博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用Squid搭建局域网视频缓存代理
阅读量:4282 次
发布时间:2019-05-27

本文共 5826 字,大约阅读时间需要 19 分钟。

1. 安装squid2.7版本,一定要2.7版本,新版本不支持
 
$ ./configure --prefix=/usr/local/squid --sysconfdir=/usr/local/squid/etc --bindir=/usr/local/squid/bin --sbindir=/usr/local/squid/sbin --mandir=/usr/local/squid/share/man --enable-gnuregex --enable-carp --enable-async-io=80 --enable-removal-policies=heap,lru --enable-icmp --enable-delay-pools --enable-useragent-log --enable-referer-log --enable-kill-parent-hack --enable-snmp --enable-arp-acl --enable-htcp --enable-cache-digests --enable-default-err-language=Simplify_Chinese --enable-err-languages="Simplify_Chinese" --enable-poll --enable-linux-netfilter --disable-ident-lookups --enable-underscores --enable-auth="basic" --enable-basic-auth-helpers="NCSA" --enable-external-acl-helpers="ip_user" --enable-x-accelerator-vary
$ make
 
$ make install
 
2. 修改配置文件
 
$ cd /usr/local/squid/
 
在alc部分添加下面代码
 

#rewrite store url youku tudou souhu iqiyi
acl store_url url_regex -i ^http:\/\/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/.*(\.flv|\.m4v\?|\.f4v\?|\.mp4\?|\.ts\?|\.letv\?)
acl store_url_no_domain urlpath_regex -i ^\/(.*\/.*\.flv$)

storeurl_access allow store_url
storeurl_access allow store_url_no_domain
storeurl_access deny all

storeurl_rewrite_program /usr/local/squirm/bin/squirm
storeurl_rewrite_children 5

3. 运行squid
 
第一次运行时,先运行squid -z创建缓存文件夹。缓存文件夹在/usr/local/squid/var下创建,因此创建缓存前还需运行chmod 777 /usr/local/squid/var给该文件夹权限。 


再运行squid -d 1开启squid即可。 


如果要关闭squid,运行squid -k shutdown则是安全关闭。 
 
$ /usr/local/squid/sbin/squid
 
启动时报错了,如下
FATAL: Cannot open '/usr/local/squid/var/logs/access.log' for writing.
 The parent directory must be writeable by the
 user 'nobody', which is the cache_effective_user
 set in squid.conf.
Squid Cache (Version 2.7.STABLE9): Terminated abnormally.
CPU Usage: 0.005 seconds = 0.001 user + 0.004 sys
Maximum Resident Size: 15008 KB
Page faults with physical i/o: 0
 
修改权限解决:
 
$ chown -R nobody /usr/local/squid/var/logs/access.log
echo>var/logs/store.log
$ chown -R nobody /usr/local/squid/var/logs/store.log
$ ./sbin/squid -z
$ ./sbin/squid -d 1
 
4. 修改/etc/resolve.conf添加DNS
 
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.237.2
nameserver 192.168.199.1
nameserver 114.114.114.114
nameserver 8.8.8.8
search localdomain
 
5.  安装squirm
wget http://squirm.foote.com.au/squirm-1.0betaB.tar.gzmv squirm-1.0betaB.tar.gz /usr/local/srccd /usr/local/src/tar xvf squirm-1.0betaB.tar.gzcd squirm-1.0betaBcd regex./configuremake cleanmakecp -p regex.o regex.h ../cd ../makemake install
6.  配置squirm
 
 
$ cd /usr/loca/squirm/etc/
$ cp squirm.local.dist squirm.local
$ squirm.patterns.dist squirm.patterns
 
修改squirm.local文件,将客户端所在的IP地址段,以标准C类IP地址段为单位,以192.168.1的形式,每行一个记录,写入到该文件中。这些地址,不是squid进程所在的主机IP,而是使用squid的客户端的IP地址,即用户IP。
[root@webcache ~]# more /usr/local/squirm/etc/squirm.local127.0.010.1.510.1.6
编辑squirm.patterns文件,重写来自优酷以及其他在线视频网站的“媒体文件URL”。
# tudou video cdn has change to youku ,but keep it!regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}[^&]*/f4v/.*id=tudou.itemid\=([0-9]*).* http://www.tudou.com.SQUIDTUDOUA/\1regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}[^&]*/flv/.*id=tudou.itemid\=([0-9]*).* http://www.tudou.com.SQUIDTUDOUB/\1#site:sohu tv status:OK date:20141024regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/sohu/[0-9]/[0-9]*/[0-9]*/(.*)\.mp4\?key=.* http://tv.sohu.com.SQUIDSOHUTV/\1.mp4#site:iqiyi status:OK date:201403120956  regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/videos/v/.*/(.*\.f4v)?  http://www.iqiyi.com.SQUIDIQIYI/\1#site:youku part-tudou status:OK date:201403120956regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/youku/.*/(.*-.*-.*-.*-[^?]*)(.*) http://www.youku.com.SQUIDYOUKU/\1#site:letv status:OK date:201403122047regex http://[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]*/[0-9]*/[0-9]*/letv-uts/[0-9]*/(.*_mp4)/(.*)\.ts\? http://www.letv.com.SQUIDLETVA/\1/\2.mp4regex http://[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]*/[0-9]*/[0-9]*/letv-uts/(.*)\.letv\?.*\&video_type=(...)\&.*\&rstart=(.*)\&rend=(.*)  http://www.letv.com.SQUIDLETVB/\1-\3-\4.\2#site:v.qq.com status:OK date:201403122102regex http://[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]*/.*\.qq\.com/.*/[0-9]*/[0-9]*/(.*)\.mp4\? http://v.qq.com.SQUIDQQ/\1.mp4#site:v.ifeng.com status:OK date:201403130838regex http://[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/data[0-9]*/documentary/[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/(.*)\.mp4 http://v.ifeng.com.SQUIDIFENG/\1.mp4#site:56 status:OK date:201403130846regex http://[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/.*\.56\.com/flvdownload/[0-9]*/[0-9]*/(.*)\.flv\?.* http://www.56.com.SQUID56/\1.flv#此文件内容,需要不断的发现、归纳、丰富!
通过squidclient -h 127.0.0.1 mgr:store_rewriter命令查询squirm的运行状态。如下所示,
[root@webcache ~]# squidclient -h 127.0.0.1 mgr:store_rewriterHTTP/1.0 200 OKServer: squid/2.7.STABLE9Date: Mon, 17 Mar 2014 08:32:23 GMTContent-Type: text/plainExpires: Mon, 17 Mar 2014 08:32:23 GMTX-Cache: MISS from webcacheVia: 1.0 webcache:3128 (squid/2.7.STABLE9)Connection: closeRedirector Statistics:program: /usr/local/squirm/bin/squirmnumber running: 5 of 5requests sent: 154replies received: 154queue length: 0avg service time: 0.37 msec#      FD     PID  # Requests     # Pending       Flags      Time  Offset Request1       9    8044         120             0                 0.000       0 (none)2      10    8045           0             0                 0.000       0 (none)3      11    8046           0             0                 0.000       0 (none)4      12    8047           0             0                 0.000       0 (none)5      14    8048           0             0                 0.000       0 (none)Flags key:B = BUSYC = CLOSINGS = SHUTDOWN[root@webcache ~]#

转载地址:http://xocgi.baihongyu.com/

你可能感兴趣的文章
vc滚动条 WM_VSCROLL消息16位屏障问题
查看>>
mfc CEdit焦点获取
查看>>
mfc动态按钮
查看>>
vs 获取当前程序文件的路径方法
查看>>
vc 回调函数
查看>>
Marddown学习
查看>>
Mac os中idea使用try catch快捷键
查看>>
无器械健身读后精简
查看>>
狂神说java,html5基础知识讲解全总结
查看>>
Mac idea 替换快捷键
查看>>
CSS3 position sticky固定定位失败的原因
查看>>
狂神说Java CSS3讲解综合代码
查看>>
springboot-mybaits 的mapper文件中使用insert into xx values(xxx) on duplicate key update
查看>>
python-day2 python的基本语法(注释,运算符,数据类型,在python中,定义变量时,不需要指定变量的类型的)
查看>>
Springboot-data-es 自动创建mapping(mapping的数据结构为空)以及自动添加新字段(生成mapping的数据结构)
查看>>
数据分析-day04-pandas-dataFrame中查询数据与修改赋值修改语句(r=df[df["z"]==6] & df["z"]=6)
查看>>
数据分析-day06-pandas-dataFrame案例分析1(方法一):获取title字段中包含物流运输业名称作为分类,统计各个分类的条数
查看>>
数据分析-day06-pandas-dataFrame案例分析1(方法二):获取title字段中包含物流运输业名称作为分类,统计各个分类的条数,
查看>>
数据分析-day06-pandas-dataFrame案例分析4:使用PeriodIndex将离散组成pandas的时间序列,然后统计不同时间段,两个地方的pm值走势
查看>>
static synchronized方法和synchronized方法的区别和联系-2(class锁和对象锁,不同锁,混合访问时)
查看>>