SpringCloud怎么将EurekaServer集群化

这篇文章主要介绍“SpringCloud怎么将Eureka Server集群化”,在日常操作中,相信很多人在SpringCloud怎么将Eureka Server集群化问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”SpringCloud怎么将Eureka Server集群化”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

十多年的武汉网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整武汉建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“武汉网站设计”,“武汉网站推广”以来,每个客户项目都认真落实执行。

一、准备工作

Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. Infact, this is the default behaviour, so all you need to do to make it work is add a valid serviceUrl to a peer, e.g.——摘自官网

Eureka通过运行多个实例,使其更具有高可用性。事实上,这是它默认的熟性,你需要做的就是给对等的实例一个合法的关联serviceurl。

这篇文章我们基于第一篇文章的工程,来做修改。

二、改造工作

在eureka-server工程中resources文件夹下,创建配置文件application-peer1.yml:

server:
  port: 8761
spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2:8769/eureka/

并且创建另外一个配置文件application-peer2.yml:

server:
  port: 8769
spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/

这时eureka-server就已经改造完毕。

ou could use this configuration to test the peer awareness on a single host (there’s not much value in doing that in production) by manipulating /etc/hosts to resolve the host names.

按照官方文档的指示,需要改变etc/hosts,linux系统通过vim /etc/hosts ,加上:

127.0.0.1 peer1
127.0.0.1 peer2

windows电脑,在c:/windows/systems/drivers/etc/hosts 修改。

这时需要改造下service-hi:

eureka:
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/
server:
  port: 8762
spring:
  application:
    name: service-hi

三、启动工程
启动eureka-server:

java -jar eureka-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1

SpringCloud怎么将Eureka Server集群化

启动service-hi:

java -jar service-hi-0.0.1-SNAPSHOT.jar

访问:localhost:8761,如图:

SpringCloud怎么将Eureka Server集群化

你会发现注册了service-hi,并且有个peer2节点,同理访问localhost:8769你会发现有个peer1节点。

client只向8761注册,但是你打开8769,你也会发现,8769也有 client的注册信息。

个人感受:这是通过看官方文档的写的demo ,但是需要手动改host是不是不符合Spring Cloud 的高上大?

Prefer IP Address

In some cases, it is preferable for Eureka to advertise the IP Adresses of services rather than the hostname. Set eureka.instance.preferIpAddress to true and when the application hostname.——摘自官网

eureka.instance.preferIpAddress=true是通过设置ip让eureka让其他服务注册它。也许能通过去改变去通过改变host的方式。

此时的架构图:

SpringCloud怎么将Eureka Server集群化

Eureka-eserver peer1 8761,Eureka-eserver peer2 8769相互感应,当有服务注册时,两个Eureka-eserver是对等的,它们都存有相同的信息,这就是通过服务器的冗余来增加可靠性,当有一台服务器宕机了,服务并不会终止,因为另一台服务存有相同的数据。

到此,关于“SpringCloud怎么将Eureka Server集群化”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


文章名称:SpringCloud怎么将EurekaServer集群化
当前网址:http://ybzwz.com/article/popsip.html