转载

springcloud在线扩容

准备工作

Eureka-client一个,Eureka-server一个,config-server一个

1.1 pom的准备

config-server

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

eureka-client和Eureka-server都添加

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

1.2 配置文件

eureka-client

server:
  port: 8081
spring:
  application:
    name: eureka-client1
eureka:
  instance:
    hostname: localhost
    prefer-ip-address: true
  client:
    service-url:
      default-zone: http://localhost:8761/eureka/

eureka-server

server:
  port: 8761
eureka:
  instance:
    hostname: localhost
    prefer-ip-address: true
  client:
    service-url:
      default-zone: http://${eureka.instance.hostname}:${server.port}/eureka/
    register-with-eureka: false
    fetch-registry: false
  server:
    wait-time-in-ms-when-sync-empty: 0
    enable-self-preservation: false

config-server

目录结构

springcloud在线扩容

application.yml

server:
  port: 8888
spring:
  application:
    name: config-server
  profiles:
    active: native

eureka-client.yml

server:
  port: 8081
spring:
  application:
    name: eureka-client1
eureka:
  client:
    service-url:
      default-zone: http://localhost:8761/eureka/

eureka-server-peer1.yml

server:
  port: 8761
eureka:
  instance:
    hostname: localhost
    prefer-ip-address: true
  client:
    service-url:
      default-zone: http://localhost:8761/eureka/
    register-with-eureka: true
    fetch-registry: true
  server:
    wait-time-in-ms-when-sync-empty: 0
    enable-self-preservation: false

然后先后启动config-server、eureka-server、eureka-client

原文  https://segmentfault.com/a/1190000019683603
正文到此结束
Loading...