Speaking from Nacos open source in 2018

Posted Jun 16, 20209 min read

In the summer of 2018, a new member was ushered in the field of domestic microservices open source. Since then, in the process of building a microservices registration center and configuration center, domestic developers have added a trusted option. Nacos is an open source Alibaba open source dynamic service discovery, configuration management and service management platform that is easier to build cloud-native applications( Official Website ) , It condenses Alibaba s best practices in ultra-large-scale registration and configuration for more than a decade, and can be used in micro-service scenarios as a service registration center, configuration center and other core scenarios, just like other micro-service open source projects in Alibaba. Nacos is also a typical example that started in Ali and grew up in the community. Why open source Nacos? In the field of large-scale service discovery and service governance, the existing open source solutions are not perfect. Alibaba has accumulated a large number of related service registration and services during the evolution from the IOE centralized application architecture to the Internet distributed service architecture. Configuration practical experience, and these experiences can be reused on a large scale in various industries. In addition, more importantly, I hope to develop together with community developers, so that Nacos can help domestic companies more freely build cloud-based applications based on dynamic service discovery, configuration and service management. Compared with other service registration and configuration center open source solutions, Nacos started late, but in addition to the functions of registration and configuration center, he also provides dynamic service discovery, service sharing and management functions, which are available in large-scale scenarios. Better performance, more convenient in ease of use, and more flexible in distributed deployment. For example, compared with Consul/Eureka/Zookeeper:(Contents are extracted from "Analysis and Comparison of Mainstream Microservice Registration Centers" ) NacosConsulEurekaZookeeper consistency Protocol CP+APCPAPCP health check TCP/HTTP/MYSQL/Client BeatTCP/HTTP/gRPC/CmdClient BeatKeep Alive load balancing policy weights/metadata/SelectorFabioRibbon Avalanche protection with or without automatic logout instance support does not support support supports access protocol HTTP/DNSHTTP /DNSHTTPTCP monitoring support support support support support multiple data center support support support do not support cross-registry center synchronization support support do not support do not support SpringCloud integration support support support support Dubbo integration support support do not support support K8S integration support support do not support do not do not want to do it yourself Nacos? Alibaba Cloud Microservice Engine MSE provides Nacos hosting services Alibaba Cloud Microservice Engine(MSE) is a fully managed platform for open source registration and configuration centers, providing high-availability, maintenance-free ZooKeeper, Nacos registration centers and Eureka clusters. It is fully compatible with the standard interface of open source products, without the need to modify the code, out of the box, and provides customers with corresponding monitoring and operation and maintenance tools. Product official website: https://www.aliyun.com/product/mse So, what is the registration center hosted by MSE and the open source self-built registration center? the difference? You can compare the following table. Contrast item Self-built registration center MSE registration center Cost resources cost ECS expenses Support on time/year-on-month basis, approximately equal to the same configuration ECS expenses Manpower cost Need special staff to maintain O&M MSE Provide easy-to-use automation capabilities O&M, low threshold High availability disaster tolerance No support for multiple computer rooms, multi-region disaster recovery and downtime processing, manual processing, automatic detection, automatic recovery activity detection does not support process activity detection, failure automatic recovery function, data management command line page visualization, support for adding, deleting, and changing access methods, machine IP direct connection, The code needs to change the domain name, change the machine, does not need to change the business alarm, does not support core business indicators such as the number of links, multi-dimensional alarm configuration, network mode, local network VPC network, public network service management does not support service providers, subscriber page management, cluster authority management, Support sub-account management, customizable sub-account access rights TPS/QPS statistics does not support TPS, QPS monitoring view operation and maintenance cluster observation without page visualization, view node health status, role monitoring chart does not provide multiple indicators such as Znode, link Several graphical view configuration manual operation and maintenance modification, manual restart page modification, one-click restart effective node scaling, manual expansion and contraction, manual restart page selection, one-key expansion and contraction performance scaling does not support page selection, one-click scaling from understanding to practice How does the Dubbo application ensure seamless migration to MSE without business downtime?

The following uses the Dubbo application built on SpringBoot as an example to introduce how to perform the first step of migration:the introduction of a customized registry for migration depends on Dubbo itself provides the ability to configure multiple registries, but it has relatively large limitations, when When consumers configure multiple registration centers, Dubbo's original strategy is to preferentially select the address of the first registration center. If the address is empty, then read the second one, and so on. The ideal model should be randomly selected after merging the addresses of multiple registration centers. Therefore, MSE provides a special registration center extension to solve this problem: com.alibaba.edas edas-dubbo-migration-bom 2.6.5.1 pom where edas-dubbo-migration-bom has both 2.6.5.1 and 2.7.5 This version corresponds to two major versions of Dubbo 2.6.x and Dubbo 2.7.x. Step 2:Purchase an MSE Nacos instance, and configure the corresponding nacos server address to purchase the Nacos instance in the same VPC in the MSE console, and add in the application.properties configuration file of the application:dubbo.registry.address = edas-migration://30.5.124.15:9999?service-registry=consul://${consulAddress}:8500,nacos://${nacosAddress}:8848&reference-registry=consul://${consulAddress}:8500,nacos://${nacosAddress}:8848 Description:edas-migration://30.5.124.15:9999 Head information of multiple registration centers. You can leave it unchanged, and ip and port can be filled in arbitrarily, mainly for compatibility with Dubbo's verification of ip and port. At startup, if the log level is WARN and below, a WARN log may be thrown and can be ignored. service-registry The address of the registration center for service registration. Write multiple registry addresses. Each registry is a standard Dubbo registry format; multiple are separated by,. The address of the registry that the reference-registry service subscribes to. Each registry is a standard Dubbo registry format; multiple, separated. Step 3:Confirm that the dual registration scheme successfully started the application, and observe that the information of the provider and consumer is registered in the service management page of the MSE instance.

At the same time, you can also see the corresponding information in the Consul console:

And confirm that the application can be accessed normally. So far our first application has been migrated. Step 4:Follow the migration steps for migrating the first application, and gradually migrate the entire application. Step 5 Clean up the migration configuration. After the migration is completed, delete the original registry configuration and the dedicated edas-dubbo-migration-bom for the migration process. Restart the application in batches in a small amount of time. edas-dubbo-migration-bom is a dedicated starter for migration. Although long-term use has no impact on the stability of your business, it will not be upgraded with Dubbo's version. To avoid future compatibility issues during the framework upgrade process, it is recommended You clean up after the migration is complete, and then restart the application in batches when the business volume is small. How can Spring Cloud applications ensure seamless migration to MSE without business downtime?

Spring Cloud only supports one registration center by default, so it can't complete seamless migration without downtime. This is enhanced here. It supports the dual registration and double subscription model to ensure business migration without downtime. Migration solution:Select the application that will be migrated first. It is recommended to start migration from the lowest Provider. However, if the calling link is too complicated to analyze, it is also possible to choose an application for migration. After the selection is complete, you can refer to the migration steps below to migrate the first application. Step 1:Purchase an MSE Nacos instance, and configure the corresponding nacos server address to purchase the Nacos instance in the same vpc in the MSE console, and add it to the application.properties configuration file of the application:spring.cloud.nacos.discovery.server-addr= {MSE corresponds to the domain name of the Nacos instance}:8848 Step 2:Add the dependency in the application Add the spring-cloud-starter-alibaba-nacos-discovery dependency in the pom.xml file. org.springframework.cloud spring-cloud-starter-alibaba-nacos-discovery {corresponding version} default In this case, Spring Cloud only supports the introduction of one registry in the dependency. When there are multiple registries:an error will be reported during startup. So here we need to add a dependency edas-sc-migration-starter to make the Spring Cloud application support multiple registrations. com.alibaba.edas edas-sc-migration-starter 1.0.2 Ribbon is a component to achieve load balancing In order for the application to support subscription services from multiple registration centers, the Ribbon configuration needs to be modified. In the main class started by the application, RibbonClients is configured by default to MigrationRibbonConfiguration. Assume that the original application main class startup code is as follows:@SpringBootApplication public class ConsumerApplication {public static void main(String[]args) {SpringApplication.run(ConsumerApplication.class, args);}} Then the modified application main class The startup code is as follows:@SpringBootApplication @RibbonClients(defaultConfiguration = MigrationRibbonConfiguration.class) public class ConsumerApplication {public static void main(String[]args) {SpringApplication.run(ConsumerApplication.class, args);}} Step 3:Confirm The dual registration scheme successfully started the application and observed that our service was registered in the service management of the MSE instance.

At the same time, we can see our service in the console of Consul.

And confirm that the application can be accessed normally. So far our first application has been migrated. Step 4:Follow the migration steps for migrating the first application, and gradually migrate the entire application Step 5:Clean up the migration configuration After the migration is completed, delete the original registry configuration and the dedicated edas-sc-migration-starter for the migration process , Restart applications in batches when the business volume is small. edas-sc-migration-starter is a dedicated starter for migration. Although long-term use has no impact on the stability of your business, it has certain limitations in the realization of Ribbon load balancing. It is recommended that you clean up after the migration is completed, and then Restart applications in batches when the business volume is small. About dynamically adjusting service registration and subscription methods:Relying on edas-sc-migration-starter has the effect of cooperating with the configuration center to dynamically adjust service registration and subscription methods. During the migration process, you can dynamically change the service registration and subscription by modifying your configuration. Subscription method. Dynamic adjustment service subscription The default subscription strategy is to subscribe from all registration centers and do some simple aggregation of data. You can modify the spring.cloud.edas.migration.subscribes property in your configuration center to choose which registration centers to subscribe to data from. spring.cloud.edas.migration.subscribes=nacos,consul # Subscribe to services from Consul and Nacos at the same time spring.cloud.edas.migration.subscribes=nacos # Only change from Nacos subscription service Dynamic service registration The default registration strategy is to register to all Registration center. You can choose to close the specified registry by spring.cloud.edas.migration.registry.excludes property in your configuration center. spring.cloud.edas.migration.registry.excludes= #The default value is empty, register to all service registration centers spring.cloud.edas.migration.registry.excludes=consul #Close Consul registration spring.cloud.edas.migration .registry.excludes=nacos,consul #Turn off the registration of Nacos and Consul Alibaba Cloud microservice engine MSE heavy upgrade conference is about to open to put aside concerns and greet the authenticity. From the configuration center to the comprehensive management of microservices, MSE is welcoming his first adult ceremony. On the basis of the original configuration center hosting, a comprehensive upgrade introduces microservice management capabilities, and through Java Agent technology, your application does not need to modify any Code and configuration, you can enjoy the micro service governance capabilities provided by Alibaba Cloud. The functions that have been launched include service query, lossless offline, service authentication, outlier instance removal, and label routing.