『互联网架构』软件架构-eureka集群(99)
source link: https://www.tuicool.com/articles/ZZfIb2m
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
eureka之前演示的图片就是集群的,但是没有说如何配置eureka集群的配置方式,这次说下eureka集群的配置。
源码:https://github.com/limingios/netFuture/tree/master/源码/『互联网架构』软件架构-eureka集群(99)/
(一)eureka集群
上图是来自eureka的官方架构图,这是基于集群配置的eureka
- 处于不同节点的eureka通过Replicate进行数据同步
- Application Service为服务提供者
- Application Client为服务消费者
- Make Remote Call完成一次服务调用
服务启动后向Eureka注册,Eureka Server会将注册信息向其他Eureka Server进行同步,当服务消费者要调用服务提供者,则向服务注册中心获取服务提供者地址,然后会将服务提供者地址缓存在本地,下次再调用时,则直接从本地缓存中取,完成一次调用。
源码:08-ms-eureka-server-ha
引入依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
application.yml配置如下(见配置文件application-ha.yml)
spring: application: name: microservice-eureka-server-ha --- spring: profiles: peer1 # 指定profile=peer1 server: port: 8761 eureka: instance: hostname: peer1 # 指定当profile=peer1时,主机名是peer1 client: serviceUrl: defaultZone: http://peer2:8762/eureka/,http://peer3:8763/eureka/ # 将自己注册到peer2这个Eureka上面去 --- spring: profiles: peer2 server: port: 8762 eureka: instance: hostname: peer2 client: serviceUrl: defaultZone: http://peer1:8761/eureka/,http://peer3:8763/eureka/ --- spring: profiles: peer3 server: port: 8763 eureka: instance: hostname: peer3 client: serviceUrl: defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/
配置host文件修改:127.0.0.1 peer1 peer2 peer3
-
用jar包方式启动:
> java -jar 项目的jar包 –spring.profiles.active=peer1
java -jar 项目的jar包 –spring.profiles.active=peer2
java -jar 项目的jar包 –spring.profiles.active=peer3
PS:集群其实很好配置,选择点的时候是相互的。A点需要配置B和C点,B点需要配置A和C点,C点配置A和B点。
>>原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!
>>原文链接地址:上一篇:已是最新文章
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK