服务注册中心Eureka Server,是一个实例,当成千上万个服务向它注册的时候,它的负载是非常高的,这在生产环境上是不太合适的,这篇文章主要介绍怎么将Eureka Server集群化。
Eureka通过运行多个实例,使其更具有高可用性。事实上,这是它默认的属性,我们需要做的就是给对等的实例一个合法的关联: serviceurl。
一、修改项目做法如下:
在eureka(我的是msa-registry)工程中resources文件夹下,创建配置文件application-peer1.yml
创建另外一个配置文件application-peer2.yml
eureka就已经改造完毕。
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:
java -jar msa-registry.jar --spring.profiles.active=peer1
java -jar msa-registry.jar --spring.profiles.active=peer2
启动service-hi:
java -jar service-hi-0.0.1-SNAPSHOT.jar
登录自己的localhost:8761 和 localhost:8760 看到都有注册的自己的微服务项目。
本章节为自己项目案例,仅供参考,请勿复制粘贴。
参考实践出处博客: https://blog.csdn.net/forezp/article/details/70148833/
复制请注明出处: https://blog.csdn.net/Mynah886