In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces Spring Cloud how to achieve a highly available service registration center, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
I. preparatory work
Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. In fact, this is the default behaviour, so all you need to do to make it work is add a valid serviceUrl to a peer, e.g.
Extracted from the official website
Eureka makes it more highly available by running multiple instances. In fact, this is its default familiarity, and all you need to do is give the peer instance a legal association serviceurl.
We revise this article based on the project of the first article.
II. Transformation work
In the eureka-server project, under the resources folder, create the configuration file application-peer1.yml:
Server: port: 8761spring: profiles: peer1eureka: instance: hostname: peer1 client: serviceUrl: defaultZone: http://peer2:8769/eureka/
And create another configuration file, application-peer2.yml:
Server: port: 8769spring: profiles: peer2eureka: instance: hostname: peer2 client: serviceUrl: defaultZone: http://peer1:8761/eureka/
By this time, the eureka-server has been transformed.
Ou could use this configuration to test the peer awareness on a single host (there's not much value in doing that in production) by manipulating / etc/hosts to resolve the host names.
According to the instructions of the official documentation, you need to change the etc/hosts,linux system through vim / etc/hosts, plus:
127.0.0.1 peer1127.0.0.1 peer2
Windows computer, modified in c:/windows/systems/drivers/etc/hosts.
At this point, you need to modify the service-hi:
Eureka: client: serviceUrl: defaultZone: http://peer1:8761/eureka/server: port: 8762spring: application: name: service-hi 3. Start the project
Start eureka-server:
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
>
Start service-hi:
Java-jar service-hi-0.0.1-SNAPSHOT.jar
Visit: localhost:8761, as shown in the figure:
You will find that service-hi is registered and there is a peer2 node. In the same way, if you visit localhost:8769, you will find a peer1 node.
Client only registers with 8761, but if you open 8769, you will also find that 8769 also has client registration information.
Personal feelings: this is written by looking at the official documents of the demo, but the need to manually change the host is not in line with the height of the Spring Cloud?
Prefer IP Address
In some cases, it is preferable for Eureka to advertise the IP Adresses of services rather than the hostname. Set eureka.instance.preferIpAddress to true and when the application registers with eureka, it will use its IP Address rather than its hostname.
Extracted from the official website
Eureka.instance.preferIpAddress=true allows eureka to register it by setting up ip for other services. Maybe by changing the way host is changed.
The architecture diagram at this time:
Eureka-eserver peer1 8761 Eureka-eserver peer2 8769 is sensitive to each other. When a service is registered, the two servers are peer-to-peer, and they both have the same information. This is to increase the reliability through server redundancy. When one server goes down, the service will not be terminated because the other service has the same data.
Thank you for reading this article carefully. I hope the article "how to achieve a highly available service registry for Spring Cloud" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.