Spring Cloud 搭建eureka

首先是版本是

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath/>
    </parent>
 <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <spring.cloud.version>Dalston.SR4</spring.cloud.version>
        <spring-boot-admin.version>1.5.4</spring-boot-admin.version>
    </properties>

首先是单节点的

spring:
  profiles:
    active: aliyun


---
spring:
  profiles: aliyun
server:
  port: 8765

eureka:
  instance:
    hostname: registry1
  client:
    registerWithEureka: false
    fetchRegistry: false
    service-url:
      defaultZone: http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

security:
  user:
    name: user
    password: ${REGISTRY_SERVER_PASSWORD:password}

可以看出来运行是可以了但是因为是单节点就没有分片这些显示了。其中在配置文件中的registerWithEureka和fetchRegistry是为了让eureka互相注册作为一个集群,如果都是false那么当前的服务器是唯一的服务器

接下来是集群

 

首先我尝试了用ip地址直接配置

spring:
  profiles:
    active: aliyun1


---
spring:
  profiles: aliyun
server:
  port: 8761

eureka:
  instance:
    ip-address: 127.0.0.1
  client:
    registerWithEureka: true
    fetchRegistry: false
    service-url:
      defaultZone: http://${security.user.name}:${security.user.password}@127.0.0.1:${server.port}/eureka/

security:
  user:
    name: user
    password: ${REGISTRY_SERVER_PASSWORD:password}

test:
  hostname: registry2
  port: 8762


---
spring:
  profiles: aliyun1
server:
  port: 8762

eureka:
  instance:
    ip-address: 127.0.0.1
  client:
    registerWithEureka: true
    fetchRegistry: true
    service-url:
      defaultZone: http://${security.user.name}:${security.user.password}@127.0.0.1:${server.port}/eureka/

security:
  user:
    name: user
    password: ${REGISTRY_SERVER_PASSWORD:password}

test:
  hostname: registry1
  port: 8761

结果界面显示

结果这两个分区都是挂掉的。。。。无效

 

查了一下原因

https://www.cnblogs.com/xuechen/p/9085162.html

https://blog.csdn.net/qq_36345181/article/details/81349211

然后修改了配置

spring:
  profiles:
    active: aliyun


---
spring:
  profiles: aliyun
server:
  port: 8761

eureka:
  instance:
    hostname: registry1
  client:
    registerWithEureka: true
    fetchRegistry: true
    service-url:
      defaultZone: http://${security.user.name}:${security.user.password}@${test.hostname}:${test.port}/eureka/

security:
  user:
    name: user
    password: ${REGISTRY_SERVER_PASSWORD:password}

test:
  hostname: registry2
  port: 8762


---
spring:
  profiles: aliyun1
server:
  port: 8762

eureka:
  instance:
    hostname: registry2
  client:
    registerWithEureka: true
    fetchRegistry: true
    service-url:
      defaultZone: http://${security.user.name}:${security.user.password}@${test.hostname}:${test.port}/eureka/

security:
  user:
    name: user
    password: ${REGISTRY_SERVER_PASSWORD:password}

test:
  hostname: registry1
  port: 8761

效果,分区已经可以正常使用了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值