In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "Spring Cloud how to achieve a high-availability configuration center", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve high-availability configuration center Spring Cloud" this article.
How does the configuration center read the configuration file from the remote git? when there are many service instances, it reads the file from the configuration center. You can consider turning the configuration center into a micro-service and clustering it to achieve high availability. The architecture figure is as follows:
I. preparatory work
Continue to use the project in the previous article to create an eureka-server project to use as a service registry. The start of introducing Eureka into its pom.xml file depends on spring-cloud-starter-eureka-server, as follows
Org.springframework.cloudspring-cloud-starter-eureka-server
On the configuration file application.yml, specify the service port as 8889, plus the basic configuration as the service registry, the code is as follows:
Server: port: 8889eureka: instance: hostname: localhost client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Entry class:
@ EnableEurekaServer@SpringBootApplicationpublic class EurekaServerApplication {public static void main (String [] args) {SpringApplication.run (EurekaServerApplication.class, args);}} II. Transform config-server
The starting point of adding EurekaClient to its pom.xml file depends on spring-cloud-starter-eureka, as follows:
Org.springframework.cloud spring-cloud-starter-eureka
Configuration file application.yml, which specifies that the service registration address is http://localhost:8889/eureka/. Other configurations are the same as in the previous article. The complete configuration is as follows:
Spring.application.name=config-serverserver.port=8888spring.cloud.config.server.git.uri= https://github.com/forezp/SpringcloudConfig/spring.cloud.config.server.git.searchPaths=respospring.cloud.config.label=masterspring.cloud.config.server.git.username= your usernamespring.cloud.config.server.git.password= your passwordeureka.client.serviceUrl.defaultZone= http://localhost:8889/eureka/
Finally, you need to add the @ EnableEureka annotation to the startup class Application of the program.
Third, transform config-client
To register it to the service registry, as an Eureka client, you need a pom file plus a start-up dependency spring-cloud-starter-eureka, as follows:
Org.springframework.cloud spring-cloud-starter-eureka
The configuration file bootstrap.properties, note that it is bootstrap. Plus the registered address of the service is http://localhost:8889/eureka/
Spring.application.name=config-clientspring.cloud.config.label=masterspring.cloud.config.profile=dev#spring.cloud.config.uri= http://localhost:8888/eureka.client.serviceUrl.defaultZone=http://localhost:8889/eureka/spring.cloud.config.discovery.enabled=truespring.cloud.config.discovery.serviceId=config-serverserver.port=8881
Spring.cloud.config.discovery.enabled reads files from the configuration center.
The servieId of spring.cloud.config.discovery.serviceId configuration center, that is, the service name.
At this time, it is found that when reading the configuration file, the ip address is no longer written, but the service name. At this time, if the configuration service is deployed in multiple copies, it will be highly available through load balancing.
Start eureka-servr,config-server,config-client in turn and visit http://localhost:8889/
Visit http://localhost:8881/hi and the browser displays:
Foo version 3
These are all the contents of the article "how to achieve a highly available configuration Center for Spring Cloud". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.