SpringCloud-Eureka注册中心
SpringCloud-Eureka注册中心
eureka注册中心
- 添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
- 注解启用
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
- 修改配置
- 单点模式
server: port: 8001 #指定运行端口 spring: application: name: eureka-server #指定服务名称 eureka: instance: hostname: 127.0.0.1 #指定主机地址 client: serviceUrl: defaultZone: http://127.0.0.1:8001/eureka/ # 配置注册中心地址 注册到另一个Eureka注册中心 fetch-registry: false #指定是否要从注册中心获取服务(注册中心不需要开启) register-with-eureka: false #指定是否要注册到注册中心(注册中心不需要开启) server: enable-self-preservation: false #关闭保护模式
- 集群模式
- 配置文件 application-reg1.yml
server: port: 8001 spring: application: name: ism-register #服务名称 eureka: instance: hostname: 127.0.0.1 client: serviceUrl: defaultZone: http://127.0.0.1:8002/eureka/,http://127.0.0.1:8003/eureka/ # 配置注册中心地址 注册到另一个Eureka注册中心 fetch-registry: true #获取注册实例列表 register-with-eureka: true # 注册到Eureka的注册中心
- 配置文件 application-reg2.yml
- 配置文件 application-reg3.yml