因为服务器只有一个独立 IP ,而且服务器也无法追加 IP ,所以我就要搭建一个 DNS 集群。

注意,DirectAdmin 有一个多服务器的功能,我们就要利用这个功能来进行搭建。
https://www.zhaojin97.cn/wp-content/uploads/2015/11/9d0fd5633a2b7ea5.png

1.首先点击上面的多重服务器功能开关,先开启。

2.然后下载这个东西。 http://regme.in/download/directslave-2.1-beta.tar.gz

3.然后在服务器上解压到 /usr/local 下.

            [root@vultr local]# tar xvzf directslave-2.1-beta.tar.gz

4.然后进去看看,需要编辑。

            [root@vultr local]# cd directslave
             [root@vultr directslave]# ls
                bin  etc  lib  log  README  run  ssl  UPDATING
             [root@vultr directslave]# cd etc
             [root@vultr etc]# ls
                directslave.conf  passwd  rc.d
             [root@vultr etc]# nano directslave.conf

5.我们需要编辑以下几个地方,以便其正常运行。

             host            0.0.0.0
                 ssl             0
              uid             named #named 是 bind 在 centos 之下软件包安装之后的运行用户
              gid             named
                named_workdir   /var/named/secondary
                named_conf      /var/named/directslave.conf
                debug         0

6.然后安装 named ,然后来设置一下权限。

            yum -y install bind
            cd /usr/local
            chown -R named:named directslave

7.还要 perl 的模块。

先来看看需要安装什么。

MODULES

=======

POSIX = system features package (bundled in perl distr)

FindBin = to find relative directories (lib etc)

CGI = CGI implementation

Crypt::PasswdMD5 = for password encryption

Digest::MD5 = for stronger password encryption

Config::Auto = to read and parse etc/directslave.conf

MIME::Base64 = authenticating incoming connections

Net::Server = main server & daemon realisation

Net::CIDR = for checking access hosts

8.输入以下命令来安装。

                rpm -i http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm #自己根据系统版本灵活安装
                yum -y install perl-POSIX*
                yum -y install perl-CGI*
                yum -y install perl-Crypt*
                yum -y install perl-Digest*
                yum -y install perl-Config*
                yum -y install perl-MIME*
                yum -y install perl-Net*

9.安装之后,我们就来设置一下从服务器的用户名和密码,这里的密码在之后需要在主服务器 的 DirectAdmin 上的多服务器处填入。

                /usr/local/directslave/bin/pass admin yourhardtoreadpassword

10.然后我们来检查一下。

                [root@vultr local]# /usr/local/directslave/bin/directslave --check
                Trying to create/open file 'access_log' -> /usr/local/directslave/log/access.log  ...
                OK.
                Trying to create/open file 'action_log' -> /usr/local/directslave/log/action.log  ...
                OK.
                Trying to create/open file 'error_log' -> /usr/local/directslave/log/error.log..  .
                OK.
                Trying to create/open file 'named_conf' -> /var/named/directslave.conf...
                flock() on closed filehandle FILE at /usr/local/directslave/bin/directslave line   320.
                not found, creating... !!! FAIL!
                Check file permissions and set it to named:named
                Set directory writable flag for user named
                Trying to create/open file 'pid' -> /usr/local/directslave/run/directslave.pid..  .
                not found, creating... OK.
                !!! No 'named_workdir' -> /var/named/secondary or it's not writable
                Check config & create it or check permissions!

可以看到有些文件没被创建,我们需要手动创建。

                [root@vultr local]# touch /var/named/directslave.conf
                [root@vultr local]# chown named:named /var/named/directslave.conf
                [root@vultr local]# mkdir /var/named/secondary
                [root@vultr local]# chown -R named:named /var/named/secondary
                [root@vultr etc]# chown -R named:named /var/named

创建完毕之后,就可以再检查一下,应该可以通过了。

11.然后就可以运行了,不过运行之前我们要先把 之前检查时生成的 pid 干掉。

                    [root@vultr etc]# rm -f /usr/local/directslave/run/directslave.pid

12.然后就可以运行了。

                    /usr/local/directslave/bin/directslave --run

13.然后把 named 的配置文件加进去。编辑 /etc/named.conf 添加以下内容。

                    include "/var/named/directslave.conf";

14.然后设置开机启动。

首先是编辑 /etc/rc.local 把以下内容加进去

                    /usr/local/directslave/bin/directslave --run

然后就是启动 bind

                    service named start
                    chkconfig named on

15.然后在 主服务器上添加从服务器。
https://www.zhaojin97.cn/wp-content/uploads/2015/11/4e4f2b9a1d5ee78b.png

16.添加之后,需要只选中这两个勾,其他的不能选。然后 保存。

https://www.zhaojin97.cn/wp-content/uploads/2015/11/4e4f2b9a1d5ee78b.png

17.OK,只要添加或变更记录就会同步到远程服务器了。可以自己做测试。

出现:

Recursive inheritance detected in package ‘Net::Server::HTTP’ at /usr/share/perl5/vendor_perl/Net/Server/MultiType.pm line 72.

Recursive inheritance detected in package ‘Net::Server::HTTP’ at /usr/share/perl5/vendor_perl/Net/Server/MultiType.pm line 72.

用 cpan 重新安装这个组件。