Bind config MySQL background

Source: Internet
Author: User

Reference Document: http://blog.csdn.net/lishangwen_alan/article/details/53332889

Http://www.cnblogs.com/xiongpq/p/3384681.html

Requirements: Bind with MySQL can dynamically load DNS records (DLZ), the only thing is a bit uncomfortable is MySQL bind all need source code compiled installation,

It's spitting blood, so tidy it up.

1. mysql Compilation installation:

Install dependent packages
Yum-y install make gcc-c++ cmake bison-devel ncurses-devel

Download MySQL

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz
Tar xvf mysql-5.6.35.tar.gz

CD mysql-5.6.35

Compile and install:
Cmake-dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/usr/local/mysql/data-dsysconfdir=/etc-dwith_ Myisam_storage_engine=1-dwith_innobase_storage_engine=1-dwith_memory_storage_engine=1-dwith_readline=1-dmysql_ Unix_addr=/var/lib/mysql/mysql.sock-dmysql_tcp_port=3306-denabled_local_infile=1-dwith_partition_storage_ Engine=1-dextra_charsets=all-ddefault_charset=utf8-ddefault_collation=utf8_general_cimake && make Install

Configure MySQL
Set permissions:
# Groupadd MySQL
# groupadd-g MySQL MySQL
# Chown-r Mysql:mysql/usr/local/mysql

Initialize the configuration:
# Cd/usr/local/mysql
# scripts/mysql_install_db--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data--user=mysql

Note: Change/etc/my.cnf to a different name in case of conflict

Start MySQL
# cp support-files/mysql.server/etc/init.d/mysql# chkconfig mysql on# service MySQL start--start MySQL

Configure users

# Path=/usr/local/mysql/bin: $PATH

# Export PATH

# Source/etc/profile

# Mysql-uroot
mysql> Set Password = password (' 123456 ')

Set up remote access
Mysql>
GRANT all privileges on *. * to ' root ' @ ' * ' identified by ' 123456 ' with GRANT OPTION;

MySQL Configuration complete


2. Bind compilation Installation:
#./configure --prefix=/usr/local/bind/-- with-dlz-mysql=/usr/local/mysql --enable -threads=no --enable-largefile --disable-ipv6 --with-openssl =no
  

# Make make Install

3. Configure bind:
# cd/usr/local/bind/etc/
#/usr/local/bind/sbin/rndc-confgen > rndc.conf
# Cat Rndc.conf >rndc.key
# tail-10 Rndc.conf | head-9 | Sed s/#\//g > named.conf

4. named.conf file

Key "Rndc-key" {
Algorithm HMAC-MD5;
Secret "mvcuyhydvnngywhovhbsaq==";
};

Controls {
inet 127.0.0.1 Port 953 allow {127.0.0.1;} keys {"Rndc-key";};
};


Options {
Listen-on Port: (any;}; Turn on listen on port 53, any to accept any IP connection
Directory "/usr/local/bind/var";
Pid-file "Named.pid"; The file content is the ID of the named process
Allow-query{any;}; Allow arbitrary IP queries
forwarders{114.114.114.114;8.8.8.8;}; Set up a forwarded public IP
};

Dlz "Mysql zone" {
Database "MySQL
{dbname=dns_data port=3306 host=localhost user=root pass=123456 Ssl=false}
{Select zone from dns_records where zone = ' $zone $ ' and status = 1}
{Select TTL, type, mx_priority, case if lower (type) = ' txt ' then concat (' \ ' ', data, ' \ ') Else data end from Dns_records W Here zone = ' $zone $ ' and the host = ' $record $ ' and not (type = ' SOA ' or type = ' NS ') and status = 1}
{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 ') and status = 1}
{Select TTL, type, host, mx_priority, data, Resp_person, serial, refresh, retry, expire, minimum from dns_records where Zo NE = ' $zone $ ' and not (type = ' SOA ' or type = ' NS ') and status = 1} ";
};


5. mysql Configuration:

Create DATABASE Dns_data

Use Dns_data
CREATE TABLE ' Dns_records ' (
' ID ' bigint (a) NOT NULL auto_increment comment ' main health ',
' Zone ' varchar (255) NOT null default ' comment ' Domain name ',
' Host ' varchar (255) NOT NULL default ' @ ' comment ' record name ',
' type ' varchar (255) NOT null default ' A ' comment ' record type ',
' Data ' varchar (255) default NULL comment ' record value ',
' TTL ' int (one) not null default ' comment ' TTL (live Time) ',
' Mx_priority ' int (one-by-one) default null comment ' mx priority ',
' Refresh ' int (one) default null comment ' Flush interval ',
' Retry ' int (one) default null comment ' Retry interval ',
' Expire ' int (one) default null comment ' Expire time ',
' Minimum ' int (one) default null comment ' Minimum time ',
' Serial ' bigint () default NULL comment ' serial number, each change configuration will add 1 ' on the original base,
' Resp_person ' varchar (+) default NULL comment ' Responsible person ',
' Primary_ns ' varchar (+) default NULL comment ' primary domain ',
' Status ' tinyint (4) Default 1 Comment ' 0: The record is invalid, 1: The record is valid ',
' Created_at ' timestamp not NULL DEFAULT current_timestamp COMMENT ' creation time ',
' Updated_at ' timestamp not NULL the DEFAULT current_timestamp on update current_timestamp COMMENT ' Update Time ',
Primary KEY (' ID '),
Key ' Ix_created_at ' (' Created_at '),
Key ' Ix_updated_at ' (' Updated_at ')
) Engine=innodb default Charset=utf8 comment= ' intranet DNS record ';


6. Inserting forward parsing data
 INSERT into dns_records (zone, host, type, data, TTL) VALUES (' phpfensi.com ', ' www ', ' A ', ' 1.1.1.1 ', ' 60 '); 
INSERT into dns_records (zone, host, type, data, TTL) VALUES (' phpfensi.com ', ' cloud ', ' A ', ' 2.2.2.2 ', ' 60 ');
INSERT into dns_records (zone, host, type, data, TTL) VALUES (' phpfensi.com ', ' ns ', ' A ', ' 3.3.3.3 ', ' 60 ');
INSERT into dns_records (zone, host, type, data, TTL) VALUES (' phpfensi.com ', ' blog ', ' CNAME ', ' cloud.phpfensi.com ', ' 60 ');
INSERT into dns_records (zone, host, type, data, TTL) VALUES (' phpfensi.com ', ' @ ', ' NS ', ' ns.phpfensi.com. ');
insert into dns_records (zone, Host, type, TTL, Data,refresh, retry, expire, minimum, serial, Resp_person) VALUES (' PHPF Ensi.com ', ' @ ', ' SOA ', ' All ', ' ns ', ' 28800 ', ' 14400 ', ' 86400 ', ' 86400 ', ' 2012020809 ', ' admin ');

7. Inserting reverse parsing data

Insert into Dns_records (Zone,host,type,data,ttl,mx_priority,refresh,retry,expire,minimum,serial,resp_person, Primary_ns) VALUES (' 1.168.192in-addr.arpa ', ' @ ', ' SOA ', ' node02.example.com ', 86400,null, 3600,15,86400,3600,2008082700, ' node02.example.com ', ' node02.example.com ');   Add an SOA (authorization area definition) record
Insert into Dns_records (zone,host,type,data) VALUES (' 1.168.192.in-addr.arpa ', ' @ ', ' NS ', ' node02.example.com. '); Add NS (domain name servers for labeled zones and authorization subdomains) records
Insert into Dns_records (zone,host,type,data) VALUES (' 1.168.192.in-addr.arpa ', ' + ', ' PTR ', ' node02.example.com. '), ( ' 1.168.192.in-addr.arpa ', ' 111 ', ' PTR ', ' x.example.com '); Add PTR (in contrast to a record, convert IP to hostname, reverse parse operation) record

8. Run the BIND service in debug mode
#/usr/local/bind/sbin/named-g D 1

-G d 1 is the debug parameter to view the log information in the background

8. Test results:

9. Over





Bind config MySQL background

Related Article

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.