- 注册时间
- 2008-5-19
- 最后登录
- 2021-2-28
- 在线时间
- 1946 小时
- 阅读权限
- 200
- 积分
- 59491
- 帖子
- 2551
- 主题
- 1209
- 精华
- 25
- UID
- 1
  
- 签到
- 476
- 注册时间
- 2008-5-19
- 最后登录
- 2021-2-28
- 在线时间
- 1946 小时
- 阅读权限
- 200
- 积分
- 59491
- 帖子
- 2551
- 主题
- 1209
- 精华
- 25
- UID
- 1
|
一.Bind-DLZ介绍
Bind-DLZ主页:http://bind-dlz.sourceforge.net/
Bind-DLZ发布软件的频率跟不上Bind9,新版本的Bind9不被官方的Bind-DLZ支持,因此有人做了跟进。
DLZ(Dynamically Loadable Zones)与传统的BIND9不同,BIND的不足之处:
- BIND从文本文件中获取数据,这样容易因为编辑错误出现问题。
- BIND需要将数据加载到内存中,如果域或者记录较多,会消耗大量的内存。
- BIND启动时解析Zone文件,对于一个记录较多的DNS来说,会耽误更多的时间。
- 如果近修改一条记录,那么要重新加载或者重启BIND才能生效,那么需要时间,可能会影响客户端查询。
二.安装配置Bind-DLZ
#mkidr /usr/local/src/bind
#cd /usr/local/src/bind
#wget http://ftp.isc.org/isc/bind9/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
1.编译安装- ./configure --with-dlz-mysql --enable-largefile --enable-threads=no --prefix=/usr/local/bind
- make && make install
复制代码 注:采用mysql做后台数据库,千万不能用?enable-threads选项启用多线程,网上有一些朋友使用mysql做后台,谈到bind会莫名中断服务,大部分都是因为打开了多线程。
2.创建相关配置文件- cd /usr/local/bind/etc/
- ../sbin/rndc-confgen >rndc.conf
- tail -n10 rndc.conf | head -n9 | sed -e s/#\//g >named.conf
复制代码 vi localhost.zone
ttl 86400- @ IN SOA localhost. root.localhost. (
- 1997022700 ; Serial
- 28800 ; Refresh
- 14400 ; Retry
- 3600000 ; Expire
- 86400 ) ; Minimum
- IN NS localhost.
- 1 IN PTR localhost.
复制代码 dig > named.root
3.在named.conf中添加DLZ相关的设置
#vi named.conf //在后面添加如下
dlz "Mysql zone" {
database "mysql
{host=127.0.0.1 dbname=dns ssl=false port=3306 user=root pass= } //数据库相关连接账号,注意填写正确.
{select zone from dns_records where zone = '%zone%' limit 1}
{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')
else data end from dns_records where zone = '%zone%' and host = '%record%'
and not (type = 'SOA' or type = 'NS')}
{select ttl, type, mx_priority, data, resp_person, serial, refresh, retry, expire, minimum
from dns_records where zone = '%zone%' and (type = 'SOA' or type='NS')}
{select ttl, type, host, mx_priority, data, resp_person, serial, refresh, retry, expire,
minimum from dns_records where zone = '%zone%' and not (type = 'SOA' or type = 'NS')}
{select zone from xfr_table where zone = '%zone%' and client = '%client%'}
{update data_count set count = count + 1 where zone ='%zone%'}";
};
4. 创建DNS数据库建一个表dns_records- use dns;
- DROP TABLE IF EXISTS `dns_records`;
- 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') NOT NULL,
- `data` varchar(255) default NULL,
- `ttl` int(11) NOT NULL default '800',
- `mx_priority` varchar(255) 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) default NULL,
- PRIMARY KEY (`id`),
- KEY `id` (`id`),
- KEY `type` (`type`),
- KEY `host` (`host`),
- KEY `zone` (`zone`)
- ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
复制代码 5.在在终端启动调试bind服务
[root@lemp ~]# /usr/local/bind/sbin/named -uroot -g -d 1
/usr/local/bind/sbin/named: error while loading shared libraries: libmysqlclient.so.16 //出错
#ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib/ //建立链链接即可.
#ldconfig
# /usr/local/bind/sbin/named -uroot -g -d 1 //无报错信息,继续如下.
三.添加相关记录并进行测试.
1.#zone anlegen:
--soa- INSERT INTO dns_records (zone,host,type,serial,refresh,retry,expire,minimum,primary_ns,resp_person)
- VALUES ('linuxtone.org', '@', 'SOA', 2009030200, 172800, 800, 1209600, 3600 , 'ns1.linuxtone.org', 'root.linuxtone.org.');
复制代码 --linuxtone.org redirection for any host to linuxtone.org.- INSERT INTO dns_records (zone,host,type,DATA)
- VALUES ('linuxtone.org', '*', 'CNAME', 'linuxtone.org.');
复制代码 --nameserver for zone- INSERT INTO dns_records (zone,host,type,DATA)
- VALUES ('linuxtone.org', '@', 'NS', 'ns1.linuxtone.org.');
复制代码 --toplevel-ip-address of zone itself- INSERT INTO dns_records (zone,host,type,DATA)
- VALUES ('linuxtone.org', '@', 'A', '192.168.0.103');
复制代码 2.#host anlegen:
--ip nameserver (resp_person can be NULL)- INSERT INTO dns_records (zone,host,type,DATA,resp_person)
- VALUES ('linuxtone.org', 'ns1', 'A', '192.168.0.103', 'root.linuxtone.org.');
复制代码 A:www.linuxtone.org- INSERT INTO dns_records (zone,host,type,DATA)
- VALUES ('linuxtone.org', 'www', 'A', '192.168.0.108');
复制代码 A:bbs.linuxtone.org- INSERT INTO dns_records (zone,host,type,DATA)
- VALUES ('linuxtone.org', 'bbs', 'A', '192.168.0.109');
复制代码 3.#host alias anlegen:
--ns2 directs to ns1- INSERT INTO dns_records (zone,host,type,DATA,resp_person)
- VALUES ('linuxtone.org', 'ns2', 'CNAME', 'ns1.linuxtone.org.', 'root.linuxtone.org.');
复制代码 alias:man.linuxtone.org cname www- INSERT INTO dns_records (zone,host,type,DATA)
- VALUES ('linuxtone.org', 'man', 'CNAME', 'www');
复制代码 alias: host.linuxton.org cname bbs- INSERT INTO dns_records (zone,host,type,DATA)
- VALUES ('linuxtone.org', 'host', 'CNAME', 'bbs.linuxtone.org.');
复制代码 4.#mailserver anlegen:
--ns2 directs to ns1- INSERT INTO dns_records (zone,host,type,DATA,mx_priority, resp_person)
- VALUES ('linuxtone.org', '*', 'MX', 'mail.linuxtone.org.', '80', 'root.linuxtone.org.');
复制代码 四.相关表结构及bind查询测试.
1.表结构:
2.查询测试(增加记录实时生效,再也不要像以前一样重启相关配置文件了.)
附:
我的表结构和相关数据:
dns.sql
(4.29 KB, 下载次数: 446)
{请下载}
named.conf配置文件:
named.conf
(1.05 KB, 下载次数: 24)
四.启动脚本(增加named进程数,提高性能!)
1.创建多个named.conf配置文件- for i in `seq 1 8`
- do
- cp named.conf named1$i.conf
- done
复制代码
2.启动脚本
[root@lemp etc]# vi /etc/init.d/named
#!/bin/bash
# named a network name service.
# chkconfig: 345 35 75
# description: a name server
# http://www.linuxtone.org
if [ `id -u` -ne 0 ]
then
echo "ERROR:For bind to port 53,must run as root."
exit 1
fi
case "$1" in
start)
if [ -x /usr/local/bind/sbin/named ]; then
for i in `seq 1 8`
do
/usr/local/bind/sbin/named -c /usr/local/bind/etc/named1$i.conf -u root
echo "BIND9-named1$i server started"
done
fi
;;
stop)
kill `cat /usr/local/bind/var/named.pid` && echo . && echo 'BIND9 server stopped'
;;
restart)
echo .
echo "Restart BIND9 server"
$0 stop
sleep 10
$0 start
;;
reload)
/usr/local/bind/sbin/rndc reload
;;
status)
/usr/local/bind/sbin/rndc status
;;
*)
echo "$0 start | stop | restart |reload |status"
;;
esac |
|