【Linux】基于Bind_DLZ和MySQL数据的DNS搭建
参考:http://www.linuxfromscratch.org/blfs/view/cvs/server/bind.html
参考:http://bind-dlz.sourceforge.net/
参考:http://www.shencan.net/index.php/2013/05/21/bind9-dlz-%e6%90%9edns/
参考:http://www.phpfensi.com/linux/20150507/9927.html
依赖:libcap libxml2 OpenSSL geoip (MIT)
编译参数(官网说明强调编译关闭多线程,即--enable-threads=no):
[root@dns bind-9.10.-P4]# ./configure --prefix=/usr/local/bind --enable-epoll --enable-largefile --enable-threads=no --with-dlz-mysql=/usr/local/mysql --disable-openssl-version-check
生成rndc.cnf:
[root@dns etc]# cd /usr/local/bind/etc
[root@dns etc]# ../sbin/rndc-confgen > rndc.conf
生成named.cnf:
[root@dns etc]# tail - rndc.conf | head - | sed s/#\ //g > named.conf
编辑named.cnf,添加dlz mysql驱动,参考其他资料也可以配置智能DNS。
(官方的dlz mysql驱动中有5个查询和1个更新语句,具体每个查询的功能可以参考官方说明)
key "rndc-key" {
algorithm hmac-md5;
secret "THnBnPv//oADGjeKQMoNng==";
};
controls {
inet 127.0.0.1 port
allow { 127.0.0.1; } keys { "rndc-key"; };
};
options {
allow-recursion { none; };
recursion no;
directory "/usr/local/bind/etc";
version "leju-db-direct";
pid-file "named.pid";
};
logging {
channel default_debug {
file "/tmp/bind_query.log" versions size 10m;
severity info;
print-time yes;
print-category yes;
};
category queries {
default_debug;
};
# category database {
# default_debug;
# };
};
dlz "mysql zone" {
database "mysql
{host=localhost dbname=name ssl=false port= user=user pass=pass socket=/tmp/mysql_3306.sock}
{select zone from dns_records where zone = '$zone$' limit }
{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"') when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire,minimum) else data end as mydata from dns_records where zone = '$zone$' and host ='$record$' and IsLive=1}";
};
官网给的mysql驱动模板:
dlz "mysql zone" {
database "mysql
{host=127.0.0.1 dbname=name ssl=false port= user=user pass=pass}
{select zone from dns_records where zone = '$zone$' limit }
{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 IsLive=1}
{select ttl, type, mx_priority, data 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') and IsLive=1}
{select zone from xfr_table where zone = '$zone$' and client = '$client$'}";
};
模板的查询需要根据环境修改。
如果驱动部分存在查询问题,或者表中值定义存在异常会出现以下报错:
-Sep- ::47.621 dns_rdata_fromtext: buffer-0x7fffc7277da0:: near eof: unexpected end of input
-Sep- ::47.621 dns_sdlz_putrr returned error. Error code was: unexpected end of input
参考:http://blog.163.com/digoal@126/blog/static/163877040201110235657127/
数据库建表:
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','PTR') NOT NULL,
`data` varchar(255) DEFAULT NULL,
`ttl` int(11) NOT NULL DEFAULT '',
`mx_priority` int(11) DEFAULT NULL,
`refresh` int(11) NOT NULL DEFAULT '',
`retry` int(11) NOT NULL DEFAULT '',
`expire` int(11) NOT NULL DEFAULT '',
`minimum` int(11) NOT NULL DEFAULT '',
`serial` bigint(20) NOT NULL DEFAULT '',
`resp_person` varchar(64) NOT NULL DEFAULT 'root.domain.com.',
`primary_ns` varchar(64) NOT NULL DEFAULT 'ns1.domain.com.',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
插入数据:
mysql> insert INTO dns_records (zone,host,type,data,ttl,retry) values ('helloworld.com','bbs','A','192.168.1.101',86400,15);
mysql> insert INTO dns_records (zone,host,type,data,ttl,retry) values ('helloworld.com','news','A','192.168.1.102',86400,15);
debug启动:
[root@dns sbin]# ./named -g -d 1
[root@dns sbin]# ./named -c ../etc/named.cnf #启动服务
如果出现MySQL无法建立连接的报错,例如:
mysql driver failed to create database connection after 4 attempts
我通过在dlz mysql驱动中使用socket方式连接数据库解决这个问题。
强制手动刷新
[root@dns sbin]# ./rndc flush
停止服务
[root@dns sbin]# ./rndc stop
DNS数据说明
type
type字段用于说明RR的类型。常用的RR类型如下:
1、区记录
SOA (Start Of Authority):SOA记录标示一个授权区定义的开始。SOA 记录后的所有信息是控制这个区的。
NS (Name Server):标识区的域名服务器以及授权子域。
2、基本记录
A (Address):用于将主机名转换为 IP 地址,任何一个主机都只能有一个A记录。
PTR (PoinTeR):将地址转换为主机名。
MX (Mail eXchanger):邮件交换记录。控制邮件的路由。
3、安全记录
KEY (Public Key):储存一个关于DNS 名称的公钥。
NXT (Next):与 DNSSEC 一起使用,用于指出一个特定名称不在域中。
SIG (Signatrue):指出带签名和身份认证的区信息,细节见 RFC 2535。
4、可选记录
CNAME (Canonical NAME):给定主机的别名,主机的规范名在A记录中给出。
SRV (Services):指出知名网络服务的信息。
TXT (Text):注释或非关键的信息。
RR的顺序:
SOA RR应该放在最前面。通常NS RR紧跟在SOA RR之后,其他记录的顺序无关紧要。
data
存放该行host+zone域名解析的IP。
ttl (time to live)
它以秒为单位定义该资源记录中的信息存放在高速缓存中的时间长度。通常省略该字段,而使用位于文件开始处的$TTL语句所指定值。
SerialNumber
本区配置数据的序列号,用于从服务器判断何时获取最新的区数据。
可以是 32 位的任何整数,每当更新区文件时都应该增加此序列号的值,否则 named 将不会把区的更新数据传送到从服务器。
Refresh
辅助域名服务器多长时间更新数据库。Refresh 1 到 6 小时。
Retry
若辅助域名服务器更新数据失败,多长时间再试。Retry 20 到 60 分钟。
Expire
若辅助域名服务器无法从主服务器上更新数据,原有的数据何时失效。Expire 1 周 到 1 月。
Minimum
设置被缓存的否定回答的存活时间。Minimum 1 到 3 小时。
缓存时间字段 Refresh、Retry、Expire、Minimum 可以使用时间单位字符m、h、d、w分别表示分钟、小时、天、星期。
resp_person
区域管理员邮箱
primary_ns
区域主节点机器名
【Linux】基于Bind_DLZ和MySQL数据的DNS搭建的更多相关文章
- Centos8 部署 ElasticSearch 集群并搭建 ELK,基于Logstash同步MySQL数据到ElasticSearch
Centos8安装Docker 1.更新一下yum [root@VM-24-9-centos ~]# yum -y update 2.安装containerd.io # centos8默认使用podm ...
- Linux高级命令及mysql数据安装
Linux系列--高级命令--mysql数据库安装 数据库是用来组织.存储和管理数据的仓库 1.安装数据库:执行命令yum -y install mysql -server 2.启动数据库:安装完毕, ...
- linux下插入的mysql数据乱码问题及第三方工具显示乱码问题
一.lampp环境下的数据库乱码问题 问题描述: 在做mysql练习的时候发现新创建的数据库中插入数据表中的记录中文出现乱码的问题,如下图: 经过多方查证,整里如下文挡: 前提: 我自己的环境是使用的 ...
- linux 命令行对mysql数据进行备份和还原
一.备份 1.进入mysql目录 cd /var/lib/mysql (进入mysql目录,根据安装情况会有差别) 2.备份 mysqldump -u root -p密码 数据库名 数据表名 > ...
- 架构实战项目心得(十一):基于spring-security-oauth2的mysql数据表设计
一.建立数据库及数据表结构 CREATE SCHEMA IF NOT EXISTS `oauth2` DEFAULT CHARACTER SET utf8 ; USE `oauth2` ; -- -- ...
- linux 安装 Logtash 同步mysql数据到Elasticsearch
官网下载Logtash 离线安装包 下载地址 https://www.elastic.co/cn/downloads/logstash 需要注意版本与es 对应 新建配置文件 新建文件夹 mkdir ...
- 基于PHP以及Mysql,使用WordPress搭建站点
1.前提环境是PHP以及Mysql以及安装配置完成,Nginx服务启动: 2.配置Mysql的初始密码:mysql安装后,默认root密码是空的,所以要设置密码: mysql -u root mys ...
- linux 下 jdk+tomcat+mysql 的 jsp 环境搭建
JDK 在 linux 下安装 1. 把安装文件放在 /opt 下,并执行 [root@localhost opt]# ./jdk-1_5_0_06-linux-i586.bin 并 ...
- 【转】美团 MySQL 数据实时同步到 Hive 的架构与实践
文章转载自公众号 美团技术团队 , 作者 萌萌 背景 在数据仓库建模中,未经任何加工处理的原始业务层数据,我们称之为ODS(Operational Data Store)数据.在互联网企业中,常见的 ...
随机推荐
- 单点登录filter根据redis中的key判断是否退出
package com.ailk.biapp.ci.localization.cntv.filter; import java.io.IOException; import java.util.Has ...
- [Offer收割]编程练习赛4 A 满减优惠
满减优惠 描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的 ...
- python实现字体闪图
!/usr/bin/env python from future import print_function import os.path import sys from optparse impor ...
- Axis2/c 知识点
官网文档: http://axis.apache.org/axis2/c/core/docs/axis2c_manual.html 从文档中可以总结出: 1. Axis2/C是一个用C语言实现的We ...
- Spring MVC 中文乱码的解决
对于POST方法提交的中文乱码 , 可在web.xml中添加如下代码 : <filter> <filter-name>encodingFilter</filter-nam ...
- Java Cookie和Session(转载)
一.cookie机制和session机制的区别 具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案. 同时我们也看到,由于才服务器端保持状态的 ...
- Salted Password Hashing
Here are some examples of poor wacky hash functions I've seen suggested in forums on the internet. m ...
- MYSQL C API : mysql_real_query()
enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, MYSQ ...
- Python 描述符(descriptor) 杂记
转自:https://blog.tonyseek.com/post/notes-about-python-descriptor/ Python 引入的“描述符”(descriptor)语法特性真的很黄 ...
- (easy)LeetCode 205.Isomorphic Strings (*)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...