eureka achieve high availability

Preface:
spring-cloud-based micro-service architecture, all of the micro-services need to be registered to the registry, if the registry obstruction or collapse, then the whole system can not continue normal service, so here we need the registration center cluster In other words, high availability (HA)
premise:
Read and complete the first registry of projects, without changing environment. This article is an analog high availability, you can copy the project two separate registry changes their profile to achieve the same effect
Modify the hosts, at the end of file add the following two lines:
127.0.0.1 peer1127.0.0.1 peer2
Recommended use notepad ++, if it is win10 will remind mention permissions, OK, and then save it.
Project to build:
Open the project registry, create a application-peer1.properties in src / resources
[url =] [/ url]
# application name spring.application.name = eureka-server # domain name service port 1111server.port = # 1111 to provide services, where the eureka.instance.hostname = peer1 # modify the hosts file register yourself eureka.client.service-url.defaultZone = http to a second registry: // peer2: 1112 / Eureka / [url =] [/ url]
 
Create a application-peer2.properties in src / resources
[url =] [/ url]
# application name and first registry as spring.application.name = eureka-server # service port 1112server.port = 1112 # domain name service, modify the eureka here in the hosts file .instance.hostname = peer2 # register their eureka.client.service-url.defaultZone = http to the first registry: // peer1: 1111 / Eureka / [url =] [/ url]
 
As used herein idea to test, you first need to be labeled jar package for this project because the pom.xml in maven build tools have been introduced and packaging tools and packaged in the format specified jar package, direct operating here, the top right of the screen
 
 
Packing is completed, the jar package located in the target folder as
 
 
Opened as terminal, bottom of the screen
 
After opening the terminal, because the jar package in the target directory, the current directory is the project directory, so first cd to the target directory, and then enter the following command:
Tip: When entering commands in order to prevent the wrong file name, you can enter the first few letters of the file name, and then use the tab key to auto-complete
java -jar EurekaServerDemo-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1
After you enter this command is completed, the project peer1 profile start, as
 
 
Next we start a second project, there is need to open another terminal, cd to the target directory
Note: We used here is the same project, the reader can use to test the two projects, special attention is required ports do not conflict
 
java -jar EurekaServerDemo-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2
 
Wait for the completion of the project start to see whether the error.
test
Browser enter: localhost: 1112 view, you can enter localhost: 1111 view
 

Epilogue
After setting the registry multiple nodes to achieve high availability, but at this time we only micro-service application is registered into this service, so we need to register the service with the same path of the new node to the micro-service applications in.
Between a plurality of nodes, "" separate, FIG.
 
 
Such micro-after service provider from one place to disconnect, because there are registered in other nodes, so it can provide services, if you do not use a host name to access the registry, you can also use the ip, but you need to add an entry, the value default false
eureka.instance.prefer-ip-address=true
Published 795 original articles · won praise 3 · Views 110,000 +

Guess you like

Origin blog.csdn.net/u010395024/article/details/105043375
Recommended