重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

怎么使用SpringCloud高可用的服务注册中心

本篇内容主要讲解“怎么使用Spring Cloud高可用的服务注册中心”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么使用Spring Cloud高可用的服务注册中心”吧!

浉河ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

一、准备工作

继续延用以前的项目,这里出现了点小插曲,由于打算不修改 hosts 文件去实现单台服务器的服务集群,折腾一天也没折腾明白,最后总结个结论:单台服务器得修改hosts,多台服务器可通过ip去配置。

修改 hosts  : C:\Windows\System32\drivers\etc

在文件最后添加几行:

怎么使用Spring Cloud高可用的服务注册中心

二、修改项目erurekaserver

1、新建application-one.yml

server:
  port: 8761
spring:
  application:
    name: eurekaserver
  profiles: one
eureka:
  instance:
    hostname: localhost1
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://localhost2:8861/eureka/
  server:
    enableSelfPreservation: false

2、新建application-two.yml

server:
  port: 8861
spring:
  application:
    name: eurekaserver
  profiles: two

eureka:
  instance:
    hostname: localhost2
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://localhost1:8761/eureka/
  server:
    enableSelfPreservation: false

3、修改启动项

EurekaServerApplication.java 右键 -> Run As -> Run Configruations.. 创建两个启动应用

怎么使用Spring Cloud高可用的服务注册中心

怎么使用Spring Cloud高可用的服务注册中心

4、分别启动 one  two

启动的时候总是有个后台会报错,等启动完成后就好了。分别访问:http://localhost:8761/,http://localhost:8861/,结果如下:

怎么使用Spring Cloud高可用的服务注册中心怎么使用Spring Cloud高可用的服务注册中心

三、修改config-server项目

1、修改application.properties,红框标注部分

怎么使用Spring Cloud高可用的服务注册中心

2、启动config-server

四、修改eurekaclient1的bootstrap.yml

怎么使用Spring Cloud高可用的服务注册中心

启动项目

五、修改service-ribbon的 application.yml

怎么使用Spring Cloud高可用的服务注册中心

启动项目

六、再次分别访问:http://localhost:8761/,http://localhost:8861/

怎么使用Spring Cloud高可用的服务注册中心

怎么使用Spring Cloud高可用的服务注册中心

七、访问http://localhost:8764/hello

怎么使用Spring Cloud高可用的服务注册中心

可成功访问。

到此,相信大家对“怎么使用Spring Cloud高可用的服务注册中心”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


分享标题:怎么使用SpringCloud高可用的服务注册中心
文章路径:http://cqcxhl.com/article/jihgoj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP