安装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
创建数据库结构
- create database cdn_view;
- CREATE TABLE `dns_records` (
- `id` int(10) unsigned NOT NULL auto_increment,
- `zone` varchar(255) NOT NULL,
- `host` varchar(255) NOT NULL default ‘@’,
- `type` enum(‘MX’,‘CNAME’,‘NS’,‘SOA’,‘A’,‘PTR’) NOT NULL,
- `data` varchar(255) default NULL,
- `ttl` int(11) NOT NULL default ‘800′,
- `view` enum(‘CNC’,‘TELECOM’,‘EDU’,‘ANY’) NOT NULL,
- `mx_priority` int(11) default NULL,
- `refresh` int(11) NOT NULL default ‘3600′,
- `retry` int(11) NOT NULL default ‘3600′,
- `expire` int(11) NOT NULL default ‘86400′,
- `minimum` int(11) NOT NULL default ‘3600′,
- `serial` bigint(20) NOT NULL default ‘2008082700′,
- `resp_person` varchar(64) NOT NULL default ‘root.domain.com.’,
- `primary_ns` varchar(64) NOT NULL default ‘ns1.domain.com.’,
- `data_count` int(11) NOT NULL default ‘0′,
- PRIMARY KEY (`id`),
- KEY `type` (`type`),
- KEY `host` (`host`),
- KEY `zone` (`zone`)
- ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=gbk;
- CREATE TABLE IF NOT EXISTS `xfr_table` (
- `zone` text,
- `client` text,
- `view` varchar(10) default ‘ANY’,
- KEY `zone_client_index` (`zone`(30),`client`(30))
- ) ENGINE=MyISAM DEFAULT CHARSET=gbk;
- CREATE TABLE IF NOT EXISTS `data_count` (
- `zone` text NOT NULL,
- `count` bigint(20) default ‘0′,
- `view` varchar(10) default ‘ANY’,
- PRIMARY KEY (`zone`(30))
- ) ENGINE=MyISAM DEFAULT CHARSET=gbk;
- INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES
- (’shaosong.com’, ‘@’, ‘SOA’, ‘ns1.shaosong.com.’, 10, ‘CNC’, NULL, 3600, 3600, 86400, 10, 2008082700, ‘root.shaosong.com.’, ‘ns1.shaosong.com.’, 0);
- INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`,
- `primary_ns`, `data_count`) VALUES
- (’shaosong.com’, ‘@’, ‘SOA’, ‘211.100.72.137′, 3600, ‘CNC’, NULL, 3600, 3600, 86400, 3600, 2008082700, ‘root.shaosong.com.’, ‘ns1.shaosong.com.’, 0);
- INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES
- (’shaosong.com’, ‘ns1′, ‘A’, ‘211.100.72.137′, 3600, ‘CNC’, NULL, 3600, 3600, 86400, 3600, 2008082700, ‘root.shaosong.com.’, ‘ns1.shaosong.com.’, 0);
- INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES
- (’shaosong.com’, ‘ns2′, ‘A’, ‘219.232.244.11′, 3600, ‘CNC’, NULL, 3600, 3600, 86400, 3600, 2008082700, ‘root.shaosong.com.’, ‘ns1.shaosong.com.’, 0);
- INSERT INTO `dns_records` (`zone`, `host`, `type`, `data`, `ttl`, `view`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES
- (’shaosong.com’, ‘www’, ‘A’, ‘210.51.36.116′, 3600, ‘CNC’, NULL, 3600, 3600, 86400, 3600, 2008082700, ‘root.shaosong.com.’, ‘ns1.shaosong.com.’, 0);
- INSERT INTO dns_records (zone,host,type,DATA,view)
- 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服务.
测试是否成功。