在只有一台dns服务器时,所有的dns解析过程都由这台dns服务器负责,压力极大。而且极不安全,因为这台dns服务器一垮掉,所有的解析服务都停止,整个网站也就垮了。
无论是出于负载均衡考虑,还是数据安全可靠的考虑,至少都应该配置2台或2台以上的dns服务器,其中必须有一台是master服务器,其余的是slave服务器。
master 和 slave 服务器都可以配置成向外提供解析服务。但 slave 上的区域数据从何而来?不是自行书写区域数据文件而来,而是从 master 服务器上复制而来。从 master 复制区域数据到 slave 的过程,DNS 术语称之为"区域传送"。
下面我们看看主从配置的过程:
1)编写主服务器named.conf文件
acl wx {
10.57.66.0/24;
};
acl zw {
10.10.2.0/24;
};
options {
listen-on port 53 { any; };
directory "/data/named";
dump-file "/data/named/data/cache_dump.db";
statistics-file "/data/named/data/named_stats.txt";
memstatistics-file "/data/named/data/named_mem_stats.txt";
dnssec-enable no;
allow-query { wx;zw; };
allow-transfer { 10.10.66.122; }; #从库无需配置此参数
also-notify { 10.10.66.122; }; #从库无需配置此参数
recursion yes;
notify yes; #从库无需配置此参数
tcp-clients 1000;
};
controls{
inet 0.0.0.0 port 953
allow { localhost; } ;
};
logging {
category "default" { "normal"; };
category "general" { "normal"; };
category "database" { "normal"; };
category "security" { "normal"; };
category "config" { "normal"; };
category "resolver" { "normal"; };
category "xfer-in" { "normal"; };
category "xfer-out" { "normal"; };
category "notify" { "normal"; };
category "client" { "normal"; };
category "unmatched" { "normal"; };
category "network" { "normal"; };
category "update" { "normal"; };
category "queries" { "normal"; };
category "dispatch" { "normal"; };
category "dnssec" { "normal"; };
category "lame-servers" { "normal"; };
channel "normal" {
file "/data/log/named/normal.log" versions 3 size 200m;
severity debug 0;
print-time yes;
print-category yes;
print-severity yes;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
2)在/etc/named.rfc1912.zones添加zone区域 (主)
zone "cmredis.com" {
type master;
file "cmredis.com.zone";
allow-update { none; };
};
3)在/etc/named.rfc1912.zones添加zone区域 (从)
zone "cmredis.com" {
type slave;
masters {10.10.66.121;};
file "slaves/cmredis.com.zone";
allow-update { none; };
};
4)撰写cmredis.com.zone文件(主)
vim /data/named/cmredis.com.zone
$TTL 60
@ IN SOA cmredis.com. root (
53 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.cmredis.com.
@ IN NS dns2.cmredis.com.
ns IN A 127.0.0.1
dns 1200 IN A 10.10.66.121
dns2 1200 IN A 10.10.66.122
5)检查配置文件、启动服务(主从)
named-checkzone cmredis.com.zone /data/named/cmredis.com.zone
注意:
在主库上添加删除A记录,从库没有同步过去,把从库的zone文件删掉,重启才重新拉取一份,原来是在master修改了记录时一定要修改serial! 只有master Serial大于slave时 slave才会同步
参考文档: