搭建Eureka注册中心
搭建Eureka服务中心
(1) 创建shop_eureka_server子模块
在 shop_parent 下创建子模块 shop_eureka_server
(2) 引入maven坐标
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
(3) 配置application.yml
server: port: 8761 eureka: instance: hostname: localhost client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
registerWithEureka: 是否将自己注册到Eureka服务中,本身就是所有无需注册
fetchRegistry : 是否从Eureka中获取注册信息
serviceUrlEureka: 客户端与Eureka服务端进行交互的地址
(4) 配置启动类
在 com.yyj.eureka 下创建启动类 EurekaServerApplication
package com.yyj.eureka; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }
EnableEurekaServer : 激活Eureka Server端配置
服务注册中心管理后台
打开浏览器访问http://localhost:8761即可进入EurekaServer内置的管理控制台,显示效果如下: