0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Almalinux9.5でPowerDNS Authoritative Server Master/Slave(Primary/Secondary)構成

Last updated at Posted at 2025-02-15

はじめに

Almalinux9 でPowerDNS Authoritative Server Master/Slave(Primary/Secondary)構成で
構築した記事がなかったので、備忘録として記録します。
PowerDNSのバックエンドとして、MariaDB。
WebUIにPoweradminを使用します。インストールも楽で、そこそこ使い勝手が良かったので。

MariaDBは構築済みとします。

現バージョンの確認

公式サイト
https://repo.powerdns.com/
https://www.poweradmin.org/

現バージョンは、4.9です。

インストールの手順は、こちら
https://doc.powerdns.com/authoritative/installation.html
って何も書いてない感じ・・・

インストール

dnf install epel-release &&
curl -o /etc/yum.repos.d/powerdns-auth-49.repo \
https://repo.powerdns.com/repo-files/el-auth-49.repo &&
dnf install -y pdns pdns-backend-mysql

データベース作成

パスワード(paaasword)は、各自設定してください。

# mysql -u root -p
> CREATE DATABASE powerdns CHARACTER SET utf8;
> CREATE USER 'pdns'@'127.0.0.1' IDENTIFIED BY 'password';
CREATE USER 'pdns'@'localhost' IDENTIFIED BY 'password';

> GRANT ALL PRIVILEGES ON powerdns.* TO 'pdns'@'127.0.0.1';
GRANT ALL PRIVILEGES ON powerdns.* TO 'pdns'@'localhost';
> QUIT

データベースをPowerDNS用に初期化します。

この時に使うSQLファイルは"/usr/share/doc/pdns-backend-mysql-"に配置されています
確認したところ、
/usr/share/doc/pdns-backend-mysql/にありました。

 # mysql -h 127.0.0.1 -u pdns -p powerdns < /usr/share/doc/pdns-backend-mysql/schema.mysql.sql

PoweDNS設定

設定ファイル"/etc/pdns/pdns.conf"に接続するデータベースの情報を記述します。他にchroot、ネットワークの制限、WEBサーバ、Master/Slaveゾーンの有効/無効、等々を環境に合わせて設定します。

vi /etc/pdns/pdns.conf
launch=gmysql
gmysql-host=localhost
gmysql-user=pdns
gmysql-password=password
gmysql-dbname=powerdns
webserver=yes
webserver-address=0.0.0.0
webserver-allow-from=0.0.0.0/0

 とりあえずここでは上記のようにしました。

起動

systemctl start pdns
systemctl enable pdns
Lastly, verify the PowerDNS service to ensure that the PowerDNS is running and enabled.
systemctl status pdns

動作確認

情報が表示されれば正常です。

WebUI Poweradminのセットアップ

https://www.poweradmin.org/
https://github.com/poweradmin/poweradmin

apacheは構築済みとします。
必要なモジュールを入れていきます。

dnf install -y php php-intl php-gettext php-pdo php-fpm
dnf install -y php-mysqlnd

Readme 関連を確認します
To get Poweradmin working on your preferred webserver (Apache/NGINX for example), download the source-code from GitHub. Note that Ubuntu has an Apache server by default, so the following NGINX configuration is only needed for Debian or custom installations:
Via Git:
Clone the repository: git clone https://github.com/poweradmin/poweradmin.git
Change directory to the cloned repository: cd poweradmin
Select the latest stable tag (for example v3.8.1): git checkout tags/v3.8.1
Alternatively, you can use the master branch, but it might be unstable as it is used for development: git checkout master
Via releases:
Get the latest file from releases

とあるので

cd /opt
git clone https://github.com/poweradmin/poweradmin.git

ダウンロードしたソフトをコピーします。

mv poweradmin /var/www/html
chown -R apache. /var/www/html/poweradmin

動作確認

PHPのエラーが出たら、PHPのバージョンを上げてください。

インストールをクリックまたは
English(日本語)で続けるを選択
日本語だと環境次第では、エラーになります。

データベースの情報を入力します。

Database type	MySQL
Username	pdns
Password	password
Hostname	localhost
DB Port		3306
Database	powerdns
DB charset 	Use default
DB collation	Use default
Poweradmin administrator password	password

で次へ
こちらでは、ネームサーバーの情報を入力します。
hogehoge.jpは、各自のFQDNに変更してください。

 Step 4: Setup of account and name servers

Now we will gather all details for the configuration itself.
Username	pdns
Password	password
Hostmaster	hostmaster.hogehoge.jp
Primary nameserver	ns.hogehoge.jp
Secondary nameserver
Tertiary Nameserver
Quaternary Nameserver
 Step 5: Create limited-rights user

You now want to give limited rights to Poweradmin so it can update the data in the tables. To do this, you should create a new user and give it rights to select, delete, insert, and update records in the PowerDNS database.

Execute the following commands based on your database:

CREATE USER 'pdns'@'%' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE, DELETE ON powerdns.* TO 'pdns'@'%';

or

CREATE USER 'pdns'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE, DELETE ON powerdns.* TO 'pdns'@'localhost';

次へ

 You should now create the file /var/www/html/poweradmin/inc/config.inc.php in the Poweradmin root directory yourself. It should contain the following few lines:

<?php
$db_host = 'localhost';
$db_name = 'powerdns';
$db_user = 'pdns';
$db_pass = 'password';
$db_type = 'mysql';

$session_key = '*****************************************';

$iface_lang = 'ja_JP';

$dns_hostmaster = 'hostmaster.hogehoge.jp';
$dns_ns1 = 'ns.hogehoge.jp';

上記の通り、/var/www/html/poweradmin/inc/config.inc.phpを編集します。

vi /var/www/html/poweradmin/inc/config.inc.php
~省略~

Step 7: Installation complete

Now we have finished the configuration.

You should (must!) remove the directory "install/" from the Poweradmin root directory. You will not be able to use Poweradmin if it exists. Do it now.

After you have removed the directory, you can login to Poweradmin.

Use the default username "admin" and the password set in step 3.

とあるので、

rm /var/www/html/poweradmin/install

ブラウザーから
http://localhost/poweradmin/

ゾーンを追加して、
Windows端末などよりnslookupなどで動作確認。

BINDから設定をコピーする

現在動いているBIND(ネームサーバー)がある場合は、
設定を変換できます。

/usr/bin/zone2sql

# zone2sql --named-conf=/etc/named.conf --gmysql > zone.sql

作られた情報をインポートします。
ただし、この変換で作られるゾーンは、NATIVEとなってしきいます。
MASTERは、マスター、SLAVEは、スレーブとして変換後に、インポートしてください。
なお、スレーブレコードの内容は不要ですので、合わせて削除します。

# mysql -h 127.0.0.1 -u pdns -p powerdns < zone.sql
systemctl restart pdns

これで、完成かと思われましたが、スレーブの情報が更新されません。

検索してみると、スレーブとして動作させるには、コンフィグファイルにslave=yesの記述が必要との事。
slave=yesを追加して再起動すると、エラーが出ます。
slaveというオプションが無いようです。

マニュアルを確認します。
https://doc.powerdns.com/authoritative/settings.html#setting-secondary

secondary

Changed in version 4.5.0: This was called slave before 4.5.0.
Boolean
Default: no
Turn on operating as a secondary. See Secondary operation.

と言うことで、slaveは廃止されて、secondaryになったようです。
追加します。

vi /etc/pdns/pdns.conf
secondary=yes

systemctl restart pdns

マスターのレコードも正常
スレーブのレコードも正常に更新されました。

なお、AXFRを送信できるようにマスターのBIND設定の変更をお忘れなく。
also-notify {; };
allow-transfer {; };
にスレーブのサーバーIPアドレスを追加
※なぜか、ゾーンファイルが更新されず悩んでいたら、IPアドレスの記述ミスだったという・・・
そんな時は、slaveマシンからdigで調べましょう。

# dig +noall +ans hogehoge.jp @ns.hoge.hoge axfr

ログが見れないので設定します。
systemctl edit --full pdnsにて、書き換える

#systemctl edit --full pdns
ExecStart=/usr/sbin/pdns_server --guardian=no --daemon=no --log-timestamp=yes --write-pid=no

#systemctl restart pdns

syslogの設定を変更します。

vi /etc/rsyslog.conf
local0.*                        /var/log/pdns.log

# systemctl restart rsyslog

ログレベルを調整します。4がベターかも

vi /etc/pdns/pdns.conf
log-dns-details=yes
loglevel=4
log-dns-queries=yes

#systemctl restart pdns

これで、しばらく運用してみます。

おわりに

Almalinux9.5でPowerDNS Authoritative Server Master/Slave(Primary/Secondary)構成で動作できました。
本当は、dnsbl(rbldnsd)を同時に稼働させたかったのですが、
PowerDNS Authoritative Serverでは、実現させる方法が見つからず。PowerDNS Recursorだとできるのかな・・・
お分かりの方、お知らせください。

CentOS7環境を新OSに移行すべく、少しずつお勉強中です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?