Spring Cloud Eureka Cluster Build-and discover a "gut bug"

Source: Internet
Author: User

First explain the title of the "Intuitive bug", this is my own definition. It is our intuition that this is a bug, a mistake, and there is no real error.

Like what:

Although the error message appears, the entire program has not been faulted. As for the reason, the text on the picture has been well explained.

Here, let's just say it briefly.

This occurs because our program has been started (the red box has already appeared in the log, the program has been started, so the program itself is not a problem.) ), why is there an error?

Because in this system, we want to build a cluster environment, each server after its own boot, to connect the other servers in the cluster, so that communication between each other to communicate information.

However, we must be in order to start the server, we do not start whichever server first, the other servers are not ready, so there will be no need to find the server to connect, so will be an error.

This error does not need to be resolved at all, all the servers are started, the entire cluster will be able to run normally (because there is a connection error, now all the servers are ready, so there will be no more connection errors, unless a server down.) )。

Let's take a look at the building process of the Springcloudeureka cluster:

1. Create the project structure first: (using Springboot 1.5.10)

2, in the Start Program class header add note

Package Com.thunisoft.thunisoftregister;import Org.springframework.boot.springapplication;import Org.springframework.boot.autoconfigure.springbootapplication;import Org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer@SpringBootApplicationpublic class Thunisoftregisterapplication {public static void main (string[] args) {Springapplication.run (thunisoftregisterapplication.class, args);}}

3. Write the configuration file

spring:application:name:spring-cloud-eureka Profiles:peer1server:port:8000eureka : Instance:hostname:peer1 client:serviceurl:defaultzone:http://peer2:8001/eureka/,http://peer3:8002/eure Ka/ fetch-registry:true register-with-eureka:true ---spring:application:n      Ame:spring-cloud-eureka profiles:peer2server:port:8001eureka:instance:hostname:peer2 Client:serviceurl: Defaultzone:http://peer1:8000/eureka/,http://peer3:8002/eureka/ Fetch-registry:tru  E register-with-eureka:true ---spring:application:name:spring-cloud-eureka profiles:peer3server:port: 8002eureka:instance:hostname:peer3 Client:serviceurl:defaultzone:http://peer1:8000/eureka/,http://peer 2:8001/eureka/ fetch-registry:true register-with-eureka:true  

The above configuration Red Code snippet is important, here to explain:

1, Fetch-registry: Indicates whether to obtain the registration information from Eureka Server, if it is a single node, do not need to synchronize other Eureka server nodes, you can set to False, but here is the cluster, should be set to True, the default is true, Not set.

2, Register-with-eureka: whether to register themselves to Eureka Server, because to build the cluster environment, you need to register themselves and the masses, so should be opened. The default is true, which is not explicitly set.

    

4, because the actual experiment on a machine, so modify the host file (under Windows system, C:\WINDOWS\SYSTEM32\DRIVERS\ETC)

127.0.0.1       peer1127.0.0.1       peer2127.0.0.1       Peer3

Added as above three paragraphs

5. Start the Registration Center service

5.1. You can use idea to start

Follow this step to add three boot nodes, note: The program arguments parameter changes to Peer2, Peer3, and corresponds to the Spring.application.files parameter value in the configuration file.

Then start all.

5.2. After packaging into a jar, start with the Java-jar command

Package The program as a jar using the Maven plugin or the Gradl plugin, and so on. Then execute the following command

The jar package name generated by the Java-jar. Jar--spring.profiles.active=peer1java-jar generated jar package name. Jar--spring.profiles.active=peer2java-jar The generated jar package name. Jar--spring.profiles.active=peer3

Note: The above two startup methods can start the cluster, but there is one problem to be aware of, is the above mentioned "intuitive bug" problem. Detailed reference above.

6. View Cluster effects

Spring Cloud Eureka Cluster Build-and discover a "gut bug"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.