In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Spring Cloud to build a high availability service registry center". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Spring Cloud to build a high availability service registry center".
Add profile
In the last article, we created a service registry called eureka-server, so in this article, I will modify the configuration file of the project to start it multiple times. As follows, I added two configuration files, application-peer1.properties and application-peer2.properties, to the project:
The contents of the two configuration files are as follows:
Application-peer1.properties:
Server.port=1111eureka.instance.hostname=peer1eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.service-url.defaultZone= http://peer2:1112/eureka/
Application-peer2.properties:
Server.port=1112eureka.instance.hostname=peer2eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.service-url.defaultZone= http://peer1:1111/eureka/
With regard to these two configuration files, I would like to say the following:
1. In peer1's configuration file, make its service-url point to peer2, and in peer2's configuration file, let its service-url point to peer1.
two。 In order for peer1 and peer2 to be accessed correctly, we need to always add two lines of configuration to the hosts file in the C:\ Windows\ System32\ drivers\ etc directory, as follows:
127.0.0.1 peer1
127.0.0.1 peer2
3. Because peer1 and peer2 point to each other, we actually build a two-node service registry cluster
Generate jar file
OK, instead of starting the project directly from IDEA, we first generate the jar file for the project as follows: double-click package to generate:
The result is as follows:
Start the project
After generating the jar file, we use the java command on the command line to start the project. At startup, we can set a different configuration file to start the project, as follows:
Java-jar eureka-server-0.0.1-SNAPSHOT.jar-spring.profiles.active=peer1 java-jar eureka-server-0.0.1-SNAPSHOT.jar-spring.profiles.active=peer2
These two lines of commands indicate that we use two configuration files, application-peer1.properties and application-peer2.properties, to start the application, OK. After executing these two commands, our service registry starts two. The effect is as follows:
We can see that we can already see the peer2 node in the DS replicas of the peer1 node, and we can see the peer1 node in the DS replicas of peer2.
OK, after that, our service registry cluster is set up, and then we can do a simple test.
test
Modify the configuration file for the provider project mentioned in the previous article as follows:
Spring.application.name=hello-service eureka.client.service-url.defaultZone= http://peer1:1111/eureka,http://peer2:1112/eureka
Attention, friends, we have added two registry addresses in service-url, the two addresses are separated, OK, and modify it here. Next, let's start the project. After starting the project successfully, we will refresh the http://localhost:1111 and http://localhost:1112 pages. We will find that my service provider is registered in both service registries, as follows:
OK, at this point, we have successfully built a highly available service registry.
Thank you for your reading. The above is the content of "how to use Spring Cloud to build a highly available service registry center". After the study of this article, I believe you have a deeper understanding of how to use Spring Cloud to build a highly available service registry center. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.