|

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

  1. Update the system packages:
   apt update && apt upgrade -y
  1. Reconfigure the system timezone:
   dpkg-reconfigure tzdata
  1. Install the MariaDB server:
   apt install mariadb-server -y
  1. Secure the MariaDB installation:
   mysql_secure_installation

Create a MySQL Database and User for PowerDNS

  1. Generate a random password for the PowerDNS database user:
   export DB_PW=$(date +%s | sha256sum | base64 | head -c 12) && echo $DB_PW
  1. 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"
  1. Verify the database creation:
   mysqlshow pdns

Disable systemd-resolved and Configure Custom DNS

  1. Disable the systemd-resolved service:
   systemctl disable --now systemd-resolved
  1. 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.
  1. Override the default resolv.conf file and add Google DNS:
     echo "nameserver 8.8.8.8" > /etc/resolv.conf

Install and Configure PowerDNS

  1. Install the PowerDNS server and MySQL backend:
   apt install pdns-server pdns-backend-mysql -y
  1. Import the PowerDNS MySQL schema:
   mysql pdns < /usr/share/pdns-backend-mysql/schema/schema.mysql.sql
  1. 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
  1. 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
  1. Stop the PowerDNS service:
   systemctl stop pdns
  1. 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
  1. Start the PowerDNS service:
   systemctl start pdns
  1. Verify the PowerDNS service status:
   systemctl status pdns

You should see the PowerDNS service running.

  1. 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

  1. 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
  1. Restart the MariaDB service:
   systemctl restart mariadb

Set Up the New Slave Node

On the master node:

  1. Get the current master status:
   mysql -e "SHOW MASTER STATUS\G"

Remember the “File” and “Position” values.

  1. Lock the tables:
   mysql pdns -e "FLUSH TABLES WITH READ LOCK;"
  1. Dump the pdns database:
   mysqldump pdns > /tmp/pdns.sql

On the new slave node:

  1. Copy the database dump from the master:
   scp -P 9922 tunneluser@xxx.xxx.xxx.xxx:/tmp/pdns.sql /tmp
  1. Import the database dump:
   mysql pdns < /tmp/pdns.sql
  1. 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
  1. 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:

  1. 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.

Similar Posts