Previous first article: Amateur Grass Springcloud Tutorial | First article: Registration and discovery of services Eureka (Finchley version)
Describes the service registration and discovery, where the service registry Eureka Server, is an instance, when thousands of services to it registered, its load is very high, this is not appropriate in production environment, this article mainly describes how to cluster Eureka Server.
First, the preparatory work
Eureka can made even more resilient and available by running multiple instances and asking them to register with each o Ther. In fact, the "the default behaviour, so all" need to does to make it work are add a valid serviceurl to a peer, e.g.
From official website
Eureka makes it more highly available by running multiple instances. In fact, this is its default maturity, and all you need to do is give the equivalent instance a legitimate association serviceurl.
This article is based on the first article of the project, to make changes.
Second, the transformation work
Under the Resources folder in the Eureka-server project, create the configuration file Application-peer1.yml:
1 server: port:8761 3 4 spring: 5 Profiles:peer1 6 eureka: 7 instance: 8 Hostname:peer1 9 client: 10 serviceurl: 11 Defaultzone: Http:// peer2:8769/eureka/
and create another configuration file Application-peer2.yml:
1 server: port:8769 3 4 spring: 5 Profiles:peer2 6 eureka: 7 instance: 8 Hostname:peer2 9 client: 10 serviceurl: 11 Defaultzone: Http:// peer1:8761/eureka/
At this time the Eureka-server has been transformed complete.
OU could use this configuration to test the peer awareness on a single host (there's not much value in doing so in Produ ction) by Manipulating/etc/hosts to resolve the host names.
In accordance with official documentation instructions, the Etc/hosts,linux system needs to be changed via Vim/etc/hosts, plus:
1 127.0.0.1 peer12 127.0.0.1 Peer2
Windows PC, modified in c:/windows/systems/drivers/etc/hosts.
At this time need to transform the next Service-hi:
1 Eureka: 2 Client:3 serviceurl:4 defaultzone:http:// peer1:8761/eureka/5server:6 port:87627Spring: 8 application:9 Name:service-hi
Iii. Commencement of Works
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,
You will find that you have registered Service-hi, and you have a Peer2 node, and the same access localhost:8769 you will find a Peer1 node.
Client only registers with 8761, but when you open 8769, you will also find that 8769 also has the client's registration information.
Personal experience: This is done by looking at the official documentation of the demo, but need to manually change the host is not in line with spring Cloud high up?
Prefer IP Address
In some cases, it's preferable for Eureka to advertise the IP Adresses of services rather than the hostname. Set eureka.instance.preferIpAddress to True and if the application registers with Eureka, it'll use the IT IP Address rat She than its hostname.
From official website
Eureka.instance.preferipaddress=true is to let Eureka let other services register it by setting the IP. It may be possible to change the way it is by changing the host.
The architecture diagram at this point:
Eureka-eserver peer1 8761,eureka-eserver peer2 8769 Mutual Sensing, when there is a service registration, two Eureka-eserver is equivalent, they all have the same information, which is the redundancy of the server to increase reliability, When one server goes down, the service does not terminate because the same data exists for the other service.
This article source code download:
Https://github.com/forezp/SpringCloudLearning/tree/master/sc-f-chapter10
Iv. Reference Documents
High_availability_zones
Thank you for your attention! Add QQ1 Group: 135430763,QQ2 Group: 454796847,QQ3 Group: 187424846. QQ Group into the group password: xttblog, want to add a group of friends, you can search: Xmtxtt, note: "Xttblog", add Assistant pull you into the group. Note errors do not agree with a friend application. Thanks again for your attention! Follow up with wonderful content will be sent to you the first time! Please send the original article to [email protected] email. Business cooperation can add assistants to communicate!
Amateur Grass Springcloud Tutorial | Tenth: High-Availability Service registry (Finchley version)