公司里的编辑 和 监控人员的工作就是天天再刷帖~~ 一个帖里面又有很多图片罗。 导致公司内部网络 有点牛车。。所以很需要我在公司内部的服务器上做一个 内部CDN 。针对公司的网站进行前端CACHE。 这样的话~~ 哇咔咔 公司内部网速就快罗
还是进行简单的安装吧。
Feebsd 系统
#/usr/ports/www/squid
# make install clean
# echo "squid_user=root" >> /etc/rc.conf 因为要启动 80端口 1024口以下的都必须 root 权限才行啦
# echo "squid_enable=yes" >> /etc/rc.conf
启动前创建存储目录:
/usr/local/sbin/squid -z
squid 的配置:
http_port 80 vhost vport dns_nameservers 202.103.224.68 202.103.224.69 visible_hostname beihai365 cache_dir ufs /var/spool/squid 2048 16 256 cache_mem 1000 MB cache_mgr 237852571@qq.com redirect_children 30 cache_access_log /var/log/squid/access.log cache_log /var/log/squid/cache.log cache_store_log /var/log/squid/store.log cache_peer 222.216.28.180 parent 80 0 no-query originserver name=edns cache_peer 222.216.28.226 parent 80 0 no-query originserver name=img cache_peer_domain edns www.beihai365.com cache_peer_domain img img.beihai365.com acl webserver dst 222.216.28.180 acl imgserver dst 222.216.28.226 http_access allow imgserver http_access allow webserver
因为只是测试。我没有给内部的DNS 做 zone 。所以暂时现在hosts文件里面进行 域名映射先。
# Copyright (c) 1993-1999 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host 127.0.0.1 localhost 192.168.1.241 www.beihai365.com 192.168.1.241 img.beihai365.com
好了。开始刷新网站。然后看下是否有 HIT 还是 MISS .. 用 firebug 看也行 看 x-cache 标记. 如下:
X-Cache | HIT from beihai365 |
Via | 1.0 beihai365 (squid/3.0.STABLE25) |
看到就知道 是经过了 CDN 处理了 而且 命中了
没有 firebug 的朋友就直接看日志啦
beihai365test# cat /var/log/squid/access.log | grep '329_437921_c975259b1f1ed19' 1299919890.545 5074 192.168.1.238 TCP_MISS/200 380347 GET http://img.beihai365.com/bbs/Mon_1103/329_437921_c975259b1f1ed19.jpg - FIRST_UP_PARENT/img image/jpeg 1299919899.490 16 192.168.1.238 TCP_HIT/200 380355 GET http://img.beihai365.com/bbs/Mon_1103/329_437921_c975259b1f1ed19.jpg - NONE/- image/jpeg 1299919913.489 15 192.168.1.238 TCP_HIT/200 380355 GET http://img.beihai365.com/bbs/Mon_1103/329_437921_c975259b1f1ed19.jpg - NONE/- image/jpeg 1299919915.818 20 192.168.1.238 TCP_HIT/200 380355 GET http://img.beihai365.com/bbs/Mon_1103/329_437921_c975259b1f1ed19.jpg - NONE/- image/jpeg
哦也~~ 准备整合到 内部 DNS 里面去~~