You can use MSE Sync to synchronize all service data from a Consul instance to a Microservices Engine (MSE) Nacos instance by performing simple configurations. During the migration, service dependencies are replaced, and application configurations are repackaged. This topic describes how to migrate service data from a Consul instance to an MSE Nacos instance.
Prerequisites
A Nacos engine is created. For more information, see Create a Nacos engine.
MSE Sync is deployed. For more information, see Migration solution based on MSE Sync.
Procedure
Start MSE Sync and import configurations of the source and destination instances to MSE Sync by using a configuration file.
Create a configuration file that contains the following content:
clusters: - clusterName: dst connectKeyList: - {nacos.endpoint}:8848 clusterType: NACOS - clusterName: src connectKeyList: - {consul.endpoint}:8500 clusterType: CONSUL tasks: - source: src destination: dstReplace
{nacos.endpoint}in the configuration file with the endpoint of the MSE Nacos instance. For example, replace {nacos.endpoint} withmse-zzzzz-.nacos-ans.mse.aliyuncs.com.Replace
{consul.endpoint}in the configuration file with the IP address of the Consul instance. For example, replace {consul.endpoint} with10.0.0.1.
Import the configuration file into MSE Sync. After the import, MSE Sync periodically scans new services in the source and destination instances and automatically creates tasks to synchronize service data.
View the number of completed synchronization tasks and check whether all service data is synchronized.
Replace the client dependency and modify configurations.
Replace the client dependency. Replace the Consul SDK with the Nacos SDK.
For Spring Cloud applications, replace
spring-cloud-starter-consul-discoverywithspring-cloud-starter-alibaba-nacos-discoverythat is compatible with Spring Cloud.Modify configurations. Modify the configuration file to configure the MSE Nacos instance as the registry.
In this example, the configuration of the Consul instance is replaced with the configuration of the MSE Nacos instance. The annotation shows the original configuration.
server: port: 9999 spring: application: name: sp-provider cloud: nacos: discovery: server-addr: mse-xxxxx-nacos-ans.mse.aliyuncs.com:8848 # consul: # host: 11.164.x.x # port: 8500 # config: # enabled: false # discovery: # health-check-path: /health
Repackage and release applications.
Check whether applications are normally started and called, and check whether applications are registered with the MSE Nacos instance in the MSE console.
MSE Sync periodically scans information about the Consul instance and synchronizes information updates. You can adjust the interval at which the instance information is updated by specifying consul.refresh.interval. The default value is 5 seconds.
FAQ
Service data in the Consul instance is not synchronized to the MSE Nacos instance. Why?
Check whether the service in Consul passes the health check. MSE Sync synchronizes only data of healthy instances.
References
For more information about MSE Sync and other instance types that are supported by MSE Sync, see Migration solution based on MSE Sync.