bind+mysql+dlz

DLZ(Dynamically Loadable Zones)与传统的BIND9不同,BIND的不足之处:
* BIND从文本文件中获取数据,这样容易因为编辑错误出现问题。
* BIND需要将数据加载到内存中,如果域或者记录较多,会消耗大量的内存。
* BIND启动时解析Zone文件,对于一个记录较多的DNS来说,会耽误更多的时间。
* 如果近修改一条记录,那么要重新加载或者重启BIND 才能生效,那么需要时间,可能会影响客户端查询。
而Bind-dlz 即将帮你解决这些问题, 对Zone文件操作也更方便了,直接对数据库操作,可以很方便扩充及开发管理程序。

实验所需清单:

CentOS 6.4 64位系统

bind-9.10.2.tar.gz

mysql-5.6.23.tar.gz


1.安装mysql

    安装依赖包:

    #yum -y install make cmake ncurses-devel bison-devel libaio-devel gcc-c++

    创建mysql用户及组

    #groupadd mysql

    #useradd mysql -g mysql -M -s /sbin/nologin

    安装mysql

    #tar xf mysql-5.6.23.tar.gz

    #cd mysql-5.6.23

    #cmake .

    #make && make install

    #cd /usr/local/mysql/

    #scripts/mysql_install_db --user=mysql

    #chown -R :mysql .

    #chown -R mysql data

    #bin/mysqld_safe --user=mysql

    #cp support-files/mysql.server /etc/init.d/mysql

    #chkconfig --add mysql

    #ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

    #service mysql start

    #bin/mysqladmin -u root password 'bmw12345'

    #echo "/usr/local/mysql/lib" >> /etc/ld.so.conf

    #ldconfig


2.配置bind

    #yum -y install openssl-devel

    #tar xf bind-9.10.2.tar.gz

    #cd bind-9.10.2

    #./configure --with-dlz-mysql --enable-largefile --enable-threads=no --prefix=/home/bind --disable-openssl-version-check

    #make && make install

    #useradd bind -M -s /sbin/nologin

    #vim /home/bind/etc/named.conf

dlz "My zone" {

   database "mysql

   {host=127.0.0.1 dbname=dns ssl=false port=3306 user=root pass=bmw12345}

   {select zone from dns_records where zone = '$zone$'}

   {select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')

        when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum)

        else data end from dns_records where zone = '$zone$' and host = '$record$'}";

};

    配置不再详说,网上一大把

    #/home/bind/sbin/named -u bind -c /home/bind/etc/named.conf


3.数据库添加

    #mysql -uroot -pbmw12345

    进入数据库操作

    #create database dns;

    #use dns

    #CREATE TABLE dns_records(id int(11) unsigned NOT NULL auto_increment,zone varchar(255) NOT NULL,host varchar(255) NOT NULL default '@',type varchar(255) NOT NULL,data text,ttl int(11) default 600,mx_priority int(11) default NULL,refresh int(11) default NULL,retry int(11) default NULL,expire int(11) default NULL,minimum int(11) default NULL,serial bigint(20) default NULL,resp_person varchar(255) default NULL,primary_ns varchar(255),PRIMARY KEY(id));

    #CREATE INDEX host_index ON dns_records(host);

    #CREATE INDEX type_index ON dns_records(type);

    #CREATE INDEX zone_index ON dns_records(zone);

    #insert into dns_records (zone,host,type,data,refresh,retry,expire,minimum,serial,resp_person,primary_ns) values('test.com','@','SOA','ns.test.com',7200,3600,86400,3600,1000,'root.test.com.','ns.test.com.');

    #insert into dns_records (zone,host,type,data) values('test.com','@','NS','ns.test.com.');

    #insert into dns_records (zone,host,type,data) values('test.com','ns','A','1.1.1.1');

    #insert into dns_records (zone,host,type,data) values('test.com','www','A','127.0.0.1');

4.验证

    dig安装:yum -y install bind-utils

    #dig @127.0.0.1 www.test.com


你可能感兴趣的:(bind)