安装Bind进行Hadoop集群主机名解析

系统:CentOS 6.4 x86_64
服务器地址:10.1.6.21(master)、10.1.6.211(slave)

当主DNS挂掉了后,从DNS可以继续提供解析服务。
一、安装
yum -y install bind bind -chroot bind-utils

bind-chroot提供安全环境
bind-utils为工具包

二、配置
参考配置文件:/usr/share/doc/bind-9.8.2/sample/etc/named.conf 
Master配置:
1、主配置文件
# cat /etc/named.conf 
options {
        listen -on port 53 { 127. 0. 0. 1; 10. 1. 6. 21; }; # ​监听地址
        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     { localhost; any;}; #允许所有人都可以查询
        allow -query -cache { any;}; #允许所有人都可以查询缓存
        recursion yes; #允许递归查询

          allow-transfer { 10.1.6.211; }; #指定slave从服务器的IP地址

        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;
        };
};

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

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

2、注册域
# cat /etc/named.rfc1912.zones 
zone "localhost.localdomain" IN {
        type master;
        file "named.localhost";
        allow -update { none; };
};

zone "localhost" IN {
        type master;
        file "named.localhost";
        allow -update { none; };
};

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
        type master;
        file "named.loopback";
        allow -update { none; };
};

zone "1.0.0.127.in-addr.arpa" IN {
        type master;
        file "named.loopback";
        allow -update { none; };
};

zone "0.in-addr.arpa" IN {
        type master;
        file "named.empty";
        allow -update { none; };
};

zone "yaukb.com" IN {  #注册一个yaukb.com域
        type master;
        file "yaukb.com.zone"; #域的配置文件
        allow -update { none; };
};

3、定义域信息:主机记录等
配置新注册域(yaukb.com)文件:
# cat /var/named/chroot/var/named/yaukb.com.zone 
$TTL 1D #缓存的生存时间
@       IN       SOA      dns1.yaukb.com.  root.dns1.yaukb.com. (
#当前域  internet 开始授权   DNS服务器的主机名   管理员邮箱
                                        0       ; serial 更新序列号,是判断记录是否是新的,如更改主机记录后,最好将序列号改大点,同步时间也有关系,这样才能同步到从服务器。
                                        1M      ; refresh 更新间隔,默认1天(1D),这里设置为1分钟
                                        5 M      ; retry 失败重试
                                        1W      ; expire 区域文件的过期时间
                                        3H )    ; minimum 缓存的生存周期
@       IN NS   dns1.yaukb.com.
dns1    IN A   10. 1. 6. 21
hadoop01 IN A   10. 1. 6. 210

@:当前域,这里是指yaukb.com.
NS:name server DNS服务器
A:地址记录

修改文件权限:
cd /var /named /chroot /var /named
cp /var /named /named. * .    #复制默认的域文件到安全目录
chown named.named -R /var /named /  #修改目录权限

4、启动服务:
/etc /init.d /named start
chkconfig --level 2345 named on

SLAVE配置:
1、主配置文件
# cat /etc/named.conf 
options {
        listen -on port 53 { 127. 0. 0. 1; 10. 1. 6. 211; };
        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     { localhost;any; };
        allow -query -cache { 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;
        };
};

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

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

2、注册域
# cat /etc/named.rfc1912.zones 
zone "localhost.localdomain" IN {
        type master;
        file "named.localhost";
        allow -update { none; };
};

zone "localhost" IN {
        type master;
        file "named.localhost";
        allow -update { none; };
};

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
        type master;
        file "named.loopback";
        allow -update { none; };
};

zone "1.0.0.127.in-addr.arpa" IN {
        type master;
        file "named.loopback";
        allow -update { none; };
};

zone "0.in-addr.arpa" IN {
        type master;
        file "named.empty";
        allow -update { none; };
};

zone "yaukb.com" IN {  #注册yaukb.com域,类型为slave
        type slave;
        file "slaves/yaukb.com.slave"; #配置存放位置
        masters { 10. 1. 6. 21; };  #指定域从哪里同步
};

3、修改目录权限
chown named.named -R /var /named /

4、启动服务:
/etc /init.d /named start
chkconfig --level 2345 named on

客户端配置:
$ cat /etc/resolv.conf 
nameserver 10. 1. 6. 21   #主DNS服务器
nameserver 10. 1. 6. 211 #从DNS服务器

三、测试
1、使用dig命令进行测试
# dig hadoop01.yaukb.com
; << >> DiG 9. 8. 2rc1 -RedHat - 9. 8. 2 - 0. 17.rc1.el6_4. 6 << >> hadoop01.yaukb.com
;; global options : +cmd
;; Got answer :
;; - >>HEADER << - opcode : QUERY, status : NOERROR, id : 50680
;; flags : qr aa rd ra; QUERY : 1, ANSWER : 1, AUTHORITY : 1, ADDITIONAL : 1

;; QUESTION SECTION :
;hadoop01.yaukb.com.            IN      A

;; ANSWER SECTION :
hadoop01.yaukb.com.     86400   IN      A       10. 1. 6. 210

;; AUTHORITY SECTION :
yaukb.com.               86400   IN      NS      dns1.yaukb.com.

;; ADDITIONAL SECTION :
dns1.yaukb.com.         86400   IN      A       10. 1. 6. 21

;; Query time : 0 msec
;; SERVER : 127. 0. 0. 1 #53(127.0.0.1)
;; WHEN : Wed Feb 19 15 : 01 : 54 2014
;; MSG SIZE  rcvd : 87

2、使用nslookup进行测试
# nslookup
> server
Default server : 8. 8. 8. 8
Address : 8. 8. 8. 8 #53
> server 127. 0. 0. 1  #指定dns服务器地址
Default server : 127. 0. 0. 1
Address : 127. 0. 0. 1 #53
> hadoop01.yaukb.com
Server :         127. 0. 0. 1
Address :         127. 0. 0. 1 #53

Name :   hadoop01.yaukb.com
Address : 10. 1. 6. 210
> exit

四、错误处理
1、master权限不足,默认日志文件为 /var/log/messages
# tail -f /var/log/messages
Feb 19 14 : 59 : 55 yau621 named[ 18813] : could not configure root hints from 'named.ca' : permission denied
Feb 19 14 : 59 : 55 yau621 named[ 18813] : loading configuration : permission denied
Feb 19 14 : 59 : 55 yau621 named[ 18813] : exiting (due to fatal error)

解决:
chown named.named /var/named

查看文件权限如:
[root@yau621 named] # ll
total 20
-rw -r -- -- - 1 named named 1892 Feb 19 14 : 58 named.ca
-rw -r -- -- - 1 named named   152 Feb 19 14 : 58 named.empty
-rw -r -- -- - 1 named named   152 Feb 19 14 : 58 named.localhost
-rw -r -- -- - 1 named named   168 Feb 19 14 : 58 named.loopback
-rw -r -- -- - 1 named named   216 Feb 19 14 : 59 yaukb.com.zone

2、slave权限不足,不能 保存 从master端同步的配置
Feb 19 17 : 21 : 14 hadoop03 named[ 11401] : stopping command channel on : : 1 #953
Feb 19 17 : 21 : 14 hadoop03 named[ 11401] : dumping master file : /var /named /chroot /var /named /slaves /tmp -AfMfEimkrr : open : file not found

解决:
chown named.named -R /var /named /





来自为知笔记(Wiz)


你可能感兴趣的:(安装Bind进行Hadoop集群主机名解析)