eureka

11 篇文章 0 订阅
10 篇文章 0 订阅
本文详细介绍了如何配置Eureka服务器集群,包括Maven依赖管理、Eureka Server的配置以及Eureka Client的设置。集群间通过HTTP请求同步服务信息,确保服务注册与发现的准确性。同时对比了Eureka与Nacos在服务同步和实时性上的差异,强调Nacos的Push机制和更高效的同步策略。
摘要由CSDN通过智能技术生成

 eureka server集群

maven配置:

   
  <dependencyManagement>
        <dependencies>
            <!--引入springcloud的版本-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.1.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>

    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

eureka server1配置:

server:
  port: 8886
spring:
  application:
    name: eurakaServer1
eureka:
  instance:
    hostname: eurakaServer1-8886
  client:
    #register-with-eureka: false
    #fetch-registry: false
    serviceUrl:
      defaultZone: http://localhost:8887/eureka/,http://localhost:8888/eureka/

 eureka server2配置:

server:
  port: 8887

spring:
  application:
    name: eurakaServer2

eureka:
  instance:
    hostname: eurakaServer2-8887
  client:
    #register-with-eureka: false
    #fetch-registry: false
    serviceUrl:
      defaultZone: http://localhost:8888/eureka/,http://localhost:8886/eureka/

  eureka server3配置:

server:
  port: 8888

spring:
  application:
    name: eurakaServer3

eureka:
  instance:
    hostname: eurakaServer3-8888
  client:
    #register-with-eureka: false
    #fetch-registry: false
    serviceUrl:
      defaultZone: http://localhost:8886/eureka/,http://localhost:8887/eureka/

 集群之间的数据同步:

1、从集群其他节点创建eureka客户端,执行http://localhost:8887/eureka//apps/  拉取全量服务列表注册到本地

2、Registering application EURAKASERVER3 with eureka with status UP 注册本身到集群其他几点

3、每隔30s发送心跳:http://localhost:8887/eureka//apps/EURAKASERVER3

4、每隔30s拉取增量服务列表:http://localhost:8887/eureka//apps/delta

 eureka client

    <dependencies>
        <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>
server:
  port: 7776

spring:
  application:
    name: eurakaClient1
eureka:
  instance:
    prefer-ip-address: true # 使用服务的ip地址(下边截图有说明)
  client:
    register-with-eureka: true # 将自己注册到服务中心
    fetch-registry: true # 检索服务
    service-url:
      defaultZone: http://127.0.0.1:8888/eureka # 服务中心地址,如果是集群环境,逗号分隔地址即可。

 其实客户端可服务端启动注册,拉取服务步骤都是一样的

可以通过debug日志查看restful接口的调用:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="LOG_PATH" value="${user.dir}/../logs"/>
    <property name="appName" value="eurekaClient1"/>
    <contextName>${appName}</contextName>

    <logger name="org.apache.zookeeper" level="ERROR" />

    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_PATH}/info.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <maxFileSize>10MB</maxFileSize>
            <fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i</fileNamePattern>
            <maxHistory>7</maxHistory>
            <totalSizeCap>3GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n</pattern>
        </encoder>
    </appender>

    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <File>${LOG_PATH}/error.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/error-%d{yyyyMMdd}.log.%i</fileNamePattern>
            <maxFileSize>10MB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>3GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n</pattern>
        </encoder>
    </appender>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>
                [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n
            </pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="INFO_FILE"/>
        <appender-ref ref="STDOUT"/>
    </root>

</configuration>

与nacos区别

1、nacos不止只有pull,而且当server有服务注册/下线,则会立即push给客户端,及时性比较高

2、在nacos集群同步,是通过异步批量同步的,其实从队列里面批量拿更新的服务,超过1000则分发给集群其他节点,如果有更新没有超过1000,则5s分发,跟eureka有着明显的区别

3、eureka server 对实例的注册,发现,是通过三级缓存实现的,nacos则是通过copyOnwrite的机制实现的,nacos及时性比eureka高

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值