企业分布式微服务云SpringCloud SpringBoot mybatis (十)高可用的服务注册中心

文章介绍了服务注册与发现,其中服务注册中心Eureka Server,是一个实例,当成千上万个服务向它注册的时候,它的负载是很是高的,这在生产环境上是不太合适的,这篇文章主要介绍怎么将Eureka Server集群化。html

1、准备工做

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.linux

摘自官网spring

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

这篇文章咱们基于第一篇文章的工程,来作修改。windows

2、改造工做

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

1
2
3
4
5
6
7
8
9
10
11
server:
port: 8761
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http: //peer2:8769/eureka/

  而且建立另一个配置文件application-peer2.yml:app

1
2
3
4
5
6
7
8
9
10
11
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 ,加上:this

1
2
127.0 . 0.1 peer1
127.0 . 0.1 peer2

  

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

这时须要改造下service-hi:

1
2
3
4
5
6
7
8
9
eureka:
client:
serviceUrl:
defaultZone: http: //peer1:8761/eureka/
server:
port: 8762
spring:
application:
name: service-hi

  架构代码以下:

"分布式b2b <wbr

资料和源码来源地址

Spring Cloud大型企业分布式微服务云架构源码请加企鹅求求:一七九一七四三三八零

相关文章
相关标签/搜索