BIND + MySQL

Source: Internet
Author: User
Tags mysql host

BIND + MySQL
Introduction to adding support for mysql databases using the bind-mysql module: For bind, if you want to modify or add dns records, you can directly modify the text. This is inconvenient for management and error-prone, if we add support for the mysql database and use php, perl, python, and other programs to directly operate mysql, it will be very convenient and error-prone for dns management. This section describes how to use the mysql bind driver module to implement this function. 1. Install mysql to install the mysql server. You can use yum or source code for compilation and installation. Here we use yum for installation. Yum-y install mysql-server mysql-devel 2. install bind and mysql-bind 1. Download bind and mysql-bind cd/tmpwget http://nchc.dl.sourceforge.net/project/mysql-bind/mysql-bind/mysql-bind-0.2%20src/mysql-bind.tar.gzwget http://ftp.isc.org/isc/bind9/cur/9.9/bind-9.9.1-P2.tar.gztar xzf bind-9.9.1-P2.tar.gztar xzf mysql-bind.tar.gz 2. copy mysql-bind mysqldb. c and mysqldb. h To bind-9.9.1-P2/bin/named and bind-9.9.1-P2/bin/named/ Include cd/tmp/mysql-bindcp mysqldb. c mysqldb. h/tmp/bind-9.9.1-P2/bin/namedcp mysqldb. c mysqldb. h/tmp/bind-9.9.1-P2/bin/named/include 3, modify bind source code in bin/named/Makefile. in File: DBDRIVER_OBJS = mysqldb. @ O @ # note that the two @ in the middle are uppercase ODBDRIVER_SRCS = mysqldb. cdbdriver_shortdes =-I/usr/include/mysql-g-pipe-Wp, -D_FORTIFY_SOURCE = 2-fexceptions-fstack-protector -- param = ssp-buffer-size = 4-m32-fasynchronous-unwind-t Ables-D_GNU_SOURCE-D_FILE_OFFSET_BITS = 64-D_LARGEFILE_SOURCE-fno-strict-aliasing-sources =-rdynamic-L/usr/lib/mysql-lmysqlclient-lz-lcrypt-lnsl-lm-L /usr/lib-lssl-lcrypto note: the value of DBDRIVER_INCLUDES is obtained by the command/usr/bin/mysql_config -- cflags. The value of DBDRIVER_LIBS is obtained by the command/usr/bin/mysql_config -- libs. 4. Edit the bind source file bin/named/main. c 4.1. Add mysqldb_init () before ns_server_create () in the setup (void) function, such as/** Add callto register sdb drivers here. * // * xxdb_init (); */mysqldb_init (); ns_server_create (ns_g_mctx, & ns_g_server); 4.2. ns_server_destroy () in the cleanup (void) Function () add mysqldb_clear (), such as ns_server_destroy (& ns_g_server); mysqldb_clear ();/** Add callto unregister sdb drivers here. * // * xxdb_clear (); */4.3. Edit bin/named/mysqldb In the bind source file. c file: change # include <named/mysqldb. h> is # include "include/mysqldb. h "4.4 install bind yum-y install gcc openssl-develcd/tmp/bind-9.9.1-P2. /configure -- prefix =/usr/local/bind -- disable-openssl-version-checkmake & make install 3. mysql configuration start: service mysqld start set root password: mysqladmin-uroot password root create database: mysql> CREATE database dns; create TABLE: mysql> create table mydomain (name varchar (255) default NULL, ttl int (11) default NULL, rdtype varchar (255) default NULL, rdata varchar (255) default NULL) TYPE = MyISAM; INSERT data example: data required for forward parsing: insert into mydomain VALUES ('mydomain. com ', 259200, 'soa', 'mydomain. com. mail.mydomain.com. 200309181 28800 7200 86400 28800 '); insert into mydomain VALUES ('mydomain. com ', 259200, 'ns', 'dns .mydomain.com. '); insert into mydomain VALUES ('mydomain. com ', 259200, 'mx', '10 mail.mydomain.com. '); insert into mydomain VALUES ('dns .mydomain.com', 259200, 'A', '2017. 168.131.129 '); insert into mydomain VALUES ('mail .mydomain.com', 259200, 'A', '2017. 168.131.131 '); insert into mydomain VALUES ('www .mydomain.com', 259200, 'A', '2017. 168.132 '); insert into mydomain VALUES ('ftp .mydomain.com', 259200, 'A', '2017. 168.131.20.'); the data required for reverse resolution: insert into mydomain VALUES ('2017. 168.192.in-addr. arpa ', 17600, 'soa ', 'mydomain. com. mail.mydomain.com. 200309181 28800 7200 86400 28800 '); insert into mydomain VALUES ('2017. 168.192.in-addr. arpa ', 17600, 'ns', 'dns .mydomain.com. '); insert into mydomain VALUES (' 129. 131.168.192.in-addr. arpa ', 17600, 'ptr', 'dns .mydomain.com. '); insert into mydomain VALUES (' 131. 131.168.192.in-addr. arpa ', 17600, 'ptr', 'mail .mydomain.com. '); insert into mydomain VALUES (' 132. 131.168.192.in-addr. arpa ', 17600, 'ptr ', 'www .mydomain.com. '); insert into mydomain VALUES (' 133. 131.168.192.in-addr. arpa ', 17600, 'ptr ', 'ftp .mydomain.com. '); Conclusion: if there are a lot of forward and reverse parsing data, you can put forward parsing data in a table, put reverse parsing data in another table. 4. bind: Configure vim/usr/local/bind/etc/named. conf zone "mydomain.com" {# type master; notify no; database "mysqldb dbname tablename hostname user password" ;}; zone "131.168.192.in-addr. arpa "{# type master; notify no; database" mysqldb dns mydomain localhost root 123456 ";}; where dbname is the database name and tablename is the table name, hostname is the mysql host, followed by the user name and password to start bind:/usr/local/bind/sbin/named. Note: Figure 5. Forward/reverse resolution test # nslookup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.