首先创建springboot应用
Eureka 提供基于REST的服务,在集群中主要用于服务管理。Eureka 提供了基于 Java语言的客户组件,客户端组件实现了负载均衡的功能,为业务组件的集群部署创造了条件。使用该框架,可以将业务组件注册到Eureka容器中,这些组件可进行集群部署,Eureka 主要维护这些服务列表并自动检查它们的状态.
Eureka 服务端
查看官方文档
EurekaServerApplication
给启动层添加注解
@SpringBootApplication
@EnableEurekaServer #新增
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
application.yml
配置相关参数
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
#声明自己是一个服务器
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
启动,访问查看
http://localhost:8761/