Eureka high-availability cluster hand-held construction

Hand-in-hand project construction

  1. Select mirror

Insert picture description here

  1. Write mvn configuration

Insert picture description here

  1. Choose Eureka Server

Insert picture description here

Single node construction

  1. Add @EnableEurekaServer annotation to the startup class
package com.bl.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**
 * @autor BarryLee
 */
@SpringBootApplication
@EnableEurekaServer
public class LearnEurekaApplication {
    
    

  public static void main(String[] args) {
    
    
    SpringApplication.run(LearnEurekaApplication.class, args);
  }

}
  1. Write the configuration file application.properties, I use properties, the same with yml
#这个和service-url一致,否则会发现unavailable
server.port=7900
#是否将自己注册到Eureka Server,默认为true,由于当前就是server,故而设置成false,表明该服务不会向eureka注册自己的信息
eureka.client.register-with-eureka=false
#是否从eureka server获取注册信息,由于单节点,不需要同步其他节点数据,用false
eureka.client.fetch-registry=false
#设置服务注册中心的URL,用于client和server端交流
eureka.client.service-url.defaultZone=http://localhost:7900/eureka/

3. Start, then open http://localhost:7900/

Insert picture description here

High-availability cluster construction

  1. Modify the host file, the location of win10 is: C:\Windows\System32\drivers\etc
host文件末尾加上
127.0.0.1 eureka-7900
127.0.0.1 eureka-7901
127.0.0.1 eureka-7902
  1. On the basis of the above operations, add a file application-eureka-7900.properties
#web端口,服务是由这个端口处理rest请求的
server.port=7900
#是否将自己注册到其他Eureka Server,默认为true 需要
eureka.client.register-with-eureka=true
#是否从eureka server获取注册信息, 需要
eureka.client.fetch-registry=true
#设置服务注册中心的URL,用于client和server端交流
#此节点应向其他节点发起请求
eureka.client.serviceUrl.defaultZone=http://eureka-7901:7901/eureka/,http://eureka-7902:7902/eureka/
#主机名,必填
eureka.instance.hostname=eureka-7900
management.endpoint.shutdown.enabled=true
  1. application-eureka-7901.properties
#web端口,服务是由这个端口处理rest请求的
server.port=7901
#是否将自己注册到其他Eureka Server,默认为true 需要
eureka.client.register-with-eureka=true
#是否从eureka server获取注册信息, 需要
eureka.client.fetch-registry=true
#设置服务注册中心的URL,用于client和server端交流
#此节点应向其他节点发起请求
eureka.client.serviceUrl.defaultZone=http://eureka-7900:7900/eureka/,http://eureka-7902:7902/eureka/
#主机名,必填
eureka.instance.hostname=eureka-7901
management.endpoint.shutdown.enabled=true
  1. application-eureka-7902.properties
#web端口,服务是由这个端口处理rest请求的
server.port=7902
#是否将自己注册到其他Eureka Server,默认为true 需要
eureka.client.register-with-eureka=true
#是否从eureka server获取注册信息, 需要
eureka.client.fetch-registry=true
#设置服务注册中心的URL,用于client和server端交流
#此节点应向其他节点发起请求
eureka.client.serviceUrl.defaultZone=http://eureka-7900:7900/eureka/,http://eureka-7901:7901/eureka/
#主机名,必填
eureka.instance.hostname=eureka-7902
management.endpoint.shutdown.enabled=true
  1. At this point, the setup is complete, and then it is running

Insert picture description here

Copy three

Insert picture description here

Specified profile

Insert picture description here

The other two are the same

Then confirm, start these three services, there will be errors in the middle, because they are registering with each other, and the other services have not been up, open it after getting up: http://localhost:7900/, it must be sure, unavaliable must be Empty

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_38238041/article/details/106608611