bind9.4.2以上版本用dlz实现多线解析

转自:http://blog.shaosong.com

安装mysql等略

http://bind-dlz.sourceforge.net/ 下载最新的bind版本,我这里用bind-9.6.0-P1.tar.gz

wget http://ftp.isc.org/isc/bind/9.6.0-P1/bind-9.6.0-P1.tar.gz
#tar zxvf bind-9.6.0-P1.tar.gz
#cd bind-9.6.0-P1
./configure –with-dlz-mysql –enable-largefile –enable-threads=no –prefix=/usr/local/bind –with-openssl=/usr/local/openssl

make;make install

注这里需要openssl0.98以上。

升级(安装)请参照http://blog.shaosong.com/show-114-1.html

创建数据库结构

SQL代码
  1. create database cdn_view;   
  2. CREATE TABLE `dns_records` (   
  3. `id` int(10) unsigned NOT NULL auto_increment,   
  4. `zone` varchar(255) NOT NULL,   
  5. `host` varchar(255) NOT NULL default ‘@’,   
  6. `type` enum(‘MX’,‘CNAME’,‘NS’,‘SOA’,‘A’,‘PTR’NOT NULL,   
  7. `data` varchar(255) default NULL,   
  8. `ttl` int(11) NOT NULL default ‘800′,   
  9. `view` enum(‘CNC’,‘TELECOM’,‘EDU’,‘ANY’NOT NULL,   
  10. `mx_priority` int(11) default NULL,   
  11. `refresh` int(11) NOT NULL default ‘3600′,   
  12. `retry` int(11) NOT NULL default ‘3600′,   
  13. `expire` int(11) NOT NULL default ‘86400′,   
  14. `minimum` int(11) NOT NULL default ‘3600′,   
  15. `serial` bigint(20) NOT NULL default ‘2008082700′,   
  16. `resp_person` varchar(64) NOT NULL default ‘root.domain.com.’,   
  17. `primary_ns` varchar(64) NOT NULL default ‘ns1.domain.com.’,   
  18. `data_count` int(11) NOT NULL default ‘0′,   
  19. PRIMARY KEY (`id`),   
  20. KEY `type` (`type`),   
  21. KEY `host` (`host`),   
  22. KEY `zone` (`zone`)   
  23. ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=gbk;  

 

 

SQL代码
  1. CREATE TABLE IF NOT EXISTS `xfr_table` (   
  2.   `zone` text,   
  3.   `client` text,   
  4.   `viewvarchar(10) default ‘ANY’,   
  5.   KEY `zone_client_index` (`zone`(30),`client`(30))   
  6. ) ENGINE=MyISAM DEFAULT CHARSET=gbk;   
  7.   
  8.   
  9. CREATE TABLE IF NOT EXISTS `data_count` (   
  10.   `zone` text NOT NULL,   
  11.   `countbigint(20) default ‘0′,   
  12.   `viewvarchar(10) default ‘ANY’,   
  13.   PRIMARY KEY  (`zone`(30))   
  14. ) ENGINE=MyISAM DEFAULT CHARSET=gbk;   
  15.   

 

SQL代码
  1. INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES  
  2. (’shaosong.com’‘@’‘SOA’‘ns1.shaosong.com.’, 10, ‘CNC’NULL, 3600, 3600, 86400, 10, 2008082700, ‘root.shaosong.com.’‘ns1.shaosong.com.’, 0);   
  3. INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`,   
  4. `primary_ns`, `data_count`) VALUES  
  5. (’shaosong.com’‘@’‘SOA’‘211.100.72.137′, 3600, ‘CNC’NULL, 3600, 3600, 86400, 3600, 2008082700, ‘root.shaosong.com.’‘ns1.shaosong.com.’, 0);   
  6. INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES  
  7. (’shaosong.com’‘ns1′‘A’‘211.100.72.137′, 3600, ‘CNC’NULL, 3600, 3600, 86400, 3600, 2008082700, ‘root.shaosong.com.’‘ns1.shaosong.com.’, 0);   
  8. INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES  
  9. (’shaosong.com’‘ns2′‘A’‘219.232.244.11′, 3600, ‘CNC’NULL, 3600, 3600, 86400, 3600, 2008082700, ‘root.shaosong.com.’‘ns1.shaosong.com.’, 0);   
  10. INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES  
  11. (’shaosong.com’‘www’‘A’‘210.51.36.116′, 3600, ‘CNC’NULL, 3600, 3600, 86400, 3600, 2008082700, ‘root.shaosong.com.’‘ns1.shaosong.com.’, 0);   
  12. INSERT INTO dns_records (zone,host,type,DATA,view)   
  13. VALUES (’shaosong.com’‘man’‘CNAME’‘www’,‘CNC’);  

 

编辑编辑/usr/local/bind/etc/named.conf

cd /usr/local/bind/etc

../sbin/rndc-confgen -a

../sbin/rndc-confgen > rndc.conf

将# Use with the following in named.conf, adjusting the allow list as needed: 和 # End of named.conf 之间的行前#号去掉

添加到named.conf

我这里只用双线

options {
    directory “/usr/local/bind/etc/”;
    pid-file “/usr/local/bind/var/run/named.pid”;
    allow-query { any; };
    recursion no;
    version “gaint-d1″;
};
include “/usr/local/bind/etc/telcom.cl”;
include “/usr/local/bind/etc/other.cl”;
view “telecom-user” {
    match-clients { telecom; };
recursion no;
dlz “Mysql zone” {
database “mysql
{host=127.0.0.1 dbname=cdn_view ssl=false port=3306 user=root pass=123 }
{select zone from dns_records where zone = ‘%zone%’ and view=’TELECOM’ limit 1}
{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 as mydata from dns_records where zone = ‘%zone%’ and host = ‘%record%’ and view=’TELECOM’}
{}
{select ttl, type, host, mx_priority, case when lower(type)=’txt’ then concat(’\”‘, data, ‘\”‘) else data end as mydata, resp_person, serial, refresh, retry, expire, minimum from dns_records where zone = ‘%zone%’ and view=’TELECOM’}
{select zone from xfr_table where zone = ‘%zone%’ and client = ‘%client%’ and view=’TELECOM’ limit 1}
{update data_count set count = count + 1 where zone =’%zone%’ and view=’TELECOM’}”;
};
};
view “any-user” {
    match-clients { any; };
recursion no;
dlz “Mysql zone” {
database “mysql
{host=127.0.0.1 dbname=cdn_view ssl=false port=3306 user=root pass=123 }
{select zone from dns_records where zone = ‘%zone%’ and view=’ANY’ limit 1}
{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 as mydata from dns_records where zone = ‘%zone%’ and host = ‘%record%’ and view=’ANY’}
{}
{select ttl, type, host, mx_priority, case when lower(type)=’txt’ then concat(’\”‘, data, ‘\”‘) else data end as mydata, resp_person, serial, refresh, retry, expire, minimum from dns_records where zone = ‘%zone%’ and view=’ANY’}
{select zone from xfr_table where zone = ‘%zone%’ and client = ‘%client%’ and view=’ANY’ limit 1}
{update data_count set count = count + 1 where zone =’%zone%’ and view=’ANY’}”;
};
};

 

etc/telecom.cl如下:
acl “telecom” {
****电信路由表
};
 
touch etc/other.cl

启动bind

# /usr/local/bind/sbin/named -uroot -g -d 9 //调试状态,如果没有报错说明环境配置正确。
做成启动服务. Debug的时候多用此模式启动bind.
# /usr/local/bind/sbin/rndc reload 重载named.conf相关配置文件.
# /usr/local/bind/sbin/named -ubind -c /usr/local/bind/etc/named.conf 启动bind服务.

测试是否成功。

你可能感兴趣的:(数据结构,sql,mysql,电信,SOA)