SQUID历史最悠久的一款cache加速服务
1.安装
# wget http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.23.tar.gz
# ./configure --prefix=/usr/local/squid --disable-carp --with-aufs-threads=32 --with-pthreads --with-large-files --enable-storeio='ufs,aufs' --enable-disk-io='AIO,Blocking' --enable-removal-policies='heap,lru' --disable-wccp --enable-kill-parent-hack --enable-snmp --disable-poll --disable-select --disable-ipv6 --enable-auth=basic --with-aio --disable-ident-lookup --enable-useragent-log --enable-referer-log --with-filedescriptors=65536 --with-pidfile=/var/run/squid.pid
# make
# make install
2.配置
# vi /usr/local/squid/etc/squid.conf
# #内容如下
http_port 80 accel vhost vport #监听的端口
logfile_rotate 10
log_fqdn off
cache_swap_low 90
cache_swap_high 97
cache_mem 1536 MB
cache_mgr admin
cachemgr_passwd test all
cache_effective_user www
cache_effective_group www
coredump_dir /usr/local/squid/var/cache
cache_dir ufs /usr/local/squid/var/cache 51200 16 256
cache_replacement_policy lru
memory_replacement_policy lru
cache_store_log none
cache_access_log /usr/local/squid/var/logs/accesslog
cache_log /usr/local/squid/var/logs/cachelog
fqdncache_size 1024
mime_table /usr/local/squid/etc/mimeconf
error_directory /usr/local/squid/share/errors/en-us/
icon_directory /usr/local/squid/share/icons/
err_page_stylesheet /usr/local/squid/etc/errorpagecss
emulate_httpd_log on
max_open_disk_fds 0
tcp_recv_bufsize 655350 bytes
request_header_max_size 5 KB
memory_pools on
memory_pools_limit 64 MB
via off
maximum_object_size 500 MB
minimum_object_size 0 KB
maximum_object_size_in_memory 5120 KB
pipeline_prefetch on
forwarded_for off
forward_timeout 2 minutes
client_lifetime 1 hours
client_persistent_connections off
server_persistent_connections on
half_closed_clients off
httpd_suppress_version_string on
check_hostnames off
visible_hostname CDN.ufstone.net
pid_filename /var/run/squidpid
vary_ignore_expire off
negative_ttl 0 minutes
reply_header_access Server deny all
reply_header_access Warning deny all
reply_header_access Expires deny all
reply_header_access Via deny all
reply_header_access Connection deny all
peer_connect_timeout 30 seconds
request_timeout 1 minutes
persistent_request_timeout 2 minutes
client_lifetime 30 minutes
half_closed_clients off
pconn_timeout 25 seconds
shutdown_lifetime 20 seconds
request_timeout 1 minutes
persistent_request_timeout 1 minutes
icp_port 3130
icp_hit_stale off
icp_access allow all
acl localhost src 127.0.0.1
acl to_localhost dst 0.0.0.0/32
acl manager proto cache_object
http_access allow manager localhost
acl Safe_ports port 80 # http
http_access deny !Safe_ports
acl CONNECT method CONNECT
acl SSL_ports port 443 563
http_access deny CONNECT !SSL_ports
acl PURGE method PURGE
http_access allow PURGE localhost
hierarchy_stoplist -i ^https:\\ ? cgi-bin ?
acl denyssl urlpath_regex -i ^https:\\
no_cache deny denyssl
acl QUERY urlpath_regex -i cgi-bin \? \asp \php \jsp \cgi Servlet
no_cache deny QUERY
#acl broken302 http_status 400-404 302
#http_access deny broken302
http_access allow all
#SNMP with Cacti config here
snmp_port 3401
acl snmppublic snmp_community valesquid
snmp_access allow snmppublic localhost
snmp_access deny all
#snmp_incoming_address 0.0.0.0
#snmp_outgoing_address 0.0.0.0
cache_peer 192.168.118.153 parent 80 0 no-query no-digest no-netdb-exchange originserver name=b #源配置
cache_peer_access b allow all
refresh_pattern -i \/$ 3 90% 6 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private
refresh_pattern -i \.html$ 43200 90% 86400 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private
refresh_pattern -i \.htm$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.shtml$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.vhtml$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.hml$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.gif$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.swf$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.jpg$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.png$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.bmp$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.js$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.css$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.wma 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.zip 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.mp3 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.rar 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.flv$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.wmv$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.exe$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern . 43200 20% 86400
3.初始化和启动服务
# useradd www -s /sbin/nologin # 创建用户
# mkdir -p /usr/local/squid/var/cache && mkdir /usr/local/squid/var/logs #创建日志目录和cache目录
# chown -R www.www /usr/local/squid/var/cache
# /usr/local/squid/sbin/squid -z #初始话squid
# /usr/local/squid/sbin/squid #启动squid服务
# curl -I http://m.hebiw.ufstone.net/zixun/
HTTP/1.0 200 OK
Pragma: no-cache
Content-Type: text/html; charset=gb2312
Content-Length: 31074
X-Cache: MISS from CDN.ufstone.net #未命中缓存
# curl -I http://m.hebiw.ufstone.net/zixun/
HTTP/1.0 200 OK
Pragma: no-cache
Content-Type: text/html; charset=gb2312
Content-Length: 31074
Age: 1 #已经缓存的时间单位秒(s)
X-Cache: HIT from CDN.ufstone.net #已命中缓存
详细配置将在http://blog.csdn.net/cwg_1992/article/details/24240735中细说
#####################################################
迷途小运维原创
作者:john
转载请注明出处