Centos7.8+bind9+mysql+智能DNS配置详解

配置智能DNS解析流程如下:

一、配置web环境

1、先安装LAMP环境.

wget http://soft.vpser.net/lnmp/lnmp1.7.tar.gz -cO lnmp1.7.tar.gz && tar zxf lnmp1.7.tar.gz && cd lnmp1.7 && ./install.sh lamp

上述安装LAMP完成,mysql账号:root 密码:111111

二、下载安装bind-dlz

1、先下载并解压bind9

wget http://ftp.isc.org/isc/bind9/9.11.0-P2/bind-9.11.0-P2.tar.gz
tar -zxvf bind-9.11.0-P2.tar.gz

2、在64位系统上编译,您可能需要设置一些变量,以便找到适当的mysql库:

[root@localhost ~]# export CPPFLAGS="-I/usr/lib64/mysql $CPPFLAGS"
[root@localhost ~]# export LDFLAGS="-L/usr/lib64/mysql $LDFLAGS"
[root@localhost ~]# export LD_LIBRARY_PATH="/usr/lib64/mysql"

3、安装编译bind-dlz

[root@localhost opt]# cd bind-9.11.0-P2
[root@localhost bind-9.11.0-P2]#./configure --prefix=/usr/local/bind  --enable-threads=no \
--enable-largefile --disable-ipv6 \
--disable-openssl-version-check \
--with-dlz-mysql=yes
[root@localhost bind-9.11.0-P2]# make
[root@localhost bind-9.11.0-P2]# make install

4、查看版本并测试软件是否安装成功

[root@localhost bind-9.11.0-P2]# /usr/local/bind/sbin/named -v
BIND 9.11.0-P2 <id:9713922>

5、配置rndc.conf和named.conf文件

cd /usr/local/bind/sbin/

./rndc-confgen -r /dev/urandom > /usr/local/bind/etc/rndc.conf

tail -n10 rndc.conf | head -n9 | sed -e s/#\//g>named.conf

cd /usr/local/bind/etc/

提供根文件

../bin/dig > ./named.root

配置 named.conf

vim named.conf

内容如下:

key "rndc-key" {
	algorithm hmac-md5;
	secret "tHC+lhXIsWmGCYK41jmmDw==";
};

controls {
	inet 127.0.0.1 port 953
		allow { 127.0.0.1; } keys { "rndc-key"; };
};

logging {
        channel bind_log {
                file "/tmp/bind.log" versions 3 size 20m;
                severity info;
                print-time yes;
                print-severity yes;
                print-category yes;
        };
        category default {
                bind_log;

        };
 };

options {
        listen-on port 53 { 192.168.30.132; };
        directory "/usr/local/bind";
        Pid-file "named.pid";
        forwarders{ 127.0.0.1; };
        allow-query-cache { any; };
        allow-query     { any; };
};

dlz "Mysql zone" {
    database "mysql
    {host=127.0.0.1 dbname=bind ssl=false port=3306 user=root pass=111111}
    {select zone from dns_records where zone = '$zone$' and  view = 'any' limit 1}
    {select ttl,type,if(mx_priority>0,mx_priority,NULL),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 view = 'any'}";
};

6、创建named用户,使bind服务以named用户运行

[root@localhost ~]#groupadd -r -g 25 named
[root@localhost ~]#useradd -r -u 25 -s /bin/nologin -d /usr/local/named -g named named
[root@localhost ~]#chown -R named:named /usr/local/bind/

7、前台启动named服务,看看配置是否正常.

[root@localhost ~]#/usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf -f -g -u named

8、在/etc/resolv.conf 文件中添加本机192.168.30.132为第一dns解析地址:

[root@localhost ~]# vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.30.132
nameserver 192.168.153.2

9、登录MySQL,并创建库、表和测试数据.

mysql -h127.0.0.1 -uroot -p111111
mysql> create database bind;

Query OK, 1 row affected (0.00 sec)

mysql> use bind;
Database changed

> CREATE TABLE IF NOT EXISTS `dns_records` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `zone` varchar(255) NOT NULL,
  `host` varchar(255) NOT NULL DEFAULT '@',
  `type` enum('A','MX','CNAME','NS','SOA','PTR','TXT','AAAA','SVR','URL') NOT NULL,
  `data` varchar(255) DEFAULT NULL,
  `ttl` int(11) NOT NULL DEFAULT '3600',
  `mx_priority` int(11) DEFAULT NULL,
  `view`  enum('any', 'Telecom', 'Unicom', 'CMCC', 'ours') NOT NULL  DEFAULT "any" ,
  `priority` tinyint UNSIGNED NOT NULL DEFAULT '255',
  `refresh` int(11) NOT NULL DEFAULT '28800',
  `retry` int(11) NOT NULL DEFAULT '14400',
  `expire` int(11) NOT NULL DEFAULT '86400',
  `minimum` int(11) NOT NULL DEFAULT '86400',
  `serial` bigint(20) NOT NULL DEFAULT '2015050917',
  `resp_person` varchar(64) NOT NULL DEFAULT 'ddns.net',
  `primary_ns` varchar(64) NOT NULL DEFAULT 'ns.ddns.net.',
  PRIMARY KEY (`id`),
  KEY `type` (`type`),
  KEY `host` (`host`),
  KEY `zone` (`zone`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;


Query OK, 0 rows affected (0.02 sec)

数据库中插入数据:

mysql> insert into bind.dns_records (zone, host, type, data, ttl) VALUES ('testinfo.com', 'www', 'A', '192.168.30.132', '600');
Query OK, 1 row affected (0.00 sec)

mysql> insert into bind.dns_records (zone, host, type, data, ttl) VALUES ('testinfo.com', 'bbs', 'A', '192.168.30.132', '600');
Query OK, 1 row affected (0.00 sec)

mysql> insert into bind.dns_records (zone, host, type, data, ttl) VALUES ('testinfo.com', 'm', 'A', '192.168.30.132', '600');
Query OK, 1 row affected (0.00 sec)

10、后台启动named服务:

/usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf -f -g -u named &

11、.解析测试:本地添加的test.info.com域名通过192.168.30.132解析

[root@localhost ~]# nslookup
> www.testinfo.com
Server:         192.168.30.132
Address:        192.168.30.2#53

Name:   www.testinfo.com
Address: 192.168.30.132

12、配置智能解析面板,下载web面板放到目录

插入面板数据库信息:

CREATE TABLE `admin` ( 
  `admin_id` int(10) unsigned NOT NULL auto_increment, 
   `admin_username` varchar(30) NOT NULL, 
   `admin_password` varchar(100) NOT NULL default '', 
   `admin_realname` varchar(50) default NULL, 
   `admin_active` varchar(50) default 1,
   PRIMARY KEY          (`admin_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=gbk;

CREATE TABLE `admin_log` ( 
   `id` int(10) unsigned NOT NULL auto_increment, 
   `admin_id` int(10) unsigned NOT NULL, 
   `admin_login_time` int(11) NOT NULL default '0', 
   `admin_lastlogin_time`  int(11) NOT NULL default '0', 
   `admin_lastlogin_ip` varchar(64) default NULL, 
   `admin_login_count` int(10) default 1,
   PRIMARY KEY          (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=gbk;

alter table admin add email varchar(64) default NULL;
insert into admin(`admin_username`,`admin_password`,`admin_realname`,`admin_active`)values('admin','96e79218965eb72c92a549dd5a330112','123','1');

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值