Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to create a SpringCloud registry cluster

Shulou Source: shulou.com Published: 2022-06-01 07:07:10 10月29日 Update

This article introduces the knowledge of "how to create a SpringCloud registry cluster". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Cluster environment construction

Step 1: we build two new registry projects, one is called eureka_register_service_master, the other is called eureka_register_service_backup

The application.properties configuration for eureka_register_service_master is as follows:

Server.port=7998eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falsespring.application.name=eureka-servereureka.instance.hostname=mastereureka.client.serviceUrl.defaultZone= http://backup:7999/eureka/# is configured with the address of backup.

The application.properties configuration for eureka_register_service_backup is as follows

Server.port=7999eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falsespring.application.name=eureka-servereureka.instance.hostname=backup# what is configured here is the address of master, eureka.client.serviceUrl.defaultZone= http://master:7998/eureka/

The above configured ports are

Master port is 7998backupr port is 7999

Step 2: add startup files: ApplicationMaster.java,ApplicationBackUp.java

The content of the code is the same.

@ EnableEurekaServer@SpringBootApplicationpublic class ApplicationMaster {public static void main (String [] args) {SpringApplication.run (ApplicationMaster.class, args);}} @ EnableEurekaServer@SpringBootApplicationpublic class ApplicationBackUp {public static void main (String [] args) {SpringApplication.run (ApplicationBackUp.class, args);}}

Step 3: start

If it is jar startup, you need to add parameters-- spring.profiles.active=matser or-- spring.profiles.active=backup.

The first method is to start it through the jar command

Java-jar eureka_register_service_matser-1.0.0.jar-spring.profiles.active=matser java-jar eureka_register_service_backup-1.0.0.jar-spring.profiles.active=backup

The second is to start through eclipse right-click Run As.

Parameters need to be added as follows

Step 4: view the interface

Open http://127.0.0.1:7998/ and http://127.0.0.1:7999/ respectively as shown below

You can see it from the picture above.

Port 7998 is matser. Its registered-replicas points to http://backup:7999/eureka/.

Port 7999 is backup. Its registered-replicas points to http://master:7999/eureka/.

This is the end of the content of "how to create a SpringCloud registry cluster". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Port configuration cluster content parameter address direction more knowledge practicality achievement next figure above two code command dilemma actual engineering situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Docker vpn macOS OPPO Reno