Migrating PowerDNS (Slave) Server to a New Host
Migrating a PowerDNS slave server with a new IP address can be tricky, so proper preparation is essential.
Update the System and Install Required Packages
- Update the system packages:
apt update && apt upgrade -y
- Reconfigure the system timezone:
dpkg-reconfigure tzdata
- Install the MariaDB server:
apt install mariadb-server -y
- Secure the MariaDB installation:
mysql_secure_installation
Create a MySQL Database and User for PowerDNS
- Generate a random password for the PowerDNS database user:
export DB_PW=$(date +%s | sha256sum | base64 | head -c 12) && echo $DB_PW
- Create the PowerDNS database and user:
mysql -e "CREATE DATABASE pdns" && \
mysql -e "GRANT ALL PRIVILEGES ON pdns.* TO pdns@localhost \
IDENTIFIED BY '$DB_PW'" && mysql -e "FLUSH PRIVILEGES"
- Verify the database creation:
mysqlshow pdns
Disable systemd-resolved and Configure Custom DNS
- Disable the systemd-resolved service:
systemctl disable --now systemd-resolved
- Remove the systemd-resolved service files:
Removed /etc/systemd/system/dbus-org.freedesktop.resolve1.service.
Removed /etc/systemd/system/multi-user.target.wants/systemd-resolved.service.
- Override the default
resolv.conf
file and add Google DNS:
echo "nameserver 8.8.8.8" > /etc/resolv.conf
Install and Configure PowerDNS
- Install the PowerDNS server and MySQL backend:
apt install pdns-server pdns-backend-mysql -y
- Import the PowerDNS MySQL schema:
mysql pdns < /usr/share/pdns-backend-mysql/schema/schema.mysql.sql
- Configure the PowerDNS MySQL connection in
/etc/powerdns/pdns.d/pdns.local.gmysql.conf
:
# Launch gmysql backend
launch+=gmysql
# gmysql parameters
gmysql-host=127.0.0.1
gmysql-port=3306
gmysql-dbname=pdns
gmysql-user=pdns
gmysql-password=OWYxNThlZWZk
gmysql-dnssec=yes
- Update the main PowerDNS configuration file
/etc/powerdns/pdns.conf
:
# Include the configuration directory
include-dir=/etc/powerdns/pdns.d
# Set PowerDNS to run as slave
master=no
slave=yes
- Stop the PowerDNS service:
systemctl stop pdns
- Check the PowerDNS logs for any issues:
Aug 06 10:43:47 gmysql Connection successful. Connected to database 'pdns' on '127.0.0.1'.
Aug 06 10:43:47 gmysql Connection successful. Connected to database 'pdns' on '127.0.0.1'.
Aug 06 10:43:47 gmysql Connection successful. Connected to database 'pdns' on '127.0.0.1'.
Aug 06 10:43:47 Done launching threads, ready to distribute questions
- Start the PowerDNS service:
systemctl start pdns
- Verify the PowerDNS service status:
systemctl status pdns
You should see the PowerDNS service running.
- Ensure PowerDNS is listening on port 53:
ss -alnp4 | grep pdns
You should see the UDP and TCP listeners on port 53.
Configure MariaDB Replication
- Edit the MariaDB configuration file
/etc/mysql/mariadb.conf.d/50-server.cnf
:
bind-address = 127.0.0.1
server-id = 2
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index
expire_logs_days = 10
max_binlog_size = 100M
replicate-do-db = pdns
binlog_format = ROW
- Restart the MariaDB service:
systemctl restart mariadb
Set Up the New Slave Node
On the master node:
- Get the current master status:
mysql -e "SHOW MASTER STATUS\G"
Remember the “File” and “Position” values.
- Lock the tables:
mysql pdns -e "FLUSH TABLES WITH READ LOCK;"
- Dump the
pdns
database:
mysqldump pdns > /tmp/pdns.sql
On the new slave node:
- Copy the database dump from the master:
scp -P 9922 tunneluser@xxx.xxx.xxx.xxx:/tmp/pdns.sql /tmp
- Import the database dump:
mysql pdns < /tmp/pdns.sql
- Configure the new slave:
mysql pdns -e "STOP SLAVE;"
mysql -e "RESET SLAVE;"
mysql -e "CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_USER='pdns-slave', MASTER_PASSWORD='NGY4NDM3MWRi', MASTER_PORT=33061, MASTER_LOG_FILE='mysql-bin.000059', MASTER_LOG_POS=124033;"
systemctl restart mariadb
- Verify the slave status:
mysql -e "SHOW SLAVE STATUS\G"
You should see the slave is running and up-to-date.
On the master node:
- Unlock the tables:
mysql -e "UNLOCK TABLES;"
The migration of the PowerDNS slave server to a new host is now complete. Remember to update any DNS records or client configurations to point to the new slave server’s IP address.