zoukankan      html  css  js  c++  java
  • Eureka使用总结

    Eureka

    使用eureka的步骤

    1. 搭建Eureka server

      1. 创建工程子模块

      2. 导入坐标

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
      3. 配置application.yml

        server:
          port: 9000
        eureka:
          instance:
            hostname: localhost
          client:
            register-with-eureka: false
            fetch-registry: false
            service-url:
              defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

        registerWithEureka: 是否将自己注册到Eureka服务中,本身就是所有无需注册
        fetchRegistry : 是否从Eureka中获取注册信息
        serviceUrlEureka: 客户端与Eureka服务端进行交互的地址

      4. 配置启动类(在启动类上添加注解)

        @EnableEurekaServer //激活Eureka Server端配置
      5. 启动。打开浏览器访问http://localhost8761即可进入EurekaServer内置的管理控制台

    2. 将服务提供者注册到Eureka Server上

      1. 引入Eureka Client的坐标

        <dependencies>
        <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-commons</artifactId>
        </dependency>
        <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        </dependencies>
      2. 修改application.yml添加Eureka Server的信息

        eureka:
        client:
        serviceUrl: # eureka server的路径
        defaultZone: http://localhost:8761/eureka/
        instance:
        prefer-ip-address: true #使用ip注册
      3. 修改启动类,添加服务发现的支持(可选)

        添加注解:@EnableDiscoveryClient@EnableEurekaClient

        从Spring Cloud Edgware版本开始, @EnableDiscoveryClient 或 @EnableEurekaClient 可省略。只需加上相关依赖,并进行相应配置,即可将微服务注册到服务发现组件上。

    3. 服务消费者通过注册中心获取服务列表,并调用

  • 相关阅读:
    权限管理命令
    常用命令2
    常用命令1
    queue
    poj 3984
    L3-008 喊山 (30 分)
    常州大学新生寒假训练会试 I 合成反应
    dfs 的全排列
    poj 1154
    hdu 1241
  • 原文地址:https://www.cnblogs.com/friend-c/p/15089990.html
Copyright © 2011-2022 走看看