bind9+mysql dlz(Dynamically Loadable Zones)
yum install openssl openssl-devel
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
chown -R mysql:mysql /usr/local/mysql
./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client -with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
make && make install
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql
cd /usr/local/mysql
cp share/mysql/my-medium.cnf /etc/my.cnf
nphup ./mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/usr/local/mysql/var &
登录mysql /usr/local/mysql/bin/mysql
insert into mysql.user(Host,User,Password) values("localhost","dns",password("dns"));
insert into mysql.user(Host,User,Password) values("%","dns",password("dns"));
GRANT ALL PRIVILEGES ON *.* TO ‘dns‘@‘%‘ IDENTIFIED BY ‘dns‘ WITH GRANT OPTION;
flush privileges;
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;
--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,9.4.0以上版本都有DLZ补丁了,DLZ(Dynamically Loadable Zones),允许区域记录放置在数据库中,并且支持多种数据库。
./configure --with-dlz-mysql --enable-largefile --enable-threads=no --prefix=/usr/local/bind --disable-openssl-version-check
make && make install
cd /usr/local/bind/etc/
../sbin/rndc-confgen >rndc.conf
tail -n10 rndc.conf | head -n9 | sed -e s/#\//g >named.conf
dig > named.root //这一步没做成功也没关系 貌似
vi /usr/local/bind/etc/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$‘}";
};
启动
/usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。