概述
关于CDN的介绍及讨论请看另一篇
本篇分两部分.一个squid反向代理,加速,一个是智能DNS,两个的结合才能构成一个完整的CDN服务.
本文不作过多的理论原理介绍,仅作为一个基本的安装配置过程,实施流程
squid
squid 为一个开源的代理软件,可以在这下载. http://www.squid-cache.org/Versions/,最新稳定版本为 3.0
wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE4-20080406.tar.gz
解压安装
tar –zxvf squid-3.0.STABLE4-20080406.tar.gz
cd squid-3.0.STABLE4-20080406
./configure –prefix=/home/server/squid
make all
make install
如果能顺利完成,没提示什么Error中断话就安装完了.
安装完要做修改配置文件为 etc/squid.conf
http_port 80 vhost vport
cache_peer (IP) parent 80 0 no-query originserver #IP 为你源站服务器的IP
cache_mem 16 MB
cache_swap_low 90
cache_swap_high 95
cache_dir ufs /home/server/squid/var/cache 100 16 256
cache_effective_user
visible_hostname localhost
把 http_access deny all 改为 http_access allow all
保存
启动测试
/home/server/squid/sbin/squid -z
/home/server/squid/sbin/squid –s
这样,一个最简单的反向代理,或叫CDN,就完成了.
但这样只是实现了最基本的功能),不是最优和最安全的设置.在多域名或多IP源站时,还需更多的设置.
bind
bind 为开源的DNS服务器软件,下载 http://www.isc.org/index.pl?/sw/bind/
解压安装
tar –zxvf bind-9.4.2.tar.gz
cd bind-9.4.2
./configure –prefix=/home/server/bind
make
make install
配置
cd /home/server/bind 因为默认安装好后,是没有配置文件的,在etc目录里面建立相关的文件.文件内容及模板,可以网上搜一下.或是在bind的安装文件里也有的.find 一下 name.conf 文件就可以
主要有
named.root 这个文件可以用 dig > named.root 得到内容
named.conf //
options {
directory "/home/server/bind/etc";
statistics-file "/var/named/data/named_stats.txt";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
// recursion no;
listen-on { 127.0.0.1;主IP;};
allow-notify { 辅IP;};
allow-transfer {辅IP;};
};
key "rndc-key" {
algorithm hmac-md5;
secret "tYAivmr9FhK3W9g==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
include "ip_tables.txt";//IP库
view "view_cnc" {
key "cnc" {
algorithm hmac-md5;
secret "xHs/RBx7pdzBiCd9==";
};
allow-transfer { key cnc; };
match-clients { key cnc;!辅IP; CNC;};
server辅IP { keys cnc;};
zone "." {
type hint;
file "named.root";
};
include "master/cnc.def";
};
view "view_any" {
key "any" {
algorithm hmac-md5;
secret "Q5vz969Ct4wFeOzw==";
};
allow-transfer { key any; };
match-clients { key any;! 辅IP;any;};
server辅IP { keys any;};
zone "." {
type hint;
file "named.root";
};
include "master/telecom.def";
};
//部分解释
rndc控制命令的key
sbin/rndc-confgen > etc/rndc.conf
KEY用这个生成 sbin/dnssec-keygen
如: sbin/dnssec-keygen -a HMAC-MD5 -b 128 -n HOST cnc
用生成的KEY替换上面named.conf里的.
master/cnc.def
master/telcom.def
为对应的电信/网通的named.conf文件,这里也可以直接放在named.conf里的,但这样独立出来,方便管理.格式为:
zone "test.com" {
type master;
file "master/telecom/test.com";
//file "master/cnc/test.com";//网通
};
智能DNS的关键就在这了.根据IP库判断是用cnc or telcom的记录指向到不同的服务器上
域名记录文件:如:test.com
$TTL 86400
$ORIGIN test.com.
@ IN SOA test.com. root. test.com.(
2006113010 ;Serial
28800 ; Refresh ( seconds )
14400 ; Retry ( seconds )
720000 ; Expire ( seconds )
86400 );Minimum TTL for Zone ( seconds )
IN NS ns1. test.com.
IN NS ns2. test.com.
@ IN A ip
www IN A IP
NS1 IN A IP
NS2 IN A IP
;
;end
ip_tables.txt 内容格式
acl "CNC" {
58.16.0.0/16;
58.17.0.0/17;
58.17.128.0/17;
…
};
至此,DNS的配置就基本完成了.
启动测试
/home/servers/bind/sbin/named -c /home/servers/bind/etc/named.conf -u named
可以查看/var/log/messages 学会查看这个文件,能帮助你解决很多的问题
nslookup
server IP
test.com/www.test.com
如果能查询到记录,也就正常了.
辅DNS
在配置上基本上和主DNS一样.
需要修改如下两处:
在named.conf/telecom.def/cnc.def文件里,改为:
zone "test.com" {
type slave;
masters{主DNS IP;};
file "master/telecom/test.com";
};
还有named.conf里的相应的IP改一下就可以了.
智能DNS部分也完成了
完成上面两部分,一个基本的CDN系统就出来了.
名词解释
#转载请保留此连接
#VRlinux技术站 http://www.vrlinux.com
#QQ:5846690

