LoginSignup
10
12

More than 5 years have passed since last update.

CentOS7 - PowerDNS構築手順

Posted at

概要

PowerDNSの構築手順です
キャッシュサーバ➡️コンテンツサーバ➡️google DNSを見に行くように設定する

サーバ

Master : 192.168.1.1
Slave : 192.168.1.2

インストール手順

※全てroot作業で実施してください

PowerDNSのインストール

[root作業]
### DNSの向先を自分自身だけにする
### IPは変えてください
$ vim /etc/resolv.conf
nameserver 192.168.1.1

### インストール
$ yum install -y boost boost-devel
$ yum -y install epel-release
$ rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ yum -y update
$ yum -y install pdns pdns-backend-mysql pdns-recursor pdns-tools mariadb-server bind-utils wget php php-cli php-pdo php-mysql php-mcrypt 

### mariadbの再起動
$ systemctl restart mariadb
$ systemctl enable mariadb

$ mysql -uroot
### DB作成
MariaDB [(none)]> CREATE DATABASE powerdns CHARACTER SET utf8;

### ユーザ作成、権限設定
MariaDB [(none)]> CREATE USER 'powerdns'@'%' IDENTIFIED BY 'password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON powerdns.* TO 'powerdns'@'%' IDENTIFIED BY 'password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON powerdns.* TO 'powerdns'@'localhost' IDENTIFIED BY 'password';

### テーブル作成
MariaDB [(none)]> use powerdns
MariaDB [(none)]> 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;
MariaDB [(none)]> CREATE UNIQUE INDEX name_index ON domains(name);
MariaDB [(none)]> 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,
  disabled              TINYINT(1) DEFAULT 0,
  ordername             VARCHAR(255) BINARY DEFAULT NULL,
  auth                  TINYINT(1) DEFAULT 1,
  PRIMARY KEY (id)
) Engine=InnoDB;
MariaDB [(none)]> CREATE INDEX nametype_index ON records(name,type);
MariaDB [(none)]> CREATE INDEX domain_id ON records(domain_id);
MariaDB [(none)]> CREATE INDEX recordorder ON records (domain_id, ordername);
MariaDB [(none)]> CREATE TABLE supermasters (
  ip                    VARCHAR(64) NOT NULL,
  nameserver            VARCHAR(255) NOT NULL,
  account               VARCHAR(40) NOT NULL,
  PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;
MariaDB [(none)]> CREATE TABLE comments (
  id                    INT AUTO_INCREMENT,
  domain_id             INT NOT NULL,
  name                  VARCHAR(255) NOT NULL,
  type                  VARCHAR(10) NOT NULL,
  modified_at           INT NOT NULL,
  account               VARCHAR(40) NOT NULL,
  comment               VARCHAR(64000) NOT NULL,
  PRIMARY KEY (id)
) Engine=InnoDB;
MariaDB [(none)]> CREATE INDEX comments_domain_id_idx ON comments (domain_id);
MariaDB [(none)]> CREATE INDEX comments_name_type_idx ON comments (name, type);
MariaDB [(none)]> CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
MariaDB [(none)]> CREATE TABLE domainmetadata (
  id                    INT AUTO_INCREMENT,
  domain_id             INT NOT NULL,
  kind                  VARCHAR(32),
  content               TEXT,
  PRIMARY KEY (id)
) Engine=InnoDB;
MariaDB [(none)]> CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);
MariaDB [(none)]> CREATE TABLE cryptokeys (
  id                    INT AUTO_INCREMENT,
  domain_id             INT NOT NULL,
  flags                 INT NOT NULL,
  active                BOOL,
  content               TEXT,
  PRIMARY KEY(id)
) Engine=InnoDB;
MariaDB [(none)]> CREATE INDEX domainidindex ON cryptokeys(domain_id);
MariaDB [(none)]> CREATE TABLE tsigkeys (
  id                    INT AUTO_INCREMENT,
  name                  VARCHAR(255),
  algorithm             VARCHAR(50),
  secret                VARCHAR(255),
  PRIMARY KEY (id)
) Engine=InnoDB;
MariaDB [(none)]> CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm); 

キャッシュサーバ、コンテンツサーバの設定(MasterとSlaveで設定値が違います)

Master
### コンテンツサーバの設定
### IP部分は変えてください
$ vim /etc/pdns/pdns.conf
setuid=pdns
setgid=pdns
allow-axfr-ips=127.0.0.1,10.0.0.0/8,172.16.0.0/8,192.168.0.0/16
allow-recursion=127.0.0.1,10.0.0.0/8,172.16.0.0/8,192.168.0.0/16
local-address=127.0.0.1
local-port=53
recursor=8.8.8.8
disable-axfr=no
guardian=yes
daemon=yes

# 再帰問い合わせのキャッシュ時間
recursive-cache-ttl=10
launch=gmysql
gmysql-socket=/var/lib/mysql/mysqld.sock
gmysql-host=127.0.0.1
gmysql-user=powerdns
gmysql-password=password
gmysql-dbname=powerdns

# log設定
log-dns-details=on
loglevel=3
logging-facility=0

# master slave設定
master=yes
slave=no

# APIの設定
experimental-json-interface=yes
experimental-api-key=hogehoge # これがAPIのキーになります
webserver=yes
webserver-allow-from=127.0.0.0/8,10.0.0.0/8,172.0.0.0/8,192.168.0.0/16
webserver-address=0.0.0.0
webserver-port=8081

### キャッシュサーバの設定 
$ vim /etc/pdns-recursor/recursor.conf
setuid=pdns-recursor
setgid=pdns-recursor

local-port=53

allow-from=127.0.0.1,10.0.0.0/8,172.16.0.0/8,192.168.0.0/16
forward-zones-recurse=.=127.0.0.1
local-address=192.168.1.1
max-negative-ttl=3600


### 再起動。/var/log/messageも同時に出力してみましょう
$ tail -f /var/log/message
$ service pdns-recursor restart
$ service pdns restart
$ systemctl enable pdns-recursor
$ systemctl enable pdns 

### digしてみましょう
$ dig @127.0.0.1
;; SERVER: 127.0.0.1#53(127.0.0.1)  # こいつが出力されてること
Slave
### コンテンツサーバの設定
### IP部分は変えてください
$ vim /etc/pdns/pdns.conf
setuid=pdns
setgid=pdns
allow-axfr-ips=127.0.0.1,10.0.0.0/8,172.16.0.0/8,192.168.0.0/16
allow-recursion=127.0.0.1,10.0.0.0/8,172.16.0.0/8,192.168.0.0/16
local-address=127.0.0.1
local-port=53
recursor=8.8.8.8
disable-axfr=no
guardian=yes
daemon=yes

# 再帰問い合わせのキャッシュ時間
recursive-cache-ttl=10
launch=gmysql
gmysql-socket=/var/lib/mysql/mysqld.sock
gmysql-host=127.0.0.1
gmysql-user=powerdns
gmysql-password=password
gmysql-dbname=powerdns

# log設定
log-dns-details=on
loglevel=3
logging-facility=0

# master slave設定
master=no
slave=yes
slave-cycle-interval=60

# APIの設定
experimental-json-interface=yes
experimental-api-key=hogehoge # これがAPIのキーになります
webserver=yes
webserver-allow-from=127.0.0.0/8,10.0.0.0/8,172.0.0.0/8,192.168.0.0/16
webserver-address=0.0.0.0
webserver-port=8081

### キャッシュサーバの設定 
$ vim /etc/pdns-recursor/recursor.conf
setuid=pdns-recursor
setgid=pdns-recursor

local-port=53

allow-from=127.0.0.1,10.0.0.0/8,172.16.0.0/8,192.168.0.0/16
forward-zones-recurse=.=127.0.0.1
local-address=192.168.1.2
max-negative-ttl=3600


### 再起動。/var/log/messageも同時に出力してみましょう
$ tail -f /var/log/message
$ service pdns-recursor restart
$ service pdns restart
$ systemctl enable pdns-recursor
$ systemctl enable pdns 

### digしてみましょう
$ dig @127.0.0.1
;; SERVER: 127.0.0.1#53(127.0.0.1)  # こいつが出力されてること
powerdnsのlogを/var/log/messageから/var/log/pdns.logに変更するため、rsyslogの設定

$ vim /etc/rsyslog.conf
*.info;mail.none;authpriv.none;cron.none;local0.none                /var/log/messages
local0.*                                                /var/log/pdns.log

$ systemctl restart rsyslog
$ systemctl enable rsyslog

iptables, firewalldの停止、apacheの停止、php-fpmのインストール、nginxのインストール

### firewalldの停止。セキュアにするなら53ポートだけ開けるとか。
$ systemctl stop firewalld.service
$ systemctl disable firewalld.service

### iptablesの停止
$ systemctl stop iptables.service
$ systemctl disable iptables.service

### apacheの停止
$ systemctl stop apache.service
$ systemctl disable apache.service

### php-fpmのインストール
$ yum install -y php-fpm
$ vim /etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php-fpm.socket # これに変更する

$ systemctl restart php-fpm
$ systemctl enable php-fpm

### nginxのインストール
$ vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

$ yum -y --enablerepo=nginx install nginx
$ vim /etc/nginx/conf.d/default.conf
server {
    listen 80;
    root   /var/www/poweradmin;
    index index.php;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_keep_conn on;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.socket;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

$ service nginx restart
$ systemctl enable nginx

## GUIツールのpoweradminをインストール

```bash
[root作業]
### ダウンロード
$ cd /tmp
$ wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz

### 解凍
$ tar zxvf poweradmin-2.1.7.tgz

### 移動
$ mv poweradmin-2.1.7 /home/websites/poweradmin

### 事前にconfig.inc.phpがないとダメだったので作る
$ cp -p /var/www/poweradmin/inc/config-me.inc.php /var/www/poweradmin/inc/config.inc.php

### 所有者をnginx:nginxにする
$ chown -R nginx:nginx /var/www/poweradmin


### GUI操作でconfig.inc.phpを設定するため、777にする
$ chmod -R 777 /var/www/poweradmin

GUI画面からの設定

# http://192.168.1.1/install/  にアクセス
# ステップ1

日本語で続ける
次へ

# ステップ2
エンコードをEUCにすれば日本語になるよ!
次へ

# ステップ3
ユーザ名:powerdns
パスワード:password
データベースタイプ:mysql
ホスト名:localhost
DBポート:3306
データベース:powerdns
poweradmin管理者用のパスワード:password
次へ

# ステップ4
ユーザ名:powerdns
パスワード:password
ホストマスター:hogehoge.jp
プライマリネームサーバ:example1.com
セカンダリネームサーバ:example2.com
次へ

# ステップ5
次へ

# ステップ7
次へ

poweradmin/installを削除する

$ rm -rf /var/www/poweradmin/install

slaveのみ スーパーマスターの設定

masterがどれか教えてあげましょう

  • http://192.168.1.2 にアクセス
  • ➡️スーパーマスターを追加
  • ➡️IPにmasterのIP、NSに自身のNSを設定し追加
  • 追加後、$ systemctl restart pdns

/etc/hostsと/etc/resolv.confを登録します

$ vim /etc/hosts
192.168.1.1 example1.com
192.168.1.2 example2.com

$ vim /etc/resolv.conf
nameserver 192.168.1.1
nameserver 192.168.1.2

事後確認&作業

  • GUI(http://192.168.1.1/) でアクセスできることを確認してください。

    • admin、passwordで接続してください
    • 何かmasterでドメインを追加して確認しましょう
    • http://192.168.1.1 にアクセス

      • ➡️マスターゾーンを追加
      • ➡️ゾーン名に"test.com" でゾーン追加
      • ➡️ゾーン一覧
      • ➡️test.comの左側の編集アイコンをクリック
      • ➡️下記のように追加
      • スクリーンショット 2015-07-29 14.27.14.png
      • ➡️DNSサーバ上で、下記コマンドで確認
### 全体的にエラーログが出てないか確認
# pdns
$ systemctl restart pdns

# pdns-recursor
$ systemctl restart pdns-resucrf

### masterにゾーンが登録されたか
$ dig @example1.com test.com axfr

### slaveにゾーンが登録されたか
$ dig @example2.com test.com axfr
10
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
12