1. 工程结构
为了演示方便所以建三个工程,实际生产是一个工程配置三份,端口不同
- 服务注册中心1 eureka-server-7001
- 服务注册中心2 eureka-server-7002
- 服务注册中心3 eureka-server-7003
2. 共同配置
2.1 pom文件
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
2.2 主启动类
分别对应工程改成EurekaServer7001Application、EurekaServer7002Application、EurekaServer7003Application
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer7001Application {
public static void main(String[] args) {
SpringApplication.run(EurekaServer7001Application.class, args);
}
}
3. yml配置
2.1 7001
server:
port: 7001
eureka:
instance:
hostname: eureka-server-7001
client:
registerWithEureka: false #false表示不向注册中心注册自己。
fetchRegistry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
serviceUrl:
defaultZone: http://eureka-server-7002:7002/eureka/,http://eureka-server-7003:7003/eureka/
# defaultZone: http://eureka-server-7001:7001/eureka/
2.2 7002
server:
port: 7002
eureka:
instance:
hostname: eureka-server-7002
client:
registerWithEureka: false #false表示不向注册中心注册自己。
fetchRegistry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
serviceUrl:
defaultZone: http://eureka-server-7001:7001/eureka/,http://eureka-server-7003:7003/eureka/
# defaultZone: http://eureka-server-7001:7001/eureka/
2.3 7003
server:
port: 7003
eureka:
instance:
hostname: eureka-server-7003
client:
registerWithEureka: false #false表示不向注册中心注册自己。
fetchRegistry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
serviceUrl:
defaultZone: http://eureka-server-7001:7001/eureka/,http://eureka-server-7002:7002/eureka/
# defaultZone: http://eureka-server-7001:7001/eureka/
4. 服务首页
http://eureka-server-7001:7001
http://eureka-server-7002:7002
http://eureka-server-7003:7003
本文详细介绍了如何在微服务架构中搭建Eureka集群,包括工程结构、pom文件配置、主启动类设置及yml配置细节,实现服务注册与发现功能。
1958

被折叠的 条评论
为什么被折叠?



