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

Creating an InnoDB ReplicaSet

原创 忘忧草 2022-08-17
224

Once you have configured your instances, create an InnoDB ReplicaSet by completing the following steps:

Connect to an instance and use dba.createReplicaSet() to create a managed ReplicaSet that uses MySQL asynchronous replication, rather than MySQL Group Replication used by InnoDB Cluster. The MySQL instance, which MySQL Shell is connected to, is used as the initial primary of the ReplicaSet.

The dba.createReplicaSet() operation performs several checks to ensure that the instance state and configuration are compatible with a managed ReplicaSet, and if so, a metadata schema is initialized on the instance.

If the ReplicaSet is created successfully, a ReplicaSet object is returned. Therefore, it is best practice to assign the returned ReplicaSet to a variable. This enables you to work with the ReplicaSet, for example by calling the status() operation. To create a ReplicaSet named example on instance rs-1 and assign it to the rs variable, issue:

mysql-js> \connect root@rs-1:3306

mysql-js> var rs = dba.createReplicaSet(“example”)
A new replicaset with instance ‘rs-1:3306’ will be created.

  • Checking MySQL instance at rs-1:3306

This instance reports its own address as rs-1:3306
rs-1:3306: Instance configuration is suitable.

  • Updating metadata…

ReplicaSet object successfully created for rs-1:3306.
Use rs.add_instance() to add more asynchronously replicated instances to this replicaset
and rs.status() to check its status.
Use the returned ReplicaSet object to verify that the operation was successful. For example, this provides the ReplicaSet.status() operation, which displays information about the ReplicaSet. The returned ReplicaSet is already assigned to the variable rs, so issue:

mysql-js> rs.status()
{
“replicaSet”: {
“name”: “example”,
“primary”: “rs-1:3306”,
“status”: “AVAILABLE”,
“statusText”: “All instances available.”,
“topology”: {
“rs-1:3306”: {
“address”: “rs-1:3306”,
“instanceRole”: “PRIMARY”,
“mode”: “R/W”,
“status”: “ONLINE”
}
},
“type”: “ASYNC”
}
}
This output shows that the ReplicaSet named example has been created, and that the primary is rs-1. Currently, there is only one instance, and the next task is to add more instances to the ReplicaSet.

InnoDB ReplicaSet replicationAllowedHost
When creating an InnoDB ReplicaSet using MySQL Shell 8.0.28 and later, if you have security requirements that want all accounts created automatically by AdminAPI to have strict authentication requirements, you can set a value for the replicationAllowedHost configuration option of the ReplicaSet. The replicationAllowedHost MySQL Shell option allows you to set internally managed replication accounts for a ReplicaSet to a strict subnet based filter instead of the default wildcard value of %.The replicationAllowedHost option can take a string value. For example, to set the replicationAllowedHost to 192.0.2.0/24, issue:

mysql-js> var rs = dba.createReplicaSet(‘example’, {replicationAllowedHost:‘192.0.2.0/24’})
A new replicaset with instance ‘rs-1:3306’ will be created.

  • Checking MySQL instance at rs-1:3306

This instance reports its own address as rs-1:3306
rs-1:3306: Instance configuration is suitable.

  • Updating metadata…

ReplicaSet object successfully created for rs-1:3306.
Use rs.addInstance() to add more asynchronously replicated instances to this replicaset and rs.status() to check its status.
An InnoDB ReplicaSet can be modified after creation to set the variable replicationAllowedHost through the setOption configuration option, by issuing:

mysql-js> rs.setOption(‘replicationAllowedHost’, ‘192.0.2.0/24’)

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论