VirtualBox中对Redhat的网络连接方式不要用默认的网络地址转换(NAT), 选用桥接网卡,这样主机和虚拟机可以双向通信。
MySQL5.6以RPM包形式安装,其默认路径分别如下。
BIN:/usr/bin/mysql
头文件H:/usr/include/mysql
库文件LIB:/usr/lib64 ##可以通过mysql_config --libs命令知道
1、解压Bind和mysql-bind,将mysql-bind下的mysqldb.h拷贝到bind的bin/named/include/named目录下,将mysqldb.c拷贝到bind的bin/named目录下。
2、修改Bind的bin/named目录下的MakeFile.in文件。
DBDRIVER_OBJS = mysqldb.@O@ DBDRIVER_SRCS = mysqldb.c DBDRIVER_INCLUDES = -I'/usr/include/mysql/' DBDRIVER_LIBS = -L'/usr/lib64/mysql' -lmysqlclient -lz -lcrypt -lnsl -lm -lc -lnss_files -lnss_dns -lresolv -lc -lnss_files -lnss_dns -lresolv
3、编辑bind源文件bin/named/main.c
--包含mysqldb.h,#include
--在函数setup(void)里面ns_server_create()的前面添加mysqldb_init();
--在函数cleanup(void)里面ns_server_destroy()的后面添加mysqldb_clear();
4、编译安装bind
./configure
make
make install
5、创建数据库bind9,创建表kaopu。
CREATE TABLE kaopu ( `name` varchar(255) default NULL, ttl int(11) default NULL, rdtype varchar(255) default NULL, rdata varchar(255) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
初始化数据:
insert into `kaopu` (`name`, `ttl`, `rdtype`, `rdata`) values('www.kaopu.com','3600','A','10.3.19.14'); insert into `kaopu` (`name`, `ttl`, `rdtype`, `rdata`) values('ns1.kaopu.com','3600','A','127.0.0.1'); insert into `kaopu` (`name`, `ttl`, `rdtype`, `rdata`) values('kaopu.com','3600','NS','ns1.kaopu.com'); insert into `kaopu` (`name`, `ttl`, `rdtype`, `rdata`) values('kaopu.com','3600','SOA','kaopu.com. www.kaopu.com. 2003080800 172800 900 1209600 3600');
6、配置Bind
--生成控制文件
rndc-confgen > /etc/named/rndc.conf
# Start of rndc.conf key "rndc-key" { algorithm hmac-md5; secret "rHLs03YrlkgYVhFl7dZZ7A=="; }; options { default-key "rndc-key"; default-server 127.0.0.1; default-port 953; }; # End of rndc.conf # Use with the following in named.conf, adjusting the allow list as needed: # key "rndc-key" { # algorithm hmac-md5; # secret "rHLs03YrlkgYVhFl7dZZ7A=="; # }; # # controls { # inet 127.0.0.1 port 953 # allow { 127.0.0.1; } keys { "rndc-key"; }; # }; # End of named.conf
--生成named.conf
tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf
--编辑named.conf
key "rndc-key" { algorithm hmac-md5; secret "rHLs03YrlkgYVhFl7dZZ7A=="; }; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; include "/etc/named/named.conf.options"; zone "." { type hint; file "/etc/named/named.root"; }; zone "localhost" { type master; file "/etc/named/named.localhost"; }; zone "kaopu.com" IN { type master; notify no; database "mysqldb bind9 kaopu localhost bind9 welcome1"; };
/etc/named/named.conf.options如下
options { directory "/etc/named"; allow-query { any; }; allow-recursion { any; }; allow-query-cache {any;}; datasize 2098; };
/etc/named/named.localhost如下
$TTL 600 @ IN SOA localhost. root.localhost. (2011080101 3H 15M 1W 1D) @ IN NS localhost. localhost. IN A 10.3.19.79
/etc/named/named.root如下
; <<>> DiG 9.10.1 <<>> ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53287 ;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 14 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4000 ;; QUESTION SECTION: ;. IN NS ;; ANSWER SECTION: . 1731 IN NS d.root-servers.net. . 1731 IN NS a.root-servers.net. . 1731 IN NS b.root-servers.net. . 1731 IN NS m.root-servers.net. . 1731 IN NS f.root-servers.net. . 1731 IN NS l.root-servers.net. . 1731 IN NS h.root-servers.net. . 1731 IN NS k.root-servers.net. . 1731 IN NS c.root-servers.net. . 1731 IN NS j.root-servers.net. . 1731 IN NS g.root-servers.net. . 1731 IN NS i.root-servers.net. . 1731 IN NS e.root-servers.net. ;; ADDITIONAL SECTION: d.root-servers.net. 2077 IN A 199.7.91.13 a.root-servers.net. 71592 IN A 198.41.0.4 b.root-servers.net. 2087 IN A 192.228.79.201 m.root-servers.net. 2091 IN A 202.12.27.33 f.root-servers.net. 1731 IN A 192.5.5.241 l.root-servers.net. 84257 IN A 199.7.83.42 h.root-servers.net. 2110 IN A 128.63.2.53 k.root-servers.net. 2111 IN A 193.0.14.129 c.root-servers.net. 614 IN A 192.33.4.12 j.root-servers.net. 2049 IN A 192.58.128.30 g.root-servers.net. 2050 IN A 192.112.36.4 i.root-servers.net. 912 IN A 192.36.148.17 e.root-servers.net. 2076 IN A 192.203.230.10 ;; Query time: 53 msec ;; SERVER: 10.3.1.2#53(10.3.1.2) ;; WHEN: Thu Nov 06 10:46:18 CST 2014 ;; MSG SIZE rcvd: 460
named.root文件可由命令生成:dig -t NS . > /etc/named/named.root
database "mysqldb bind9 kaopu localhost bind9 welcome1";解释如下:
bind9-数据库名
kaopu-数据库表名
localhost-数据库主机名
bind9-用户名
welcome1-密码
7、验证MySQL-bind SDB方式。
输入命令:dig @127.0.0.1 www.kaopu.com
响应如下:
; <<>> DiG 9.10.1 <<>> @127.0.0.1 www.kaopu.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3426 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.kaopu.com. IN A ;; ANSWER SECTION: www.kaopu.com. 3600 IN A 10.3.19.14 ;; AUTHORITY SECTION: kaopu.com. 3600 IN NS ns1.kaopu.com. ;; ADDITIONAL SECTION: ns1.kaopu.com. 3600 IN A 127.0.0.1 ;; Query time: 1 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Thu Nov 06 17:43:56 CST 2014 ;; MSG SIZE rcvd: 92
比较有参考意义的几篇博客。
使用Mysql-bind实现mysql管理bind配置: http://www.aooshi.org/blog/article/81.html
Binding Bind to MySQL... On RHEL5: http://pbraun.nethence.com/unix/net/named-mysql.html
bind9安装: http://blog.csdn.net/chenfei_5201213/article/details/7866231