NacosSync User Manual

Manual Objectives

  • Understanding NacosSync components
  • Start the NacosSync service
  • Through a simple example, we demonstrate how to migrate the Dubbo client registered with Zookeeper to Nacos.

introduce

  • NacosSync is a synchronization component that supports multiple registration centers. It is based on the Spring boot development framework. The data layer uses Spring Data JPA. It follows the standard JPA access specification and supports multiple data source storage. It is implemented by default using Hibernate and supports tables more conveniently. Automatically create updates for
  • It uses an efficient event asynchronous driver model and supports a variety of custom events, so that the delay of synchronization task processing is controlled at 3s. A single machine of 8C16G can support 6K synchronization tasks.
  • In addition to stand-alone deployment, NacosSync also provides a high-availability cluster deployment mode. NacosSync is a stateless design and migrates task and other status data to the database, making cluster expansion very convenient.
  • The core interface of the Sync component is abstracted, and synchronization types are distinguished through annotations, allowing developers to easily expand different registration centers according to their own needs. Currently supported synchronization types:
    • Synchronize Nacos data to Nacos
    • Synchronize Zookeeper data to Nacos
    • Synchronize Nacos data to Zookeeper
    • Eureka data synchronization to Nacos
    • Synchronize Consul data to Nacos

System structure:

image.png


Console
Provides a streamlined Web operation console and supports internationalization:

### Synchronization task management page ![](https://img.alicdn.com/tfs/TB1eSYyJ5LaK1RjSZFxXXamPFXa-2866-1064.png)### Registration center management page## ![image.png](https://img.alicdn.com/tfs/TB1e_rdJ7voK1RjSZFNXXcxMVXa-2876-1124.png)## Usage scenarios: * Service sharing between multiple network-connected Regions, breaking the service call restrictions between Regions

image.png

  • Two-way synchronization function supports the smooth migration of Dubbo+Zookeeper service to Dubbo+Nacos and enjoys better services from Nacos

image.png

manual

Preparation work

Before starting the service, you need to install the following services:

Get the installation package

There are two ways to obtain the NacosSync installation package:

  • Download the binary installation package of NacosSync directly:nacosSync.${version}.zip
  • Download the source code of NacosSync from GitHub and build it

Package:

cd nacosSync/
mvn clean package -U

Path to target file:

nacos-sync/nacossync-distribution/target/nacosSync.${version}.zip

After unzipping the installation package, the file directory structure of the project is:

nacosSync
├── LICENSE
├── NOTICE
├── bin
│   ├── nacosSync.sql
│   ├── shutdown.sh
│   └── startup.sh
├── conf
│   ├── application.properties
│   └── logback-spring.xml
├── logs
└── nacosSync-server.${version}.jar

Initialize database

The default database configured by the system is Mysql, and other relational databases can also be supported. 1. Create a database. The default database name is "nacos_Sync". 2. Database tables do not need to be created separately, hibernate's automatic table creation function is used by default. 3. If your environment does not support automatic table creation, you can use the sql script that comes with the system to create the table. The script is placed in the bin directory.

Database configuration

The configuration file of the database is placed inconf/application.properties:

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/nacos_sync?characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root

Start the server

$ nacosSync/bin:
sh startup.sh  restart

Check system status

1. Check system logs

The path of the log isnacosSync/logs/nacosSync.log, check whether there is any abnormal information.

2. Check the system port

The default system port is8081, you can define it yourself in application.properties.

$netstat -ano|grep 8081
tcp        0      0 0.0.0.0:8081                0.0.0.0:*                   LISTEN      off (0.00/0/0)

Waiting table

Access path:

http://127.0.0.1:8081/#/serviceSync

image.png

If there is no problem, NacosSync has started normally. The deployment structure of NacosSync:

image.png

Start transfer

Transfer Information

Deployment information of Dubbo service:

image.png

Migrated services:

Service Name Version Group Name
com.alibaba.nacos.api.DemoService 1.0.0 zk

Add registration center cluster information

1. Click the "Cluster Configuration" button in the left navigation bar to add a new cluster. First add a Zookeeper cluster and select the cluster type as ZK.

image.png

Note: The cluster name can be customized, but once confirmed, it cannot be modified. Otherwise, the tasks added based on this cluster will not be restored successfully after NacosSync is restarted.

2. Follow the same steps to add a NacosSync cluster.

image.png

3. After the addition is completed, you can query it in the list:

image.png

Add synchronization task

1. Add a synchronization task to synchronize from the Zookeeper cluster to the Nacos cluster. The granularity of synchronization is service. The Zookeeper cluster is called the source cluster, and the Nacos cluster is called the target cluster.

imagesd.png

After the addition is completed, you can view the added synchronization tasks in the service synchronization list:

image.png

2. After the synchronization is completed, check whether the data has been successfully synchronized to the Nacos cluster. You can query it through the Nacos console.

image.png

3. At this moment, the data has been successfully synchronized from the Zookeeper cluster to the Nacos cluster. The deployment structure is as follows:

image.png

Dubbo client connects to Nacos registration center

Dubbo Consumer client migration

Dubbo already supports the Nacos registration center. The supported version is 2.5+. You need to add a Dubbo extension plug-in dependency of the Nacos registration center:

<dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>dubbo-registry-nacos</artifactId>
            <version>0.0.2</version>
</dependency>

Add dependencies on Nacos client:

<dependency>
        <groupId>com.alibaba.nacos</groupId>
        <artifactId>nacos-client</artifactId>
        <version>0.6.2</version>
</dependency>

Configure Dubbo Consumer's Dubbo configuration fileconsumer.yaml so that the client can find the Nacos cluster.

spring:
  application:
name: dubbo-consumer
demo:
  service:
    version: 1.0.0
    group: zk
dubbo:
  registry:
    address: nacos://127.0.0.1:8848

There is no need to modify the code. After the configuration is updated, you can restart your application to make it effective.

After the Consumer release is completed, the current deployment structure is as follows:

image.png

Dubbo Provider迁移

Before upgrading the Provider, you need to ensure that the services published by the Provider have been configured in NacosSync. The synchronization method is from Nacos to Zookeeper. Because after the Provider is upgraded and connected to Nacos, you need to ensure that the old Dubbo Consumer client can run in Zookeeper. Subscribe to the Provider's address. Now, we add a synchronization task:

image.png

image.png

Note: The Nacos service is synchronized to Zookeeper. There is no need to fill in the version number. When you select the source cluster, the input box for the version number will be automatically hidden.

After the synchronization task is completed, you can upgrade the Provider. For how to upgrade the Provider, refer to the steps for upgrading the Consumer.

New deployment structure

  • During the upgrade process, new and old versions of the client will exist at the same time. The deployment structure is as follows:

image.png

  • After all client migrations are completed, the deployment structure is as follows:

image.png

Now, the Zookeeper cluster and NacosSync cluster can be taken offline.

Notes

  • After adding the synchronization task, you need to ensure whether the service is successfully synchronized to the target cluster. You can query it through the console of the target cluster.
  • NacosSync supports high-availability cluster mode deployment, you only need to configure the same database.
  • If you can't sort out the subscription and publishing services, it is recommended to synchronize the services in two directions.
  • The Dubbo client currently does not support the weight function of Nacos. If you use the weight function, you need to reconsider whether the solution is appropriate.

Original text from: Nacos official website 

Guess you like

Origin blog.csdn.net/leesinbad/article/details/134757393