分布式 高可用 注册中心 eureka集群搭建

基于spring boot 搭建 集群

环境版本
spring cloud  Greenwich.SR5
spring boot   2.1.6.RELEASE
jdk           11
pom文件:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

配置文件
application-dev0.yml
application-dev1.yml
application-dev2.yml
  • application-dev0.yml
## server
server:
  port: 8010
#  spring
spring:
  application:
    name: eureka-server

# eureka
eureka:
  instance:
    hostname: eureka0
  server:
    enable-self-preservation: false
  client:
    # false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    fetch-registry: true
    # false表示不向注册中心注册自己。
    register-with-eureka: true
    serviceUrl:
      defaultZone: http://eureka1:8011/eureka, http://eureka2:8012/eureka
  • application-dev1.yml
## server
server:
  port: 8011
#  spring
spring:
  application:
    name: eureka-server

# eureka
eureka:
  instance:
    hostname: eureka1
  server:
    enable-self-preservation: false
  client:
    # false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    fetch-registry: true
    # false表示不向注册中心注册自己。
    register-with-eureka: true
    serviceUrl:
      defaultZone: http://eureka0:8010/eureka, http://eureka2:8012/eureka
  • application-dev2.yml
## server
server:
  port: 8012
#  spring
spring:
  application:
    name: eureka-server

# eureka
eureka:
  instance:
    hostname: eureka2
  server:
    enable-self-preservation: false
  client:
    # false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    fetch-registry: true
    # false表示不向注册中心注册自己。
    register-with-eureka: true
    serviceUrl:
      defaultZone: http://eureka0:8010/eureka, http://eureka1:8011/eureka
  • 启动时 使用 --spring.profiles.active=dev2 指定不同的环境
启动类添加注解
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {

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

}

FAQ:

路径不能使用localhost
defaultZone: http://eureka0:8010/eureka, http://eureka1:8011/eureka中的 不饿能使用localhost
开启相互注册
# false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: true
# false表示不向注册中心注册自己。
register-with-eureka: true
spring.application.name或eureka.instance.appname必须一致
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值