环境
- 当前有 6 个运行中的 powerdns 服务器
- 当前具有一个 master, 五个 slave 角色
- 由于需要回收 master 机器
目的
需要把其中一台 powerdns 服务器切换至 master
把其他 powerdns 服务器指向新的 master 服务器
机器环境
主机名 | IP | 原角色 | 新角色 | pdns 版本 | 备注 |
---|---|---|---|---|---|
fc-master.vc.com | xx.xxx.129.22 | master | remove | 3.4.4 | |
fc-slave.vc.com | xx.xxx.129.21 | slave | remove | 3.4.4 | |
sh-master.vc.com | xx.xxx.129.23 | slave | slave | 3.4.4 | |
sh-slave.vc.com | xx.xxx.128.23 | slave | slave | 3.4.4 | |
ns-master.vc.com | xx.xxx.208.22 | slave | master | 4.1.0 | |
ns-slave.vc.com | xx.xxx.208.21 | slave | slave | 4.1.0 |
操作步骤
- 对原 master 执行数据库锁表操作
- 对 ns-master.vc.com 启用 master 功能
- 对其他 slave 执行主服务器映射修改
- 可以对原 master fc-master.vc.com 进行下线操作
- 测试
老 MASTER 操作
锁表
目的
为了防止在操作过程中, 有其他程序对 DNS 进行写入丢失数据
flush table with read lock;
启用新 master 服务器
目的
对 ns-master.vc.com 执行操作
为了允许其他服务器向其进行数据请求
修改 /etc/pdns/pdns.conf 配置文件
api=yes
api-key=openstack
api-logfile=/var/log/pdns.log
cache-ttl=20
daemon=yes
default-ttl=30
guardian=no
launch=gmysql
gmysql-host=127.0.0.1
gmysql-port=3306
gmysql-user=mysqlusername
gmysql-dbname=mysqldbname
gmysql-password=mypassword
local-address=xx.xxx.208.22
local-port=5300
master=yes <--- 修改
setgid=pdns
setuid=pdns
webserver=yes
webserver-address=0.0.0.0
webserver-allow-from=0.0.0.0/0
webserver-port=8081
write-pid=yes
allow-axfr-ips=xx.xxx.128.23,xx.xxx.129.23,xx.xxx.129.22,xx.xxx.129.21,xx.xxx.208.21,xx.xxx.208.22
also-notify=xx.xxx.128.23,xx.xxx.129.23,xx.xxx.129.22,xx.xxx.129.21,xx.xxx.208.21,xx.xxx.208.22
only-notify=xx.xxx.128.23,xx.xxx.129.23,xx.xxx.129.22,xx.xxx.129.21,xx.xxx.208.21,xx.xxx.208.22
slave=no <--- 修改
slave-cycle-interval=60
重启服务
systemctl restart pdns
修改数据库, 令所有域成为 MASTER
MariaDB [pdns]> update domains set master = null, type='MASTER';
Query OK, 20 rows affected (0.00 sec)
Rows matched: 20 Changed: 20 Warnings: 0
MariaDB [pdns]> select * from domains;
+----+---------------------+--------+------------+--------+-----------------+---------+
| id | name | master | last_check | type | notified_serial | account |
+----+---------------------+--------+------------+--------+-----------------+---------+
| 1 | 189.10.in-addr.arpa | NULL | 1521634981 | MASTER | NULL | NULL |
| 2 | 198.10.in-addr.arpa | NULL | 1521634861 | MASTER | NULL | NULL |
| 3 | 199.10.in-addr.arpa | NULL | 1521634861 | MASTER | NULL | NULL |
| 4 | 30.240.in-addr.arpa | NULL | 1521634801 | MASTER | NULL | NULL |
| 5 | 60.240.in-addr.arpa | NULL | 1521634981 | MASTER | NULL | NULL |
| 6 | centos.org | NULL | 1521634921 | MASTER | NULL | NULL |
| 7 | ceph.com | NULL | 1521634981 | MASTER | NULL | NULL |
| 8 | cobblerd.org | NULL | 1521634981 | MASTER | NULL | NULL |
| 9 | dev.oranger.com | NULL | 1521634801 | MASTER | NULL | NULL |
| 10 | fedorapeople.org | NULL | 1521634861 | MASTER | NULL | NULL |
| 11 | fedoraproject.org | NULL | 1521634981 | MASTER | NULL | NULL |
| 12 | gluster.org | NULL | 1521634981 | MASTER | NULL | NULL |
| 13 | opensuse.org | NULL | 1521634981 | MASTER | NULL | NULL |
| 14 | puppetlabs.com | NULL | 1521634921 | MASTER | NULL | NULL |
| 15 | qa.oranger.com | NULL | 1521634861 | MASTER | NULL | NULL |
| 16 | redhatopenstack.com | NULL | 1521634861 | MASTER | NULL | NULL |
| 17 | sh.oranger.com | NULL | 1521634861 | MASTER | NULL | NULL |
| 18 | theforeman.org | NULL | 1521634921 | MASTER | NULL | NULL |
| 19 | ustc.edu.cn | NULL | 1521634861 | MASTER | NULL | NULL |
| 20 | oranger.com | NULL | 1521634861 | MASTER | NULL | NULL |
+----+---------------------+--------+------------+--------+-----------------+---------+
20 rows in set (0.00 sec)
备注
上面操作已成功令其成为新 MASTER 服务器
已经满足外部程序对新 MASTER 服务器执行 DNS 增删改操作
外部程序修改(略)
其他 DNS 服务器修改(包含老 MASTER)
解锁旧 master 数据库
unlock tables;
对所有从服务器执行相应数据库修改则可
use pdns;
update master set master='x.x.x.x:5300', type='SLAVE';
这里 x.x.x.x 指向新 master ip 地址
参考
如上图所示
本地 53 端口 用于 pdns-resursor 服务, 主要用于数据转发
本地 5300 端口由 pdns-server 进程管理, 主要用于负责本地域名解析客户请求 ustc.edu.cn 域名
53 端口 (pdns-rescursor) 应答, 并根据规则转发至 pdns-server (5300端口) 进行解析
pdns-server 把数据返回到 pdns-recursor 并返回用户对于其他 PDNS slave 服务器需要向 MASTER 进行数据同步
则 PDNS SLAVE 需要直接指向 MASTER:5300 端口由 pdns-server 响应