Spring|1 Spring Cloud微服务入门之 服务注册中心Eureka

  1. 新建cloud-eureka-server7001模块作为微服务注册中心
  2. 修改POM加入依赖包
org.springframework.cloud spring-cloud-starter-netflix-eureka-server com.albert.springcloud cloud-api-common ${project.version} org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-devtools >runtime true org.projectlombok lombok org.springframework.boot spring-boot-starter-test

  1. 修改YML
server: port: 7001eureka: instance: hostname: eureka7001.com#eureka 服务实例名 client: # false 表示不会像注册中心注册自己 register-with-eureka: false # false 表示自己端就是就是服务注册中心,我的职责是维护服务的实例,并不需要取检索服务 fetch-registry: false service-url: # 设置与Eureka server 交互的地址查询服务和注册服务都需要依赖这个地址 defaultZone: http://eureka7002.com:7002/eureka

  1. 写主启动类添加注解
/** * @auther cyq * @create 21:57 2020/6/9 */ @SpringBootApplication @EnableEurekaServer public class EurekaMain7001 { public static void main(String[] args) { SpringApplication.run(EurekaMain7001.class,args); } }

  1. 启动
    Spring|1 Spring Cloud微服务入门之 服务注册中心Eureka
    文章图片
    7. 相关说明
    * 抓的这张图,我已经注册了三个微服务进去,所以application下面会有内容,微服务如何注册进入Eureka注册中心,下一篇讲
    * yml中参数说明 ->defaultZone: http://eureka7002.com:7002/eureka这是我的另一个注册中心微服务,在这里我将他们搭建为一个Eureka集群,提高可用性。
    * eureka7001.com和eureka7001.com实质是127.0.0.1需要在C:\Windows\System32\drivers\etc找到host将其添加映射,如下:
    * Spring|1 Spring Cloud微服务入门之 服务注册中心Eureka
    文章图片
    8. 工程案例地址https://gitee.com/albertchen521/cloud2020

    推荐阅读