搭建主从服务器

搭建主从服务器

  • 目的及准备
  • 主服务器
    • 1.编辑主配置文件
    • 2.主配置文件区域配置部分
    • 3.创建zone数据库配置文件并编辑
    • 4.语法检测
    • 5.启动服务
    • 6.指定本机为域名服务器
  • 从服务器
    • 1.安装bind
    • 2.修改bind主配置文件
    • 3.主配置文件区域配置部分
    • 4.语法检测
    • 5.启动服务
    • 6.指定域名服务器
    • 7.检验

目的及准备

  1. 安装bind软件,搭建主从服务器
  2. 主服务器ip:192.168.2.55
  3. 从服务器ip:192.168.2.1

主服务器

1.编辑主配置文件

vim /etc/named.conf
options {
        listen-on port 53 { any;};
        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;
        };
};

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

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

2.主配置文件区域配置部分

vim /etc/named.rfc1912.zones
zone "kgc.com" IN {
        type master;
        allow-transfer {192.168.2.1;};
        file "kgc.com.zone";
};
zone "2.168.192. in-addr.arpa" IN {
        type master;
        allow-transfer {192.168.2.1;};
        file "192.168.2.arpa";
};      

3.创建zone数据库配置文件并编辑

cd /var/named/
cp -p named.localhost kgc.com.zone
cp -p named.localhost 192.168.2.arpa

编辑正向解析文件:

vim kgc.com.zone
$TTL 1D
@       IN SOA  kgc.com. root.kgc.com. (
                                        2018102001      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1
www     A       192.168.2.66

编辑反向解析文件:

vim 192.168.2.arpa
$TTL 1D
@       IN SOA  kgc.com. root.kgc.com. (
                                        2018102001      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1
66      PTR     www.kgc.com
~                            

4.语法检测

主配置文件检查

named-checkconf /etc/named.conf

区域数据文件检查

cd /var/named/
named-checkzone kgc.com kgc.con.zone
nemed-checkzone kgc.com 192.168.2.arpa

5.启动服务

service named restart

6.指定本机为域名服务器

vim /etc/resolv.conf

添加域名服务器

# Generated by NetworkManager
192.168.2.55

从服务器

1.安装bind

cd /media/RHEL_6.5\ x86_64\ Disc\ 1/Packages
rpm -ivh bind-9.8.2-0.17.rcl.el6_4.6.x86_64

2.修改bind主配置文件

vim /etc/named.conf
options {
        listen-on port 53 { any;};
        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;
        };
};

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

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

3.主配置文件区域配置部分

vim /etc/named.rfc1912.zones
zone "kgc.com" IN {
        type slave;
       masters  {192.168.2.55;};
        file "slaves/kgc.com.zone";
};
zone "2.168.192. in-addr.arpa" IN {
        type slave;
        masters  {192.168.2.55;};
        file "slaves/192.168.2.arpa";
};      

4.语法检测

主配置文件检查

named-checkconf /etc/named.conf

区域数据文件检查

cd /var/named/
named-checkzone kgc.com kgc.con.zone
nemed-checkzone kgc.com 192.168.2.arpa

5.启动服务

service named restart

6.指定域名服务器

vim /etc/resolv.conf

添加域名服务器

# Generated by NetworkManager
192.168.2.55

7.检验

nslookup 192.168.2.66
nslookup www.kgc.com

成功

你可能感兴趣的:(linux基础)