Learning blog: [SpringCloud] Eureka cluster

Simply learn how to use the Eureka cluster.
First, add the hosts file (opened by the administrator) under the path C:\Windows\System32\drivers\etc to create a
insert image description here
cluster module
insert image description here
and import dependencies .

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

configuration file

server:
  port: 7001

eureka:
  instance:
    hostname: eureka7001.com #Eureka服务端实例名
  client:
    register-with-eureka: false #是否向Eureka注册自己
    fetch-registry: false #false表示自己是注册中心
    service-url:  #监控界面
      #单机
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      #集群
      defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
server:
  port: 7002

eureka:
  instance:
    hostname: eureka7002.com #Eureka服务端实例名
  client:
    register-with-eureka: false #是否向Eureka注册自己
    fetch-registry: false #false表示自己是注册中心
    service-url:  #监控界面
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/
server:
  port: 7003

eureka:
  instance:
    hostname: eureka7003.com #Eureka服务端实例名
  client:
    register-with-eureka: false #是否向Eureka注册自己
    fetch-registry: false #false表示自己是注册中心
    service-url:  #监控界面
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/

Open the annotation @EnableEurekaServer in the main startup class respectively

@SpringBootApplication
@EnableEurekaServer //服务端启动类 接受注册
public class EurekaServer_7001 {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(EurekaServer_7001.class, args);
    }
}

insert image description here
Cluster association succeeded


Add in the original configuration file application.yml of the service provider

eureka:
  client:
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
  instance:
    instance-id: springcloud-provider-dept8001  #描述信息
    prefer-ip-address: true #优先使用ip注册,访问显示ip

The service provider has been registered in the cluster, as long as at least one of the three service registries survives, the service provider can still work normally

Guess you like

Origin blog.csdn.net/Aurinko324/article/details/125649690