標籤:service pre ptr 定義 依賴包 官網 分享 cmake 測試結果
參考文檔: http://blog.csdn.net/lishangwen_alan/article/details/53332889
http://www.cnblogs.com/xiongpq/p/3384681.html
需求說明: bind下用mysql可以動態載入DNS記錄(dlz), 唯一有點不爽的是mysql bind 都需要源碼編譯安裝,
簡直吐血, 所以整理下來.
1. mysql 編譯安裝:
安裝依賴包
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
下載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
編譯安裝:
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
配置mysql
設定許可權:
# groupadd mysql
# groupadd -g mysql mysql
# chown -R mysql:mysql /usr/local/mysql
初始化配置:
# cd /usr/local/mysql
# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
注意: 將/etc/my.cnf 改成其他名字,以防衝突
啟動MySQl
# cp support-files/mysql.server /etc/init.d/mysql# chkconfig mysql on# service mysql start --啟動MySQL
配置使用者
# PATH=/usr/local/mysql/bin:$PATH
# export PATH
# source /etc/profile
# mysql -uroot
mysql> set password = password(‘123456‘)
設定遠端存取
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘*‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;
mysql 配置完成
2. bind 編譯安裝:
# ./configure --prefix=/usr/local/bind/ --with-dlz-mysql=/usr/local/mysql --enable-threads=no --enable-largefile --disable-ipv6 --with-openssl=no
//--enable-threads 多線程支援(官網解析是需要關閉),--enable-largefile 啟用大檔案支援,--disable-ipv6 關閉ipv6支援,--with-dlz-mysql意思是使用mysql儲存網域名稱解析
# make make install
3. 配置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檔案
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 53 {any;}; //開啟偵聽53連接埠,any表示接受任意ip串連
directory "/usr/local/bind/var";
pid-file "named.pid"; //檔案內容就是named進程的id
allow-query{any;}; //允許任意ip查詢
forwarders{114.114.114.114;8.8.8.8;}; //設定轉寄的公網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 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‘) 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 zone = ‘$zone$‘ and not (type = ‘SOA‘ or type = ‘NS‘) and status = 1}";
};
5. mysql 配置:
create database dns_data
use dns_data
create table `dns_records` (
`id` bigint(20) not null auto_increment comment ‘主健‘,
`zone` varchar(255) not null default ‘‘ comment ‘網域名稱‘,
`host` varchar(255) not null default ‘@‘ comment ‘記錄名稱‘,
`type` varchar(255) not null default ‘A‘ comment ‘記錄類型‘,
`data` varchar(255) default null comment ‘記錄值‘,
`ttl` int(11) not null default ‘800‘ comment ‘ttl(存活時間)‘,
`mx_priority` int(11) default null comment ‘mx優先順序‘,
`refresh` int(11) default null comment ‘重新整理時間間隔‘,
`retry` int(11) default null comment ‘重試時間間隔‘,
`expire` int(11) default null comment ‘到期時間‘,
`minimum` int(11) default null comment ‘最小時間‘,
`serial` bigint(20) default null comment ‘序號,每次更改配置都會在原來的基礎上加1‘,
`resp_person` varchar(64) default null comment ‘責任人‘,
`primary_ns` varchar(64) default null comment ‘主網域名稱‘,
`status` tinyint(4) default 1 comment ‘0:該記錄無效, 1:該記錄有效‘,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘建立時間‘,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘更新時間‘,
primary key (`id`),
key `ix_created_at` (`created_at`),
key `ix_updated_at` (`updated_at`)
) engine=InnoDB default charset=utf8 comment=‘內網DNS記錄‘;
6. 插入正向解析資料
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.‘, ‘60‘);
INSERT INTO dns_records (zone, host, type, ttl, data,refresh, retry, expire, minimum, serial, resp_person) VALUES (‘phpfensi.com‘, ‘@‘, ‘SOA‘, ‘60‘, ‘ns‘, ‘28800‘, ‘14400‘, ‘86400‘, ‘86400‘, ‘2012020809‘, ‘admin‘);
7. 插入反向解析資料
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‘); //添加SOA(授權地區定義)記錄
insert into dns_records (zone,host,type,data)values(‘1.168.192.in-addr.arpa‘,‘@‘,‘NS‘,‘node02.example.com.‘); //添加NS(標記地區的網域名稱伺服器以及授權子域)記錄
insert into dns_records(zone,host,type,data)values(‘1.168.192.in-addr.arpa‘,‘250‘,‘PTR‘,‘node02.example.com.‘),(‘1.168.192.in-addr.arpa‘,‘111‘,‘PTR‘,‘x.example.com.‘); //添加PTR(與A記錄相反,將ip轉換成主機名稱,反向解析操作)記錄
8. debug 模式下運行 bind 服務
# /usr/local/bind/sbin/named -g d 1
-g d 1 是debug的參數 可以查看到背景日誌資訊
8. 測試結果:
9. over
bind配置mysql後台