其他
新特性解读 | InnoDB-Cluster 扫盲-日常运维
作者:杨涛涛
资深数据库专家,专研 MySQL 十余年。擅长 MySQL、PostgreSQL、MongoDB 等开源数据库相关的备份恢复、SQL 调优、监控运维、高可用架构设计等。目前任职于爱可生,为各大运营商及银行金融企业提供 MySQL 相关技术支持、MySQL 相关课程培训等工作。
节点 A:192.168.2.210:3601(主节点)
节点 B:192.168.2.210:3602(从节点)
节点 C:192.168.2.210:3603(从节点)
MySQL debian-ytt1:3601 ssl Py > c1 = dba.get_cluster();
MySQL debian-ytt1:3601 ssl Py > c1
<Cluster:ytt_mgr
用来获取集群目前状态,输出极简结果。
输出集群节点拓扑图,集群各个节点 IP 地址等。
MySQL debian-ytt1:3601 ssl Py > c1.describe()
{
"clusterName": "ytt_mgr",
"defaultReplicaSet": {
"name": "default",
"topology": [
{
"address": "127.0.0.1:3601",
"label": "127.0.0.1:3601",
"role": "HA"
},
{
"address": "127.0.0.1:3602",
"label": "127.0.0.1:3602",
"role": "HA"
},
{
"address": "127.0.0.1:3603",
"label": "127.0.0.1:3603",
"role": "HA"
}
],
"topologyMode": "Single-Primary"
}
}
MySQL debian-ytt1:3601 ssl Py > c1.list_routers()
{
"clusterName": "ytt_mgr",
"routers": {
"debian-ytt1::system": {
"hostname": "debian-ytt1",
"lastCheckIn": "2020-07-15 11:43:18",
"roPort": 6447,
"roXPort": 64470,
"rwPort": 6446,
"rwXPort": 64460,
"version": "8.0.21"
}
}
}
5、options 方法
7、set_primary_instance 方法
MySQL debian-ytt1:3601 ssl Py > c1.status().get("defaultReplicaSet").get("topology")
{
"node_a": {
"address": "127.0.0.1:3601",
"mode": "R/O",
"readReplicas": {},
"replicationLag": null,
"role": "HA",
"status": "ONLINE",
"version": "8.0.21"
},
"node_b": {
"address": "127.0.0.1:3602",
"mode": "R/W",
"readReplicas": {},
"replicationLag": null,
"role": "HA",
"status": "ONLINE",
"version": "8.0.21"
},
"node_c": {
"address": "127.0.0.1:3603",
"mode": "R/O",
"readReplicas": {},
"replicationLag": null,
"role": "HA",
"status": "ONLINE",
"version": "8.0.21"
}
}
root@debian-ytt1:/home/ytt# mysql -uroot -proot -P6446 -hdebian-ytt1 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
| 3602 |
+--------+
MySQL debian-ytt1:3601 ssl Py > c1.switch_to_multi_primary_mode()
Switching cluster 'ytt_mgr_sandbox' to Multi-Primary mode...
Instance '127.0.0.1:3601' was switched from SECONDARY to PRIMARY.
Instance '127.0.0.1:3602' remains PRIMARY.
Instance '127.0.0.1:3603' was switched from SECONDARY to PRIMARY.
The cluster successfully switched to Multi-Primary mode.
9、switch_to_single_primary_mode 方法
0:禁止打印详细信息(默认)
1:打印集群元数据相关信息,集群组协议的版本,成员等简单的信息。
2:打印集群重放线程的相关事务执行信息。
3:打印集群内每个节点所属详细的信息。
11、dissolve() 方法
MySQL debian-ytt1:3601 ssl Py > c1.dissolve()
...
Are you sure you want to dissolve the cluster? [y/N]: y
Instance '127.0.0.1:3602' is attempting to leave the cluster...
Instance '127.0.0.1:3603' is attempting to leave the cluster...
Instance '127.0.0.1:3601' is attempting to leave the cluster...
The cluster was successfully dissolved.
Replication was disabled but user data was left intact.
总结
MySQL InnoDB Cluster 是一款非常好用的管理 MySQL 组复制的套件,熟悉它的使用方法会极大的简化我们对组复制的日常管理。
相关文章推荐:
社区近期动态