CentOS7 に PowerDNS をインストールする手順をメモしておきます。バックエンドには MariaDB を使いました。
MariaDB をインストールする
MariaDB は epel リポジトリにあるので、先に epel リポジトリを追加します。
yum -y install epel-release
MariaDB をインストールします。
yum -y install mariadb mariadb-server
MariaDB を起動しつつ、自動起動するように設定しておきます。
systemctl enable mariadb.service
systemctl start mariadb.service
mysql_secure_installation で MariaDB を初期設定します。
mysql_secure_installation
実行例は以下の通りです。
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): (初期パスワードは空なので、そのまま ENTER)
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] (ENTER)
New password: (root パスワードを入力)
Re-enter new password: (確認用に root パスワードを再入力)
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] (ENTER)
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] (ENTER)
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] (ENTER)
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] (ENTER)
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
PowerDNS のインストール
PowerDNS をインストールします。
yum -y install pdns pdns-backend-mysql pdns-tools
次は PowerDNS 用のデータベースを作成します。予め、データベース作成用の .sql ファイルをダウンロードしておきます。
curl -O https://raw.githubusercontent.com/sig9org/powerdns-create-db/master/create-database.sql
MariaDB にログインします。root ユーザのパスワードを聞かれるので、mysql_secure_installation で設定した root ユーザの新パスワードを入力し、MariaDB にログインします。
mysql -u root -p
PowerDNS 用のデータベースとユーザを作成します。今回は以下のパラメータとしました。データベースとユーザの作成が完了したら SOURCE で .sql ファイルを流し込み、PowerDNS 用のテーブルを作成します。
項目 | 値 |
---|---|
データベース名 | powerdns |
ユーザ名 | powerdns |
パスワード | password |
具体的には以下のように実行します。
CREATE DATABASE powerdns;
GRANT ALL ON powerdns.* TO 'powerdns'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
SOURCE create-database.sql
exit
設定ファイルの修正
PowerDNS の設定ファイルを以下の内容で修正します。設定ファイルは /etc/pdns/pdns.conf にあります。
setuid=pdns
setgid=pdns
launch=gmysql
gmysql-host=localhost
gmysql-user=powerdns
gmysql-password=password
gmysql-dbname=powerdns
gmysql-dnssec=yes
loglevel=10
log-dns-queries=1
recursor=8.8.8.8
allow-recursion=0.0.0.0/0
log-dns-details=on
loglevel=3
logging-facility=0
PowerDNS の起動
PowerDNS を起動し、自動起動の設定も済ませておきます。
systemctl enable pdns.service
systemctl start pdns.service
動作テスト
nslookup や dig で正しく名前解決出来ていることを確認しておきます。
nslookup での動作テスト
# nslookup time1.google.com 127.0.0.1
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: time1.google.com
Address: 216.239.35.0
dig での動作テスト
# dig time1.google.com @127.0.0.1
; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3 <<>> time1.google.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43328
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;time1.google.com. IN A
;; ANSWER SECTION:
time1.google.com. 3589 IN A 216.239.35.0
;; Query time: 7 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Dec 29 11:20:42 JST 2016
;; MSG SIZE rcvd: 61
参考
create-database.sql の内容
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,
disabled TINYINT(1) DEFAULT 0,
ordername VARCHAR(255) BINARY DEFAULT NULL,
auth TINYINT(1) DEFAULT 1,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
CREATE INDEX recordorder ON records (domain_id, ordername);
CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) NOT NULL,
PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;
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;
CREATE INDEX comments_domain_id_idx ON comments (domain_id);
CREATE INDEX comments_name_type_idx ON comments (name, type);
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
CREATE TABLE domainmetadata (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
kind VARCHAR(32),
content TEXT,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);
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;
CREATE INDEX domainidindex ON cryptokeys(domain_id);
CREATE TABLE tsigkeys (
id INT AUTO_INCREMENT,
name VARCHAR(255),
algorithm VARCHAR(50),
secret VARCHAR(255),
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
コメント