微服务:使用Eureka构建集群

官方文档内容如下:

Peer Awareness

Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. In fact, 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.

application.yml (Two Peer Aware Eureka Servers)
---
spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2/eureka/

---
spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1/eureka/

In this example we have a YAML file that can be used to run the same server on 2 hosts (peer1 and peer2), by running it in different Spring profiles. You 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. In fact, the eureka.instance.hostname is not needed if you are running on a machine that knows its own hostname (it is looked up using java.net.InetAddress by default).

You can add multiple peers to a system, and as long as they are all connected to each other by at least one edge, they will synchronize the registrations amongst themselves. If the peers are physically separated (inside a data centre or between multiple data centres) then the system can in principle survive split-brain type failures.

微服务:Eureka+Zuul+Ribbon+Feign+Hystrix构建微服务架构章节中我们搭建了一个单例的微服务,但是如何搭建一个集群式的微服务呢?

本节演示如何搭建一个Eureka集群,开篇附官方eureka服务器的集群配置。

这里拿出我自己的配置文件
One Eureka Server Profile
这里的主机名称切勿当真,理解其本质即可!!!

#集群模式启动Eureka Server
spring: 
  application:
    name: windowHost-EurekaServer
server:
  port: 8761 #启动端口
eureka: #向另一个Eureka Server注册自己为一个Client
  hostname: windowHost #指定本机器的主机名
  client:
    serviceUrl:
      defaultZone: http://hadoopMaster:${server.port:8761}/eureka/ #去主机名未hadoopMaster的Eureka服务器,将自己注册为一个客户端

注意:eureka.client.serviceUrl—我理解的含义将该Eureka Server做为一个Client注册中服务地址为:http://hadoopMaster:${server.port:8761}/eureka/ 的服务器上,当然在另一个服务器上同样的就应该复制该主机地址,这样就构成了双向的通信机制

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值