Linux Centos 6.5 DNS主从复制配置(bind-9.8.2)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux Centos 6.5 DNS主从复制配置(bind-9.8.2)相关的知识,希望对你有一定的参考价值。

测试环境:
OS: Centos 6.5
bind : 9.8.2
软件安装方式: yum
主DNS:realserver1 192.168.200.134
从DNS:realserver2 192.168.200.135
测试服务器: test01 192.168.200.136

第一步:环境准备
挂载iso光盘提供本地yum源,如果您的服务器可以提供外部网络,您可以不需要配置本地yum源直接使用网络yum源。
本地yum源配置:
1、ISO将镜上传至服务器根目录如文件名为:centos6.5_release.iso
[[email protected] ~]# mount -o loop -t iso9660 /centos6.5_release.iso /mnt/

2、建立本地yum仓库
[[email protected] ~]# vim /etc/yum.repos.d/test.repo
[base]
name=test
baseurl=file:///mnt/
gpgcheck=0
enabled=1

3、清除yum缓存,列出仓库
[[email protected] ~]# yum clean all
[[email protected] ~]# yum repolist

注:Centos自带网络yum源无需使用本地yum,直接[[email protected] ~]yum -y install xxx #安装需要的软件。yum详细配置(http://www.cnblogs.com/chuncn/archive/2010/10/17/1853915.html

第二步:主DNS服务器配置
1、安装主DNS所需要的软件包
[[email protected] ~]# yum -y install bind bind-chroot bind-util bind-libs
[[email protected] ~]#rpm -ql bind //查看rpm安装的所有文件
/etc/named.conf //DNS主配置文件

2、主DNS的主配置配置
[[email protected] ~]ls -lh /etc/named.conf 主配置文件权限如下(红色字体)
-rw-r----- 1 root named 934 10月 21 23:06 /etc/named.conf

[[email protected] ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.200.134; }; //监听的端口为主DNS的地址
listen-on-v6 port 53 { ::1; }; //IPv6监听端口地址
directory "/var/named"; //DNS根目录
dump-file "/var/named/data/cache_dump.db"; //缓存文件
statistics-file "/var/named/data/named_stats.txt"; //统计文件
memstatistics-file "/var/named/data/named_mem_stats.txt"; //内存使用的统计信息
allow-query { any; }; //允许那些客户端请求
recursion yes; //支持递归
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

};

logging { //日志路径/var/named/data/named.run
channel default_debug {
file "data/named.run";
severity dynamic;
};
};

zone "." IN { // 记录了所有根域地址
type hint;
file "named.ca";
};

zone "test.com" IN { //正向添加一个测试区域
type master; //DNS类型 “主”
file "test.com_zone"; //正向解析区域文件名test.com_zone,在/var/named目录下
allow-transfer {192.168.200.135; }; //允许从DNS进行,同步
};

zone "200.168.192.in-addr.arpa" IN { //反向区域
type master; //DNS类型 “主”
file "192.168.200.zone"; //反向解析区域文件名192.168.200.zone,在/var/named目录下
allow-transfer {192.168.200.135; }; //允许从DNS进行,同步
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
3、创建正反向解析区域文件,并配置好DNS记录
[[email protected] ~]# vim /var/named/test.com_zone //正向解析区域
$TTL 1D
@ IN SOA ns1.test.com. mail.test.com. (
2017071411 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS ns1.test.com.
ns1.test.com. IN A 192.168.200.134
@ IN NS ns2.test.com.
ns2.test.com. IN A 192.168.200.135
www.test.com. IN A 192.168.200.136
tt.test.com. IN A 192.168.200.135
test.test.com. IN A 192.168.200.135

[[email protected] ~]# vim /var/named/192.168.200.zone //反向解析区域
$TTL 1D
@ IN SOA ns1.test.com. mail.test.com. (
2017071412 ; serial //同步编码
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS ns1.test.com.
134 IN PTR ns1.test.com.
@ IN NS ns2.test.com.
135 IN PTR ns2.test.com.
136 IN PTR www.test.com.
135 IN PTR tt.test.com.
135 IN PTR test.test.com.

#同步编码,每次主DNS修改,需要改动编码从DNS才能同步

4、重启DNS服务,验证DNS是否生效
[[email protected] ~]# service named configtest
[[email protected] ~]# named-checkconf //检查配置文件语法
[[email protected] ~]# service named restart //重启DNS服务

5、测试服务器(192.168.200.136)进行测试
[[email protected] ~]# echo nameserver 192.168.200.134 >> /etc/resolv.conf
[[email protected] ~]# ping www.test.com //能够正常解析
注:测试机将自己的DNS设置为主DNS,测试DNS的A记录

第三步:从DNS配置
挂载iso光盘提供本地yum源,如果您的服务器可以提供外部网络,您可以不需要配置本地yum源直接使用网络yum源。
本地yum源配置:
1、ISO将镜上传至服务器根目录如文件名为:centos6.5_release.iso
[[email protected] ~]# mount -o loop -t iso9660 /centos6.5_release.iso /mnt/

2、建立本地yum仓库
[[email protected] ~]# vim /etc/yum.repos.d/test.repo
[base]
name=test
baseurl=file:///mnt/
gpgcheck=0
enabled=1

3、清除yum缓存,列出仓库
[[email protected] ~]# yum clean all
[[email protected] ~]# yum repolist

注:Centos自带网络yum源无需使用本地yum,直接[[email protected] ~]yum -y install xxx #安装需要的软件。yum详细配置(http://www.cnblogs.com/chuncn/archive/2010/10/17/1853915.html

1、安装从DNS所需要的软件包
[[email protected] ~]# yum -y install bind bind-chroot bind-util bind-libs
[[email protected] ~]#rpm -ql bind //查看rpm安装的所有文件
/etc/named.conf //DNS主配置文件

2、从DNS的主配置配置
[[email protected] ~]ls -lh /etc/named.conf 主配置文件权限如下(红色字体)
-rw-r----- 1 root named 934 10月 21 23:06 /etc/named.conf

[[email protected] ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.200.135; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
recursion yes;

    dnssec-enable yes;
    dnssec-validation yes;
    dnssec-lookaside auto;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

};

logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};

logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};

zone "." IN {
type hint;
file "named.ca";
};

zone "test.com" IN {
type slave;
file "test.com_zone";
masters {192.168.200.134; };

};

zone "200.168.192.in-addr.arpa" IN {
type slave;
file "192.168.200.zone";
masters {192.168.200.134; };
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
3、编辑存放解析文件的权限,同步时候有权限
[[email protected] ~]# chmod 770 /var/named/
[[email protected] ~]# ll /var/named/ -d
drwxrwx--- 6 root named 4096 Oct 22 10:49 /var/named/

4、检查从DNS配置,并启动服务
[[email protected] ~]# service named configtest
[[email protected] ~]# named-checkconf //检查配置文件语法
[[email protected] ~]# service named restart //重启DNS服务
注:重启完成后,从DNS会同步到主DNS的配置文件
[[email protected] ~]# cat /var/named/test.com_zone //可以看到同步的A记录

5、测试服务器进行测试,从DNS也可以进行解析
[[email protected] ~]# dig @192.168.200.135 www.test.com
注:从DNS也能提供域名解析

第四步:测试主从是否能够同步
1、在主DNS正向解析文件中添加A记录
[[email protected] ~]# vim /var/named/test.com_zone
$TTL 1D
@ IN SOA ns1.test.com. mail.test.com. (
2017071412 ; serial //一定要修改同步编码
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS ns1.test.com.
ns1.test.com. IN A 192.168.200.134
@ IN NS ns2.test.com.
ns2.test.com. IN A 192.168.200.135
www.test.com. IN A 192.168.200.136
tt.test.com. IN A 192.168.200.135
test.test.com. IN A 192.168.200.135
nihao.test.com. IN A 192.168.200.136 //添加的A记录

#同步码一定要修改,从才能同步到

2、重新载入主DNS配置文件
[[email protected] ~]# /etc/init.d/named reload

3、从DNS配置文件已经同步
[[email protected] ~]# cat /var/named/test.com_zone

未完待续.... 下一节LVS+DNS+Keepalived

以上是关于Linux Centos 6.5 DNS主从复制配置(bind-9.8.2)的主要内容,如果未能解决你的问题,请参考以下文章

Linux Centos 6.5 DNS主从复制配置(bind-9.8.2)

Linux-中级篇搭建MySQL的主从复制

MySQL主从复制

Linux Centos7DNS解析(正向解析,反向解析,主从复制)你想要的这都有

CentOS 7部署DNS主从复制及Apache域名虚拟主机

Linux-Centos6.5-Oracle数据库安装-DNS安装