3.3 搭建Eureka注册中心
3.3.1 搭建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
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)
配置启动类
在
cn.itcast.eureka
下创建启动类
EurekaServerApplication
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
EnableEurekaServer : 激活Eureka Server端配置
打开浏览器访问
http://localhost:8761
即可进入
EurekaServer
内置的管理控制台
,
显示效果如下
下一篇:服务注册到Eureka