In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to deploy Eureka cluster, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
I. Eureka cluster deployment
It is recommended that you strictly follow the steps to deploy, otherwise it is easy to cause problems, and possible problems will be explained below.
1. Create a new maven project. The pom example is as follows
4.0.0 com.iceberg.eurekatest eureka-test 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE org.springframework.cloud spring-cloud-dependencies Greenwich.SR2 pom import Org.springframework.cloud spring-cloud-starter-netflix-eureka-server org.springframework.boot spring-boot-maven-plugin
2. Add a note to the Application class to open eureka
@ EnableEurekaServer@SpringBootApplicationpublic class EurekaApplication {public static void main (String [] args) {SpringApplication.run (EurekaApplication.class, args);}}
3. Add two configuration files application-peer1.yaml
Spring: application: name: eureka-serverserver: port: 8001eureka: client: # whether to register with Eureka Server register-with-eureka: true # whether to obtain registration information from Eureka Server fetch-registry: true serviceUrl: defaultZone: "http://peer2:8002/eureka/" instance: prefer-ip-address: false hostname:" peer1 "
Application-peer2.yaml
Spring: application: name: eureka-serverserver: port: 8002eureka: client: # whether to register with Eureka Server register-with-eureka: true # whether to obtain registration information from Eureka Server fetch-registry: true serviceUrl: defaultZone: "http://peer1:8001/eureka/" instance: prefer-ip-address: false hostname:" peer2 "
4. Add two mappings to host
127.0.0.1 peer1
127.0.0.1 peer2
5. Add-Dspring.profiles.active=peer1 to the startup parameters of SpringBoot, and then start the project.
Then change it to peer2 and start the project (a total of two)
6. Points for attention
(1) when the first eureka is started, the following exception is reported
2019-07-29 15 c.n.discovery.InstanceInfoReplicator 49 WARN 15416-[nfoReplicator-0] c.n.discovery.InstanceInfoReplicator: There was a problem with the instance info replicatorcom.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute (RetryableEurekaHttpClient.java:112) ~ [eureka-client-1.9.12.jar:1.9.12] at com.netflix.discovery.shared.transport .decorator.EurekaHttpClientDecorator.register (EurekaHttpClientDecorator.java:56) ~ [eureka-client-1.9.12.jar:1.9.12] at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute (EurekaHttpClientDecorator.java:59) ~ [eureka-client-1.9.12.jar:1.9.12] at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute (SessionedEurekaHttpClient.java:77) ~ [eureka-client-1.9.12.jar : 1.9.12] at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register (EurekaHttpClientDecorator.java:56) ~ [eureka-client-1.9.12.jar:1.9.12] at com.netflix.discovery.DiscoveryClient.register (DiscoveryClient.java:847) ~ [eureka-client-1.9.12.jar:1.9.12] at com.netflix.discovery.InstanceInfoReplicator.run (InstanceInfoReplicator.java:121) ~ [eureka- Client-1.9.12.jar:1.9.12] at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511) [na:1.8.0_212] at java.util.concurrent.FutureTask.run$$$capture (FutureTask.java:266) [na:1.8.0_212] at java.util.concurrent.FutureTask.run (FutureTask.java) [na:1.8.0_212] at java. Util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201 (ScheduledThreadPoolExecutor.java:180) [na:1.8.0_212] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run (ScheduledThreadPoolExecutor.java:293) [na:1.8.0_212] at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149) [na:1.8.0_212] at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624) [na:1.8 .0,212] at java.lang.Thread.run (Thread.java:748) [na:1.8.0_212]
This exception means that the configured eureka-server has not been found (because you haven't started it yet), and it will be normal when the second eureka-server is started.
(2) in the stand-alone configuration of eureka, the two options of register-with-eureka and fetch-registry are false, but the cluster version of eureka is implemented by service discovery, so you need to change it to true to register yourself with the server and obtain client information.
7. After startup, the browser accesses localhost:8001 and localhost:8002
See the following picture to show success
Second, the pits that may be encountered in cluster deployment
1. Do not want to add host, just use localhost
Some friends may not know how to change host or just be lazy and directly replace peer1 and peer2 with localhost. The configuration file is as follows
Application-peer1.yaml
Spring: application: name: eureka-serverserver: port: 8001eureka: client: # whether to register with Eureka Server register-with-eureka: true # whether to obtain registration information from Eureka Server fetch-registry: true serviceUrl: defaultZone: "http://localhost:8002/eureka/" instance: prefer-ip-address: false hostname:" localhost "
Application-peer2.yaml
Spring: application: name: eureka-serverserver: port: 8002eureka: client: # whether to register with Eureka Server register-with-eureka: true # whether to obtain registration information from Eureka Server fetch-registry: true serviceUrl: defaultZone: "http://localhost:8001/eureka/" instance: prefer-ip-address: false hostname:" localhost "
There are two situations here:
(1) deploy two eureka on a stand-alone, and then access http://localhost:8001/
You can see that the registered-replicas column is empty. Why is it like this?
Let's take a look at the resolvePeerUrls () method of PeerEurekaNodes in the source code of eureka. The purpose of this method is to obtain available addresses from the configured serviceUrl.
Protected List resolvePeerUrls () {InstanceInfo myInfo = applicationInfoManager.getInfo (); String zone = InstanceInfo.getZone (clientConfig.getAvailabilityZones (clientConfig.getRegion ()), myInfo); List replicaUrls = EndpointUtils .getDiscoveryServiceUrls (clientConfig, zone, new EndpointUtils.InstanceInfoBasedUrlRandomizer (myInfo)); int idx = 0 While (idx < replicaUrls.size ()) {/ / this place is the culprit if (isThisMyUrl (replicaUrls.get (idx)) {replicaUrls.remove (idx);} else {idx++;}} return replicaUrls;} public boolean isThisMyUrl (String url) {final String myUrlConfigured = serverConfig.getMyUrl () If (myUrlConfigured! = null) {return myUrlConfigured.equals (url);} return isInstanceURL (url, applicationInfoManager.getInfo ());} / / determine whether the hostnam of url is consistent with the current hostname, and if so, directly ignore public boolean isInstanceURL (String url, InstanceInfo instance) {String hostName = hostFromUrl (url); String myInfoComparator = instance.getHostName (); if (clientConfig.getTransportConfig (). ApplicationsResolverUseIp ()) {myInfoComparator = instance.getIPAddr () } return hostName! = null & & hostName.equals (myInfoComparator);}
Through the isInstanceURL () method, eureka removes the same url as hostname, and we happen to configure localhost, so although you start two eureka, they don't think of themselves as clusters.
(2) deployment of multiple machines (or multiple virtual machines)
If you start two eureka on different hosts and configure localhost, you will see the error com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server all the time because it cannot find another eureka through localhost
2. Instead of using a domain name, use IP to register
Eureka provides an option to enable eureka registered addresses to use IP instead of domain names, and the configuration item is eureka.instance.prefer-ip-address=true
(1) deployment of multiple network cards on a single machine
Here, explain what multiple network cards are. After we install vmware, it will create some virtual network cards for us. For example, in my case, it has created two virtual addresses for me.
Multiple network cards mean that you can see multiple IP addresses using the ipconfig command (only my own definition, not an academic definition)
In this case, the IP registered by eureka may be different from your actual IP. For example, the eureka I just started, its instance info shows that the IP is 192.168.157.1. In this case, his registered IP is also 192.168.157.1. In order for him to register the actual IP, we need to specify it through eureka.instance.ip-address=10.60.44.136.
Then the question arises: if the ip-address filled in by your peer1 is 10.60.44.136, the url in the serviceUrl.defaultZone in peer2 has to be 10.60.44.136, what does the ip-address of peer2 use? If you also use 10.60.44.136, the previous problem will occur, which will be eliminated by eureka itself, so you need to change to an IP and still represent the local one, such as 127.0.0.1. The configuration file is as follows: application-peer1.yaml
Spring: application: name: eureka-serverserver: port: 8001eureka: client: # whether to register with Eureka Server register-with-eureka: true # whether to obtain registration information from Eureka Server fetch-registry: true serviceUrl: defaultZone: "http://127.0.0.1:8002/eureka/" instance: prefer-ip-address: true hostname:" localhost "ip-address:" 10.60.44.136 "
Application-peer2.yaml
Spring: application: name: eureka-serverserver: port: 8002eureka: client: # whether to register with Eureka Server register-with-eureka: true # whether to obtain registration information from Eureka Server fetch-registry: true serviceUrl: defaultZone: "http://10.60.44.136:8001/eureka/" instance: prefer-ip-address: true hostname:" localhost "ip-address:" 127.0.0.1 "
The result of the operation is as follows
(2) deployment of stand-alone Nic
Just now, multiple network cards mean that ipconfig has multiple IP, and a single network card means that there is only one IP. According to the previous description, if there is only one IP, you cannot successfully deploy the cluster on a stand-alone machine (it will be ignored), so you will skip it.
(3) Multi-machine deployment
There is nothing to say about this. Ip is designated as an ip that can access each other, and OK as long as it is configured correctly.
After reading the above, have you mastered how to deploy the Eureka cluster? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.