SpringCloud 篇 一 之 Eureka Server搭建


闲话不多说,直接开干。在这里,我使用的是IDEA来搭建环境,比较方便。

首先我们要明白的是:我们是服务注册中心Eureka Server ,那么我们的pom文件中是不需要多余的组件的,只需要eureka server stater

 

pom: 

<!-- 这里特别需要注意的是 parent 版本依赖需要一致,不然启动报错
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>-->
<!-- 服务注册中心 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <version>2.1.1.RELEASE</version> </dependency>

主启动类:

//开启eureka服务注册中心自动配置
@EnableEurekaServer
@SpringBootApplication
public class SpringCloudDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudDemoApplication.class, args);
    }

}

application.yml:

#配置相关eureka服务注册中心相关配置信息
eureka:
  instance:
    hostname: localhost  #eureka server 单个 主机地址就是localhost
  client:
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
    register-with-eureka: false #默认为true,ture:需要向注册中心注册自己的服务信息 false: 本身就是服务注册中心,自然不需要自己向自己注册
    fetch-registry: false          # 表示我就是服务注册中心,我的职责是维护注册的实例,不需要去检索服务
 server: port: 7001      # 端口可以自定义

当三处地方定义完成之后,我们可以启动eureka server客户端查看:  

http://${eureka.instance.hostname}:${server.port}/eureka/

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM