海运的博客

PowerDNS使用

发布时间:February 1, 2014 // 分类:DNS // No Comments

使用EPEL源可直接安装:

yum install pdns pdns-backend-mysql

添加MySQL数据库:

create database powerdns;
grant all privileges on powerdns.* to 'powerdns'@'localhost' identified by 'password';
use powerdns;
create table domains (
 id              INT auto_increment,
 name            VARCHAR(255) NOT NULL,
 master          VARCHAR(128) DEFAULT NULL,
 last_check      INT DEFAULT NULL,
 type            VARCHAR(6) NOT NULL,
 notified_serial INT DEFAULT NULL, 
 account         VARCHAR(40) DEFAULT NULL,
 primary key (id)
) Engine=InnoDB;

CREATE UNIQUE INDEX name_index ON domains(name);

CREATE TABLE records (
  id              INT auto_increment,
  domain_id       INT DEFAULT NULL,
  name            VARCHAR(255) DEFAULT NULL,
  type            VARCHAR(10) DEFAULT NULL,
  content         VARCHAR(64000) DEFAULT NULL,
  ttl             INT DEFAULT NULL,
  prio            INT DEFAULT NULL,
  change_date     INT DEFAULT NULL,
  primary key(id)
) Engine=InnoDB;

CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);

create table supermasters (
  ip         VARCHAR(64) NOT NULL, 
  nameserver VARCHAR(255) NOT NULL, 
  account    VARCHAR(40) DEFAULT NULL,
  PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;

将SQL信息添加到PowerDNS配置文件:

launch=gmysql
gmysql-host=localhost
gmysql-user=powerdns
gmysql-password=password
gmysql-dbname=powerdns

添加域名记录:

INSERT INTO domains (name, type) values ('example.com', 'NATIVE');
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values 
 (1,'example.com','SOA','localhost root@example.com 1',86400,NULL,NULL);
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values
 (1,'example.com','NS','ns.example.com',86400,NULL,NULL);
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values
 (1,'example.com','A','192.0.2.10',120,NULL,NULL);
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values
 (1,'*.example.com','A','192.0.2.10',120,NULL,NULL);
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values
 (1,'ns.example.com','A','192.0.2.10',120,NULL,NULL);

看看效果:

/etc/init.d/pdns monitor

PHP:

<?php
   try { 
      $dbo = new PDO('mysql:host=localhost;dbname=powerdns', 'powerdns', 'password');
   } catch (PDOException $e) { 
      $error = $e->getMessage();
      die("PDO Execute Error : ".$error."\n");       
   }
   $domain = 'www.haiyun.me';
   $sql = "SELECT `id` FROM domains WHERE NAME = \"$domain\"";
   $stmt = $dbo->query($sql);
   //var_dump($stmt);
   $result = $stmt->fetch(PDO::FETCH_ASSOC);
   var_dump($result);
   if ($result) {
      $id = $result['id'];
   } else {
      $sql = "INSERT INTO domains (name, TYPE) VALUES (\"$domain\", 'NATIVE')";
      $dbo->query($sql);
      $id = $dbo->lastInsertId();
   }
   $sql = "INSERT INTO `records` (`domain_id`, `name`, `TYPE`, `content`, `ttl`) VALUES (:id, :name, :type, :content, :ttl)";
   $stmt = $dbo->prepare($sql);    
   $stmt->execute(array(':id'=>$id, ':name'=>'a.'.$domain, ':type'=>'A', ':content'=>'192.168.1.1', ':ttl'=>'600')); 
   $stmt->execute(array(':id'=>$id, ':name'=>'b.'.$domain, ':type'=>'A', ':content'=>'192.168.1.1', ':ttl'=>'600')); 
?>

标签:dns

评论已关闭

分类
最新文章
最近回复
  • 海运: 正常情况下编译整个内核执行make menuconfig后就不会出现此提示,当单独编译单个模块...
  • oijq: 就是用的armbian的配置文件哈,按你的教程做的,在执行make LOCALVERSION=...
  • 海运: 使用armbian的配置文件,其它添加或修改自己懂的部分,不懂的就不要碰了。
  • oijq: 编译时这些选项全部选Y吗?Actions Semi Platforms (ARCH_ACTIO...
  • 海运: n1编译bbr内核模块参考这个:https://www.haiyun.me/archives/...
  • jiqz: make M=net/ipv4/ CONFIG_TCP_CONG_BBR=m modules编...
  • ruralhunter: 哦,文档里应该是对的,是.config
  • ruralhunter: cp /mnt/boot/config-4.18.7-aml-s9xxx .config这里应...
  • 海运: 你是编译不成功呢?还是编译后不能运行呢?还是运行后不能访问web界面呢?
  • 白墨: 可能不清楚就是编译安装后启动后访问不了web界面