Service registration center eureka build

Service registration center, netfix company, debut is the peak, but unfortunately no one maintains it.
1.x is available, 2.x is used at your own risk. This article talks about the establishment of eureka service center, which is divided into stand-alone version and eureka cluster version. And how the service consumers and service providers enter the registration center.


eureka pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>cloud2020</artifactId>
        <groupId>top.bitqian</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <!-- 127.0.0.1 eureka7001.com -->
    <artifactId>cloud-eureka-server7001</artifactId>


    <dependencies>
        <!-- eureka server~ -->
        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>top.bitqian</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>

    </dependencies>


</project>

The registration center of the eureka service server, single

server:
  port: 7001

# 单机版eureka
eureka:
  instance:
    hostname: localhost  #eureka服务端的实例名字
  client:
    register-with-eureka: false    #表识不向注册中心注册自己
    fetch-registry: false   #表示自己就是注册中心,职责是维护服务实例,并不需要去检索服务
    service-url:
      defaultZone: http://${
    
    eureka.instance.hostname}:${
    
    server.port}/eureka/
      #设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址

Eureka's cluster construction

  1. Change the host file
127.0.0.1 http://eureka7001.com
127.0.0.1 http://eureka7002.com
  1. yaml mutual registration, mutual watch
server:
  port: 7001

# 服务注册集群 eureka服务注册中心地址7001
eureka:
  instance:
    hostname: eureka7001.com #eureka服务端的实例名字
  client:
    register-with-eureka: false    #表识不向注册中心注册自己
    fetch-registry: false   #表示自己就是注册中心,职责是维护服务实例,并不需要去检索服务
    service-url:
      defaultZone: http://eureka7002.com:7002/eureka/     #设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址


server:
  port: 7002

# 服务注册集群 eureka服务注册中心地址7002
eureka:
  instance:
    hostname: eureka7002.com #eureka服务端的实例名字
  client:
    register-with-eureka: false    #表识不向注册中心注册自己
    fetch-registry: false   #表示自己就是注册中心,职责是维护服务实例,并不需要去检索服务
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/     #设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址


How does the client enter the eureka cluster

  1. consumer
# 暴露80端口,消费者调用8001 支付接口
server:
  port: 80

# 服务消费者 client
spring:
  application:
    name: cloud-order-service

eureka:
  client:
    register-with-eureka: true # 是否注册到服务中心~
    fetchRegistry: true
    service-url:
      # 将80消费者服务 发布到7001, 7002端口的eureka集群服务里面
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka  #集群版

  1. Two service providers
eureka:
  client:
    register-with-eureka: true
    fetchRegistry: true
    service-url:
      # 将支付服务8001发布到7001, 7002 两台eureka集群配置中
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka  #集群版
# eureka客户端 可以又多个
eureka:
  client:
    register-with-eureka: true
    fetchRegistry: true
    service-url:
      # 将支付服务8001发布到7001, 7002 两台eureka集群配置中
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka  #集群版
 

Eureka's self-protection mechanism

eureak will not delete, and kill the services that have been down.

      # 自我保护机制出现现象: 服务客户端和eureka server之间在网络分区下进行的保护
      # 一旦进入保护模式,eureka server将会尝试保护其注册表中的信息, 不会注销掉任何微服务
      # 某个时刻某一个微服务不可用了, eureka不会进行服务清理, 会对微服务信息进行保存。
      # 为什么进行保护: 网络是不稳定的, 可能某个服务可能因为短暂的网络拥堵, 导致服务暂停了, 但是服务是健康的。 cap --> ap

Guess you like

Origin blog.csdn.net/qq_44783283/article/details/110587146