squid安装使用
来源:互联网 发布:软件产品质量控制 编辑:程序博客网 时间:2024/06/05 19:48
背景:
公司为节约成本,需要部署反向代理设备,用以缓存视频文件,节省机房出口带宽,增加廉价机房的上联出向流量。本人之前接触较多squid,但由于前公司使用时间较久,个人也是在使用上熟悉,接下来就是自己部署的过程记录,方便大家查阅。本文只解释编译安装的方法。安装环境:
系统环境:Ubuntu 12.04.1 LTS. x86_64 8G内存,12核心。由于是dell服务器,只得系统盘做了raid1,数据盘做了raid5.数据盘挂在了/srv下,整个磁盘大小是40T.可用大小37T。
软件环境:
登录到squid官网,http://www.squid-cache.org/Versions/ 下载最新版本。因为只用到基本功能,因此,只需要下载稳定版本即可。这里我选择的是3.5.22版本,发布时间2016-10.9日,下载链接:http://www.squid-cache.org/Versions/v3/3.5/squid-3.5.22.tar.gz。
软件安装及配置:
下载上边软件链接到本地服务器上,解压后生成一个名为squid-3.5.22的文件夹,该文件便是squid的源码。详细使用方法可以参考这里,http://zyan.cc/book/squid/ 此链接为squid的中文权威指南。对squid的基本使用和原理做了比较详尽的解释。编译安装:
安装前先对ubuntu系统进行软件升级apt-get update安装编译需要的环境apt-get install build-essential下载安装wget http://www.squid-cache.org/Versions/v3/3.5/squid-3.5.22.tar.gztar -zxvf squid-3.5.22.tar.gzcd squid-3.5.22/./configure --prefix=/var/www/dream/squid --sysconfdir=/var/www/dream/squid/etc--enable-arp-acl--enable-linux-netfilter--enable-pthreads--enable-err-language="Simplify_Chinese"--enable-default-err-language="Simplify_Chinese"--enable-storeio=ufs,aufs ##确定使用存储的格式,这里由于我们存储较大视频文件10M左右甚至以上,所以这里选择aufs。--enable-baisc-auth-helpers="NCSA"--enable-underscoremakemake installln -s /var/www/dream/squid/sbin/squid /usr/bin/squid ##设置squid成为系统可以识别的系统命令。
配置:
#<common_begin############################## Common ACL Define #################################acl localhost src 127.0.0.1/255.255.255.255acl monitor src 127.0.0.1/255.255.255.255acl manager proto cache_objectacl SSL_ports port 443acl Safe_ports port 80 # httpacl Safe_ports port 21 # ftpacl Safe_ports port 443 # httpsacl Safe_ports port 70 # gopheracl Safe_ports port 210 # waisacl Safe_ports port 1025-65535 # unregistered portsacl Safe_ports port 280 # http-mgmtacl Safe_ports port 488 # gss-httpacl Safe_ports port 591 # filemakeracl Safe_ports port 777 # multiling httpacl CONNECT method CONNECThttp_access deny !Safe_portshttp_access deny CONNECT !SSL_portsacl PURGE method PURGEhttp_access allow PURGE localhosthttp_access deny purgehttp_access allow manager monitorhttp_access deny manager acl snmppublic snmp_community publicsnmp_access allow snmppublic localhostacl spider_ua req_header User-Agent -i spiderhttp_access deny spider_uaacl ip_in_fqdn url_regex -i ^http://[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/.*http_access deny ip_in_fqdn#acl allow_ip src "/var/www/dream/squid/etc/allow_ip"#http_access allow allow_ip#http_reply_access allow allow_ip######### Device Configuration Define ###############visible_hostname proxy45-236#cache_dir Directory-Name Mbytes Level-1 Level2 cache_dir aufs /srv/cache1 3000000 128 128 min-size=1000000maximum_object_size 10240000 KBminimum_object_size 0 KBstore_dir_select_algorithm round-robincache_replacement_policy lrucache_swap_low 80cache_swap_high 85reload_into_ims on#request_header_access Via allow all#header_access Via allow all#header_access X-Cache deny all#header_access X-Cache-Lookup deny all#header_access X-Squid-Error deny alldns_timeout 2 minutedns_retransmit_interval 10 secondsnegative_dns_ttl 1 minute#refresh_stale_hit 0 minutevary_ignore_expire onrequest_timeout 40 secondspersistent_request_timeout 5 secondsconnect_timeout 1 minuteread_timeout 15 minutesserver_persistent_connections offclient_persistent_connections offcollapsed_forwarding onforwarded_for on#ignore_expect_100 onmaximum_object_size_in_memory 2 MBcache_mem 512 MBmemory_replacement_policy lru#logformat squid_custom_log %ts.%03tu %6tr %{X-Real-IP}>h %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt "%{Referer}>h" "%{User-Agent}>h" "%{Cookie}>h"logformat squid_custom_log %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt "%{Referer}>h" "%{User-Agent}>h" "%{Cookie}>h"cache_access_log /var/www/dream/squid/var/logs/access.log squid_custom_logstrip_query_terms offlogfile_rotate 0cache_log /var/www/dream/squid/var/logs/cache.logcache_store_log none#http_port 80 accel vhost vport#http_port 9090 accel vhost vport=80 allow-direct http_port 80 accel vhost vport allow-direct #http_port 80icp_port 3130icp_access allow allsnmp_port 3401cache_effective_user squid cache_effective_group squidpid_filename /var/www/dream/squid/var/run/squid.piddiskd_program /var/www/dream/squid/libexec/diskdunlinkd_program /var/www/dream/squid/libexec/unlinkdhalf_closed_clients off#client_db off#cachemgr_passwd test4squid config#cache_mgr support@chinacache.comhosts_file /var/www/dream/squid/etc/hosts.conf#dns_nameservers 127.0.0.1dns_nameservers 8.8.8.8################Domain Begin#####会把Range头去掉,再回后端服务器。所以都能取回整个文件。默认range_offset_limit 0 如果请求带有Range头,则squid会把Range头部转发到后端,不会预取多余的数据。range_offset_limit -1#这样的话比如一个1G的文件,用户下载到1M中断了,squid会一直把1G文件下载下来,但是如果文件大小超过"maximum_object_size"大小呢,下载完毕又放弃了。 quick_abort_min -1################Domain End###### Add any of your own refresh_pattern entries above these.coredump_dir /var/www/dream/squid/var/cache/squidrefresh_pattern -i ^http 1440 0% 1440 ignore-reload override-lastmodhttp_access allow allhttp_reply_access allow all
以上配置可以让服务正常跑起来。
日志定期清理脚本并保留近30天日志
#!/bin/shset -eyesterday_date=$(date -d "1 day ago" +%Y%m%d)cd /var/www/dream/squid/log/# rename the current log file without interrupting the logging processmv access.log access.log.$yesterday_datemv cache.log cache.log.$yesterday_date# tell Squid to close the current logs and open new ones/var/www/dream/squid/sbin/squid -k rotate -f /var/www/dream/squid/etc/squid.conf/var/www/dream/squid/sbin/squid -k rotate -f /var/www/dream/squid/etc/squid1.conf/var/www/dream/squid/sbin/squid -k rotate -f /var/www/dream/squid/etc/squid2.conf/var/www/dream/squid/sbin/squid -k rotate -f /var/www/dream/squid/etc/squid3.conf# give Squid some time to finish writing swap.state filessleep 30mv access.log.$yesterday_date bak/mv cache.log.$yesterday_date bak/gzip -9 bak/access.log.$yesterday_dategzip -9 bak/cache.log.$yesterday_datefind bak/ -type f -ctime +30 | xargs rm
0 0
- squid安装使用
- Squid – 安装、配置、使用
- squid的安装和使用
- centos7安装和使用http代理(squid)
- squid缓存服务器安装和使用
- Squid 代理服务器安装配置和使用
- 安装Squid
- Squid安装
- squid安装
- Squid安装
- squid使用
- Squid使用
- squid日志分析软件sarg的安装和使用
- Ubuntu9.04安装使用 用户名和密码 的squid代理服务器
- squid安装(squid加速apache)
- squid使用手册第一章 squid的安装
- Squid安装配置[转]
- squid 安装 配置
- 嵌入式软件可靠性设计的一些理解
- 使用xml文件备份短信
- c语言仓库信息管理
- windows使用npm安装node.js环境express提示失败解决办法
- JDBC
- squid安装使用
- Atitit 图像处理Depixelizing Pixel Art像素风格画的矢量化
- 不用第三个变量交换两个变量
- 华东交通大学2016届新生选拔赛:1010 我是签到题
- 数据结构---栈的应用
- 对”对象和类“的理解
- hibernate配置报错
- 第十六周项目一验证算法(3)直接选择排序
- Cannot change version of project facet Dynamic web