暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

AntDB 数据库集中式运维手册-常用管理操作3

tocata 2024-09-02
218

主备切换

数据库在运行过程中,数据库管理员可能需要手工对数据库节点做主备切换。例如发现数据库节点主备 failover 后需要恢复原有的主备角色,或怀疑硬件故障需要手动进行主备切换。可以通过 switchover 或 failover,手动实现主备切换。

操作步骤

非故障切换:使用命令 adbhamgrctl -c /etc/adbhamgr.yml switchover 进行手动切换主备。

[antdb@host-10-19-28-129 ~]$ adbhamgrctl -c /etc/adbhamgr.yml switchover
Master [adbhamgr-02]: adbhamgr-02                                            #输入当前主节点
Candidate ['adbhamgr-01', 'adbhamgr-03'] []: adbhamgr-01                     #输入当前同步备节点(Sync Standby)
When should the switchover take place (e.g. 2022-12-27T12:14 )  [now]:
Current cluster topology
+ Cluster: antdb-cluster (7348278630800196973) ---+---------+-----+-----------+
| Member      | Host               | Role         | State   |  TL | Lag in MB |
+-------------+--------------------+--------------+---------+-----+-----------+
| adbhamgr-01 | 10.19.28.129:55551 | Sync Standby | running | 465 |         0 |
| adbhamgr-02 | 10.19.36.206:55551 | Leader       | running | 465 |           |
| adbhamgr-03 | 10.19.36.207:55551 | Replica      | running | 465 |         0 |
+-------------+--------------------+--------------+---------+-----+-----------+
Are you sure you want to switchover cluster antdb-cluster, demoting current master adbhamgr-02? [y/N]: y

#查看主备切换结果:
[antdb@host-10-19-28-129 ~]$ adbhamgrctl -c /etc/adbhamgr.yml list
+ Cluster: antdb-cluster (7348278630800196973) ---+----------+-----+-----------+
| Member      | Host               | Role         |  State   | TL  | Lag in MB |
+-------------+--------------------+--------------+----------+-----+-----------+
| adbhamgr-01 | 10.19.28.129:55551 | Sync Standby | running  | 465 |         0 |
| adbhamgr-02 | 10.19.36.206:55551 | Leader       | stopping |     |           |
| adbhamgr-03 | 10.19.36.207:55551 | Replica      | running  | 465 |         0 |
+-------------+--------------------+--------------+----------+-----+-----------+

#Leader由adbhamgr-02切换到了adbhamgr-01
[antdb@host-10-19-28-129 ~]$ adbhamgrctl -c /etc/adbhamgr.yml list
+ Cluster: antdb-cluster (7348278630800196973) ---+---------+-----+-----------+
| Member      | Host               | Role         | State   |  TL | Lag in MB |
+-------------+--------------------+--------------+---------+-----+-----------+
| adbhamgr-01 | 10.19.28.129:55551 | Leader       | running | 466 |           |
| adbhamgr-02 | 10.19.36.206:55551 | Replica      | running | 466 |         0 |
| adbhamgr-03 | 10.19.36.207:55551 | Sync Standby | running | 466 |         0 |
+-------------+--------------------+--------------+---------+-----+-----------+

故障切换:使用命令 adbhamgrctl -c /etc/adbhamgr.yml failover 进行手动切换主备。

[antdb@host-10-19-28-129 ~]$ adbhamgrctl -c /etc/adbhamgr.yml failover
Candidate ['adbhamgr-02', 'adbhamgr-03'] []: adbhamgr-03            #输入当前同步备节点(Sync Standby)              
Current cluster topology
+ Cluster: antdb-cluster (7348278630800196973) ---+---------+-----+-----------+
| Member      | Host               | Role         | State   |  TL | Lag in MB |
+-------------+--------------------+--------------+---------+-----+-----------+
| adbhamgr-01 | 10.19.28.129:55551 | Leader       | running | 466 |           |
| adbhamgr-02 | 10.19.36.206:55551 | Replica      | running | 466 |         0 |
| adbhamgr-03 | 10.19.36.207:55551 | Sync Standby | running | 466 |         0 |
+-------------+--------------------+--------------+---------+-----+-----------+
Are you sure you want to failover cluster antdb-cluster, demoting current master adbhamgr-01? [y/N]: y

#查看主备切换结果:
[antdb@host-10-19-28-129 ~]$ adbhamgrctl -c /etc/adbhamgr.yml list
+ Cluster: antdb-cluster (7348278630800196973) ---+----------+-----+-----------+
|  Member     | Host               | Role         | State    |  TL | Lag in MB |
+-------------+--------------------+--------------+----------+-----+-----------+
| adbhamgr-01 | 10.19.28.129:55551 | Leader       | stopping |     |           |
| adbhamgr-02 | 10.19.36.206:55551 | Replica      | running  | 466 |         0 |
| adbhamgr-03 | 10.19.36.207:55551 | Sync Standby | running  | 466 |         0 |
+-------------+--------------------+--------------+----------+-----+-----------+
[antdb@host-10-19-28-129 ~]$ adbhamgrctl -c /etc/adbhamgr.yml list
+ Cluster: antdb-cluster (7348278630800196973) ---+---------+-----+-----------+
|  Member     | Host               | Role         | State   | TL  | Lag in MB |
+-------------+--------------------+--------------+---------+-----+-----------+
| adbhamgr-01 | 10.19.28.129:55551 | Replica      | stopped |     |   unknown |
| adbhamgr-02 | 10.19.36.206:55551 | Sync Standby | running | 467 |         0 |
| adbhamgr-03 | 10.19.36.207:55551 | Leader       | running | 467 |           |
+-------------+--------------------+--------------+---------+-----+-----------+

#Leader由adbhamgr-01切换到了adbhamgr-03
[antdb@host-10-19-28-129 ~]$ adbhamgrctl -c /etc/adbhamgr.yml list
+ Cluster: antdb-cluster (7348278630800196973) ---+---------+-----+-----------+
|  Member     | Host               | Role         | State   | TL  | Lag in MB |
+-------------+--------------------+--------------+---------+-----+-----------+
| adbhamgr-01 | 10.19.28.29:55551  | Replica      | running | 467 |         0 |
| adbhamgr-02 | 10.19.36.206:55551 | Sync Standby | running | 467 |         0 |
| adbhamgr-03 | 10.19.36.207:55551 | Leader       | running | 467 |           |
+-------------+--------------------+--------------+---------+-----+-----------+
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论