(一)DNS主从同步的原理:
1、master DNS服务器每次修改完成并重启服务后,将传送notify给所有的slave DNS服务器;
2、slave DNS服务器将查询master服务器的SOA记录;
3、master DNS服务器收到请求后将SOA记录发送给Slave DNS服务器,Slave DNS服务器收到后同时对比查询结果中的serial值;
4、如果serial值不大于本机的话将结束数据同步过程;但是如果serial值大于本机的话,slave DNS将发送zone transfer请求要求(AXFR/IXFR)。Master响应zone transfer请求并传送结果,直到整个slave更新完成。
(二)DNS服务器类型
1,Primary DNS Server (Master)域主服务器:是这个域的权威服务器,所有这个域的信息都是由域的主服务器控制,改域的所有配置,更改,都在master服务器运行
2,Seconday DNS Server (Slave)域从服务器:通常是用于备份(冗余)和 负载均衡使用。所有slave的信息都是由域的主服务器控制(即域的从服务器从域的主服务器抓取zone配置文件),从服务器不进行不进行信息的修改,所有的修改与主服务器同步。查看域的zone文件是否正常抓取要到/var/named/chroot/var/named/slaves/目录中查看。
3,Cacheing only Server(DNS缓存服务器):不存在zone文件,仅仅依靠缓存为客户端提供服务。
(三)配置主从DNS
序号 | IP | 功能 |
---|---|---|
1 | 192.168.99.98 | Master |
2 | 192.168.99.99 | Slave |
1,在Master上操作
(1),查看Master的named.conf配置
[[email protected] chroot]# cat /var/named/chroot/etc/named.conf
options
{
listen-on port 53 { any; };
allow-query { any; };
recursion yes;
listen-on-v6 port 53 { ::1; };
};
zone "lqb.com" IN {
type master;
file "lqb.com.zon";
allow-transfer { 192.168.99.99; }; ####slave服务器的IP地址
};
(2),在Master新建主服务器解析库文件 zone文件
[[email protected] chroot]# vim /var/named/chroot/var/named/
data/ dynamic/ lqb.com.zon slaves/
[[email protected] chroot]# cat /var/named/chroot/var/named/lqb.com.zon
$TTL 1D
$ORIGIN lqb.com.
@ IN SOA lqb.com. admin.lqb.com. (
20180511; serial ########这个很重要,每次修改记录的时候都要修改这个数T+1(每次修改完主DNS配置后,都需要改一下serial序列号,且必须比从服务器号大才会同步。)
1D ; refresh
1H ; retry
1W ; expire
3H ; minimum
)
IN NS ns1.lqb.com.
mail IN A 172.20.66.111
www2 IN A 172.20.66.112
ns1 IN A 192.168.99.99
www IN A 172.20.66.110
ftp IN A 10.128.105.250
(3)每次添加修改dns记录时,serial值比原先的值大才能同步(建议采用T+1)。
[[email protected] chroot]# vim var/named/lqb.com.zon
$TTL 1D
$ORIGIN lqb.com.
@ IN SOA lqb.com. admin.lqb.com. (
20180513; serial ###改值比修改前的要大,才能同步
1D ; refresh
1H ; retry
1W ; expire
3H ; minimum
)
IN NS ns1.lqb.com.
@ IN NS ns1.lqb.com.
@ IN NS ns2.lqb.com.
mail IN A 172.20.66.111
www2 IN A 172.20.66.112
ns1 IN A 192.168.99.98
ns2 IN A 192.168.99.99
www IN A 172.20.66.110
ftp IN A 10.128.105.250
file IN A 172.20.66.112
lqb IN A 172.20.66.120
(4)重新加载配置文件
[[email protected] chroot]# rndc reload
[[email protected] chroot]# tail -f /var/log/messages
May 11 17:30:57 server98 named[33430]: reloading configuration succeeded
May 11 17:30:57 server98 named[33430]: reloading zones succeeded
May 11 17:30:57 server98 named[33430]: zone lqb.com/IN: loaded serial 20180513
May 11 17:30:57 server98 named[33430]: zone lqb.com/IN: sending notifies (serial 20180513)
May 11 17:30:57 server98 named[33430]: all zones loaded
May 11 17:30:57 server98 named[33430]: running
May 11 17:30:57 server98 named[33430]: client 192.168.99.99#32886 (lqb.com): transfer of ‘lqb.com/IN‘: AXFR-style IXFR started
May 11 17:30:57 server98 named[33430]: client 192.168.99.99#32886 (lqb.com): transfer of ‘lqb.com/IN‘: AXFR-style IXFR ended
May 11 17:30:57 server98 named[33430]: client 192.168.99.99#11716: received notify for zone ‘lqb.com‘
2,在slave上操作
(1)编辑slave服务器上的named.conf文件,
[[email protected] ~]# vim /var/named/chroot/etc/named.conf
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
allow-query { any; };
directory "/var/named";
recursion yes;
};
zone "lqb.com" IN {
type slave; ###本机是从服务器
file "slaves/lqb.com.zon"; ###将同步后的文件放置在哪里,这里是相对路径绝对路径是/var/named/chroot/var/named/slaves/
masters { 192.168.99.98; }; ###指定主服务器的ip地址
};
(2),给slaves赋读写权限并修改该目录的所有者为named用户
[[email protected] ~]# chown -R named:named /var/named/chroot/var/named/slaves/
[[email protected] ~]# chmod -R 777 /var/named/chroot/var/named/slaves/
[[email protected] ~]# ll /var/named/chroot/var/named/
总用量 24
drwxrwxrwx 2 root root 6 5月 11 11:40 data
-rw-r--r-- 1 root root 56 5月 11 11:40 my.external.zone.db
-rw-r--r-- 1 root root 56 5月 11 11:40 my.internal.zone.db
-rw-r--r-- 1 root root 2281 5月 11 11:40 named.ca
-rw-r--r-- 1 root root 152 5月 11 11:40 named.empty
-rw-r--r-- 1 root root 152 5月 11 11:40 named.localhost
-rw-r--r-- 1 root root 168 5月 11 11:40 named.loopback
drwxrwxrwx 2 named named 25 5月 11 15:41 slaves
(3)检查语法,并在master和slave重启下服务
[[email protected] ~]# named-checkconf /var/named/chroot/etc/named.conf
[[email protected] ~]# systemctl restart named-chroot
(4)查看从服务器是否有文件同步进来,注意该文件是用vim 打不开的。
[[email protected] ~]# ll /var/named/chroot/var/named/slaves/
总用量 4
-rw-r--r-- 1 named named 340 5月 11 16:05 lqb.com.zon
(5)用从服务器解析 (‘@’后面指定dns 服务器的地址,就可以不用改本机的dns了)
[[email protected] var]# dig file.lqb.com @192.168.99.99
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> file.lqb.com @192.168.99.99
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55636
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;file.lqb.com. IN A
;; ANSWER SECTION:
file.lqb.com. 86400 IN A 10.128.105.251
;; AUTHORITY SECTION:
lqb.com. 86400 IN NS ns1.lqb.com.
;; ADDITIONAL SECTION:
ns1.lqb.com. 86400 IN A 192.168.99.99
;; Query time: 1 msec
;; SERVER: 192.168.99.99#53(192.168.99.99)
;; WHEN: Fri May 11 16:25:53 CST 2018
;; MSG SIZE rcvd: 91
备注:如果没有同步文件,则一般的检查步骤如下:
1,确认ntp时间是否同步
2,samples文件夹的属主是否是named用户,是否具有读写权限。
3,是否启用了notify功能,该功能也可以在全局项options内配置,只不过全局配置是针对所有域的。
4,每次修改dns解析的记录,需要修改series值,采用T+1算法。
日志信息如下:
[[email protected] named]# tail -f /var/log/messages
May 11 17:30:57 zabbix named[33420]: client 192.168.99.98#18648: received notify for zone ‘lqb.com‘
May 11 17:30:57 zabbix named[33420]: zone lqb.com/IN: Transfer started.
May 11 17:30:57 zabbix named[33420]: transfer of ‘lqb.com/IN‘ from 192.168.99.98#53: connected using 192.168.99.99#32886
May 11 17:30:57 zabbix named[33420]: zone lqb.com/IN: transferred serial 20180513
May 11 17:30:57 zabbix named[33420]: transfer of ‘lqb.com/IN‘ from 192.168.99.98#53: Transfer completed: 1 messages, 13 records, 316 bytes, 0.001 secs (316000 bytes/sec)
May 11 17:30:57 zabbix named[33420]: zone lqb.com/IN: sending notifies (serial 20180513)
原文地址:http://blog.51cto.com/liqingbiao/2115336