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

简单squid 缓存服务器配置--献给和我一样的新手

2012-07-18 19:09 232 查看
简单squid 缓存服务器配置--献给和我一样的新手

环境介绍:
服务 主机名 IP
Squid cdn.fantong.com 192.168.1.125
Web db.fantong.com 192.168.1.122
内网测试需要绑定HOST文件

服务端:
Squid 版本选择 squid-3.0.STABLE8.tar.gz

wget http://ftp.vim.org/internet/squid/squid-3.0.STABLE8.tar.gz

客户端
安装http 自行写个首页文件能访问.

Useradd squid
Groupadd squid

安装squid
文件放在/usr/local/src 下
tar –zxvf squid-3.0.STABLE8.tar.gz
/usr/local/src/squid-3.0.STABLE8
安装squid 的配置较多 建议做个shell 来运行
#!/bin/bash
./configure --prefix=/usr/local/squid3 \
--enable-dlmalloc \
--enable-debug-cbdata \
--enable-async-io=100 \
--with-pthreads \
--enable-storeio="aufs,coss,diskd,ufs" \
--enable-removal-policies="heap,lru" \
--enable-icmp \
--enable-delay-pools \
--enable-useragent-log \
--enable-referer-log \
--disable-wccp \
--disable-wccpv2 \
--enable-kill-parent-hack \
--enable-arp-acl \
--enable-snmp \
--enable-default-err-language=Simplify_Chinese \
--enable-err-languages="Simplify_Chinese English" \
--disable-poll \
--enable-epoll \
--disable-ident-lookups \
--disable-internal-dns \
--enable-truncate \
--enable-underscores \
--enable-basic-auth-helpers="NCSA" \
--enable-stacktrace \
--with-winbind-auth-challenge \
--enable-large-cache-files --with-large-files \
--with-maxfd=32768\
--enable-ssl \
--enable-x-accelerator-vary

Make && make install
#创建缓存文件夹和日志文件夹并更改属主 属组
Mkdir –p /usr/local/squid3/var/cache
Mkdir –p /usr/local/squid3/var/logs
Chown squid:squid /usr/local/squid3/var/cache
Chown squid:squid /usr/local/squid3/var/logs

修改/usr/local/squid3/etc/squid.conf

Echo > squid.conf
清空文件 (里面的选项太多了2000多行)

cache_effective_user squid
cache_effective_group squid
#必须要有的主机名
visible_hostname cdn.fantong.com
#配置为http 加速模式
http_port 80 accel vhost vport
icp_port 3130
#下面的配置有待研究
#cache_peer db.fantong.com sibling 80 3130
#cache_peer squid3.ibm.com.cn sibling 80 3130

#这个主要是用于配置如果当前缓存中如果没有请求的内容,就去兄弟服务器或者父亲服务器或者源地址去取需要的内容。
#cache_peer 192.168.1.122 parent 80 0 no-query originserver round-robin name=webServer1

cache_peer 192.168.1.122 parent 80 0 no-query originserver round-robin name=cdn.fantong.com

#acl localnet src 192.168.1.125
acl all src
http_access allow all
icp_access allow all
cache_log /usr/local/squid3/var/logs/cache.log
access_log /usr/local/squid3/var/logs/access.log squid
cache_dir ufs /usr/local/squid3/var/cache/ 1000 16 256
maximum_object_size 10240 KB
maximum_object_size_in_memory 512 KB
cache_mem 256 MB

检测配置文件是否正确:
squid -k parse

初始化squid
/usr/local/squid2/sbin/squid –z

启动squid

/usr/local/squid3/sbin/squid -Nd1

查看是否启动
ps aux |grep squid





测试是否命中

curl -I http://192.168.1.125 HTTP/1.0 200 OK
Date: Wed, 18 Jul 2012 10:03:31 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Fri, 13 Jul 2012 02:02:23 GMT
ETag: "180f68-6d-789089c0"
Accept-Ranges: bytes
Content-Length: 109
Content-Type: text/html; charset=UTF-8
Age: 980
X-Cache: HIT from cdn.fantong.com
Via: 1.0 cdn.fantong.com (squid/3.0.STABLE8)
Connection: close

倒数第3行x-cache:HIT 代表命中 x-cache:miss 代表未命中

以上为简单squid 配置,如果有错误请联系QQ:57674891 指正。第3次写技术博客希望大家多多包涵。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 配置 服务器 squid