上一篇博客我们讲述了 Eureka 这个服务注册组件,接下来我们去搭建一下 Eureka Server 注册中心。
一、搭建 Eureka Server
模块名称:microservice-eureka-server-2000
我们使用该模块当做我们的服务注册中心,到时候让其他的子服务注册到 Eureka 中。
pom 配置
<dependencies>
<!-- Eureka Server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
application.yml 配置
server:
port: 2000
servlet:
context-path: /
eureka:
instance:
# eureka注册中心实例名称
hostname: localhost
client:
# false 由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己。
register-with-eureka: false
# false 由于注册中心的职责就是维护服务实例,它并不需要去检索服务,所以也设置为false
fetch-registry: false
#设置与Eureka注册中心交互的地址,查询服务和注册服务用到(这里是单机模式)
service-url:
defaultZone: http://localhost:2000/eureka/
最后我们再弄个启动类
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
启动类中我们主要是增加一个注解:@EnableEurekaServer,该注解为 Eureka Server 的声明。
二、启动 Eureka Server
启动 Eureka Server 之后,我们可以去 Eureka 的控制台看看。
地址:http://localhost:2000/ 这里的这个端口我用的就是 2000。
进去之后,就可以看到这个界面,这个就是 Eureka 的控制台。
这一讲就讲到这里,有问题可以联系我:QQ 2100363119,欢迎大家访问我的个人网站:https://www.lemon1234.com
最近网站已经做好,并且已经上线,欢迎各位留言~~