单节点配置
- 新建项目
- 勾选Spring Web、Eureka Server
- application.yml配置
server:
port: 7000
spring:
application:
# 项目名称/微服务节点名称。
# 若有第二个微服务节点启动,也配置为eurekaServer,springcloud会认为它也是eurekaServer这个微服务的一个节点
name: eurekaServer
eureka:
instance:
#注册服务器名称
hostname: eurekaServer
client:
#是否自动拉去注册中心服务列表,默认true,该项目维护服务实例用,无需拉取服务列表
fetch-registry: false
#是否将当前服务注册到注册中心,默认true,该项目本身就是服务治理中心,所以不用注册
register-with-eureka: false
service-url:
# 服务中心的域,用来提供给别的微服务注册
defaultZone: http://localhost:7000/eureka/
注意:这里的的defaultZone的值,必须是以eureka结尾,否则会报错(was unable to refresh its cache! status = Cannot execute request on any known server)
- 添加服务端注解 @EnableEurekaServer
package com.springcloud.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
*
* @date 2020/7/25 12:12
* @author wei.heng
*/
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer01Application {
public static void main(String[] args) {
SpringApplication.run(EurekaServer01Application.class, args);
}
}
5、启动服务注册中心
至此,单节点的Eureka服务注册中心配置完毕
后面会再更新多节点高可用的方案