美文网首页
SpringCloud eureka 集群

SpringCloud eureka 集群

作者: 楚长铭 | 来源:发表于2020-03-12 08:35 被阅读0次

依赖

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
    implementation 'org.springframework.boot:spring-boot-starter-freemarker'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}
  • 新版的需要引入freemarker否则eureka页面出不来

配置文件



server:
  port: 2000
eureka:
  instance:
    hostname: localhost
  client:
    #是否向注册中心注册本身服务,
    #由于本身是注册中心单例模式设置false
    #集群模式设置为true将自己注册到注册中心
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      #集群模式下注册中心地址 用,分开
      defaultZone: http://localhost:2000/eureka/,http://localhost:2001/eureka/
spring:
  freemarker:
    prefer-file-system-access: false
  application:
    name: eureka-server-2000
  • 其他的节点配置类似,只要改个ip地址或者端口号即可
  • 集群模式下注册中心会相互注册,即使挂了一个其他的也还能用
  • 注册中心启动之后,会相互复制信息,所以即使客户端之注册到其中一个注册中心,经过少许时间也最终会注册到集群中所有的注册中心

开启eureka

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerProjectApplication {

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

}

客户端依赖和配置

    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'

@EnableEurekaClient
server:
  port: 3001
spring:
  application:
    name: hystrix-project
eureka:
  client:
    service-url:
      defaultZone: http://localhost:2000/eureka/

相关文章

网友评论

      本文标题:SpringCloud eureka 集群

      本文链接:https://www.haomeiwen.com/subject/icmhjhtx.html