Using VMware Tanzu SQL with MySQL for VMs for Multi-Site Replication
Note: In v2.9 and later, MySQL for VMware Tanzu is named VMware Tanzu SQL with MySQL for VMs.
Page last updated:
This topic provides instructions for developers using the VMware Tanzu SQL with MySQL for VMs for replication across multiple foundations or data centers.
Overview
In Tanzu SQL for VMs v2.7.4 and later, you provision a leader-follower service instance across two foundations using the Multi‑Site Replication topology. This leader-follower service instance is comprised of two single node instances that are configured for replication.
Note: The Multi‑Site Replication plan type is configured separately from the leader-follower service plan.
For more information about the Multi‑Site Replication topology, see About Multi‑Site Replication.
Prerequisites
Before you use Tanzu SQL for VMs across multiple foundations, you must have:
- Access to the Multi‑Site Replication plan. Your operator configures this plan and enables access to it in your org and space.
- Selected two foundations to deploy your Multi‑Site Replication leader and follower VMs. Your operators must configure these foundations for multi‑site replication. For more information configuring a Multi‑Site Replication topology, see Preparing for Multi‑Site Replication.
Create a Multi‑Site Replication Leader-Follower Service Instance
To create a leader-follower service across multiple foundations:
- Check the availability of the Multi‑Site Replication plan in the Marketplace in both your foundations. See Confirm the VMware Tanzu SQL with MySQL for VMs Service Availability.
- Create one Multi‑Site Replication service instance on each foundation. See Create Multi‑Site Replication Service Instances, below.
- Enable replication between the Multi‑Site Replication service instances. See Configure Multi‑Site Replication, below.
- Bind the Multi‑Site Replication leader-follower service instance to your apps. See Bind a Multi‑Site Replication Leader-Follower Service Instance to Your App, below.
- Modify your app to use the Tanzu SQL for VMs service. See Use the MySQL Service in Your App.
After you create a Multi‑Site Replication leader-follower service instance, you can manage it over the life cycle of your apps and data. For instructions on how to manage a Tanzu SQL for VMs service instance, see Manage Service Instances.
Create Multi‑Site Replication Service Instances
To create a leader-follower service instance across two foundations, you must create one Multi‑Site Replication service instance in each foundation. You must configure the service instances in each foundation for replication.
Note: In the below procedure, the primary foundation is the foundation that your leader VM is deployed to. The secondary foundation is the foundation that the follower VM is deployed to, and usually is your disaster recovery site.
To create a multi-site replication service instance in both foundations:
Create a Multi‑Site Replication service instance in your primary foundation:
Log in to the deployment for your primary foundation by running:
cf login PRIMARY-API-URL
Where
PRIMARY-API-URL
is the API endpoint for the primary foundation.Create a primary service instance by running:
cf create-service p.mysql PLAN PRIMARY-INSTANCE
Where:
PLAN
is the name of the Multi‑Site Replication plan you want to use.PRIMARY-INSTANCE
is a name you choose to identify the service instance. This name appears underservice
in output fromcf services
.
For example:
$ cf create-service p.mysql db-small primary-node
Creating service primary-node in org my-org / space my-space as admin... OKNote: Do not name your service instance
leader
orfollower
. If you trigger a failover or switchover, the service instances in your primary and secondary foundations switch roles. For more information, see Triggering Multi-Site Replication Failover and Switchover.(Optional) Watch the progress of the service instance creation by running:
watch cf services
Wait for the
last operation
for your instance to show ascreate succeeded
.
For example:$ watch cf services
Getting services in org my-org / space my-space as admin... OK name service plan bound apps last operation primary-node p.mysql db-small create succeededIf you get an error, see Troubleshooting Instances.
Create a Multi‑Site Replication service instance in your secondary foundation by repeating step 1 and replacing references to
primary
withsecondary
. Ensure that you log in to deployment for your secondary foundation.
Configure Multi‑Site Replication
After you create the Multi‑Site Replication service instance in primary and secondary foundations, you must configure replication between the two service instances.
You configure replication using service keys to pass connection information between the leader and follower VMs. You must not use these service keys for any other use case besides establishing multi‑site replication.
Workflow for Configuring Multi‑Site Replication
The following diagram describes the workflow for configuring multi‑site replication:
The steps shown in the diagram are as follows:
- Create host-info service key.
- Record host-info service key.
- Update secondary service instance with host-info service key.
- Create credentials service key.
- Record credentials service key.
- Update primary service instance with credentials service key.
Procedure for Configuring Multi‑Site Replication
Note: The below procedure assumes you created the leader service instance in the primary foundation and the follower service instance in the secondary foundation. You created these service instances in Create Multi‑Site Replication Service Instances above.
To configure replication for your Multi‑Site Replication leader-follower service instance:
Create a host-info service key for the service instance in your secondary foundation by running:
cf create-service-key SECONDARY-INSTANCE SERVICE-KEY \ -c '{"replication-request": "host-info"}'
Where:
SECONDARY-INSTANCE
is the name of the secondary service instance you created in step 2 of Create Multi‑Site Replication Service Instances, above.SERVICE-KEY
is a name you choose for the host-info service key.
For example:$ cf create-service-key secondary-node host-info \ -c '{"replication-request": "host-info" }'
Creating service key host-info for service instance secondary-node as admin... OK
View the
replication-credentials
for your host-info service key by running:cf service-key SECONDARY-INSTANCE SERVICE-KEY
Where:
SECONDARY-INSTANCE
is the name of the secondary service instance you created in step 2 of Create Multi‑Site Replication Service Instances, above.SERVICE-KEY
is the name of the host-info service key you created in step 1, above.
For example:
$ cf service-key secondary-node host-info-key
Getting key host-info-key for service instance secondary-node as admin... { "replication": { "peer-info": { "hostname": "secondary.bosh", "ip": "10.0.19.12", "system_domain": "sys.secondary-domain.com", "uuid": "ab12cd34-5678-91e2-345f-67891h234567" }, "role": "leader" } }Record the output of the above command.
Log in to the deployment for your primary foundation by running:
cf login PRIMARY-API-URL
Update your primary service instance with the host-info service key by running:
cf update-service PRIMARY-INSTANCE -c HOST-INFO
Where:
PRIMARY-INSTANCE
is the name of the primary service instance you created in step 1 of Create Multi‑Site Replication Service Instances, above.HOST-INFO
is the output you recorded in step 3, above.
For example:
$ cf update-service primary-node -c '{"replication":{ \ "peer-info":{ \ "hostname": "secondary.bosh", \ "ip": "10.0.18.12", \ "system_domain": "sys.secondary-domain.com", \ "uuid": "ab12cd34-5678-91e2-345f-67891h234567" \ },\ "role": "leader" \ } \ }'
Updating service instance primary-node as admin... OKWatch the progress of the service instance by running:
watch cf services
Wait for the
last operation
for your instance to show asupdate succeeded
.
For example:$ watch cf services
Getting services in org my-org / space my-space as admin... OK name service plan bound apps last operation primary-node p.mysql db-small update succeededIf you get an error, see Troubleshooting Instances.
Create a credentials service key for the service instance in your primary foundation by running:
cf create-service-key PRIMARY-INSTANCE SERVICE-KEY-NAME \ -c '{"replication-request": "credentials"}'
Where:
PRIMARY-INSTANCE
is the name of the primary service instance you created in step 1 of Create Multi‑Site Replication Service Instances, above.SERVICE-KEY-NAME
is a name you choose for the credentials service key.
For example:$ cf create-service-key primary-node cred-key \ -c '{"replication-request": "credentials" }'
Creating service key cred-key for service instance primary-node as admin... OKNote: The
-c
flag is different than the one in step 1.
View the
replication-credentials
for your credentials service key by running:cf service-key PRIMARY-INSTANCE SERVICE-KEY-NAME
Where:
PRIMARY-INSTANCE
is the name of the primary service instance you created in step 1 of Create Multi‑Site Replication Service Instances, above.SERVICE-KEY-NAME
is the name of the credentials service key you created in step 6, above.
For example:
$ cf service-key primary-node cred-key
Getting key cred-key for service instance primary as admin... { "replication": { "credentials": { "password": "a22aaa2a2a2aaaaa", "username": "6bf07ae455a14064a9073cec8696366c" }, "peer-info": { "hostname": "primary.bosh", "ip": "10.0.17.12", "system_domain": "sys.primary-domain.com", "uuid": "zy98xw76-5432-19v8-765u-43219t876543" }, "role": "follower" } }Record the output of the above command.
Log in to the deployment for your secondary foundation by running:
cf login SECONDARY-API-URL
Update your secondary service instance with the credentials service key by running:
cf update-service SECONDARY-INSTANCE -c CREDENTIALS
Where:
SECONDARY-INSTANCE
is name of the secondary service instance you created in step 2 of Create Multi‑Site Replication Service Instances, above.CREDENTIALS
is the output you recorded in step 8, above.
For example:
$ cf update-service secondary-node -c '{"replication": { \ "credentials": { \ "password": "a22aaa2a2a2aaaaa", \ "username": "6bf07ae455a14064a9073cec8696366c" \ }, \ "peer-info": { \ "hostname": "primary.bosh", \ "ip": "10.0.17.12", \ "system_domain": "sys.primary-domain.com", \ "uuid": "zy98xw76-5432-19v8-765u-43219t876543" \ }, \ "role": "follower" \ } \ }'
Updating service instance primary-node as admin... OK
You should now have a Multi‑Site Replication leader-follower service instance that is fully configured and has replication enabled.
Bind a Multi‑Site Replication Leader-Follower Service Instance to Your App
For an app to use a Multi‑Site Replication leader-follower service instance, you must bind your app to your primary service instance in your primary foundation. If you want to use an active-active topology, you must additionally bind your app to the secondary service instance in your secondary foundation.
For information about active-passive and app-layer active-active topologies, see see About Active-Passive Topology and About App-Layer Active-Active Topology.
To bind an app to a leader-follower service instance:
Log in to the deployment for your primary foundation by running:
cf login PRIMARY-API-URL
Bind your app to your primary service instance by doing the procedure in Bind a Service Instance to Your App.
(Optional) If you are using an active-active topology, you must bind the same app to your secondary service instance in your secondary foundation. To do this, repeat the above steps and replace references to
primary
withsecondary
.Modify your app to use the Tanzu SQL for VMs service by doing the procedure in Use the MySQL Service in Your App.