ToB企服应用市场:ToB评测及商务社交产业平台

标题: 03. 微服务 - 集群搭建 - Eureka(二) [打印本页]

作者: 勿忘初心做自己    时间: 2025-1-5 23:28
标题: 03. 微服务 - 集群搭建 - Eureka(二)
媒介

   基于上一篇文章搭建Eureka集群服务
实现3个eureka server节点数据同步
记录搭建过程中的的问题及疑问
  Spring Cloud Eureka利用手册
Eureka Wiki
Eureka集群架构



预备工作


  1. # Copyright (c) 1993-2009 Microsoft Corp.
  2. #
  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  4. #
  5. # This file contains the mappings of IP addresses to host names. Each
  6. # entry should be kept on an individual line. The IP address should
  7. # be placed in the first column followed by the corresponding host name.
  8. # The IP address and the host name should be separated by at least one
  9. # space.
  10. #
  11. # Additionally, comments (such as these) may be inserted on individual
  12. # lines or following the machine name denoted by a '#' symbol.
  13. #
  14. # For example:
  15. #
  16. #      102.54.94.97     rhino.acme.com          # source server
  17. #       38.25.63.10     x.acme.com              # x client host
  18. # localhost name resolution is handled within DNS itself.
  19. #        127.0.0.1       localhost
  20. #        ::1             localhost
  21. 127.0.0.1       activate.navicat.com
  22. 127.0.0.1                eureka-server-1
  23. 127.0.0.1                eureka-server-2
  24. 127.0.0.1                eureka-server-3
复制代码
父级模块dingsu-eureka-cluster


  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5.     <modelVersion>4.0.0</modelVersion>
  6.     <parent>
  7.         <groupId>com.hd</groupId>
  8.         <artifactId>confucius</artifactId>
  9.         <version>0.0.1</version>
  10.     </parent>
  11.     <artifactId>dingsu-eureka-cluster</artifactId>
  12.     <packaging>pom</packaging>
  13.     <modules>
  14.         <module>eureka-server-1</module>
  15.         <module>eureka-server-2</module>
  16.         <module>eureka-server-3</module>
  17.     </modules>
  18.     <properties>
  19.         <maven.compiler.source>8</maven.compiler.source>
  20.         <maven.compiler.target>8</maven.compiler.target>
  21.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  22.     </properties>
  23.     <dependencies>
  24.         <dependency>
  25.             <groupId>org.springframework.cloud</groupId>
  26.             <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  27.         </dependency>
  28.     </dependencies>
  29. </project>
复制代码
eureka Server 1设置


  1. spring:
  2.   application:
  3.     name: confucius-eureka-server # 注册到Eureka的实例名称,Application列
  4. server:
  5.   port: 4311
  6. eureka:
  7.   server:
  8.     #关闭自我保护,默认为true
  9.     enable-self-preservation: false
  10.     # 清理间隔 ms,默认60*1000
  11.     eviction-interval-timer-in-ms: 30000
  12.   instance:
  13.     #注册实例名称,非ip注册时的副本名称
  14.     hostname: eureka-server-1
  15.     #是否将自己的ip注册到eureka中,默认false
  16.     prefer-ip-address: false
  17.   client:
  18.     #是否作为客户端,注册自己到eureka server中
  19.     register-with-eureka: true
  20.     # 是否作为客户端,拉取其他服务
  21.     fetch-registry: true
  22.     service-url:
  23.       defaultZone: http://eureka-server-2:4322/eureka,http://eureka-server-3:4333/eureka
  24. logging:
  25.   config: classpath:logback.xml
复制代码
eureka Server 2设置


  1. spring:
  2.   application:
  3.     name: confucius-eureka-server # 注册到Eureka的实例名称,Application列
  4. server:
  5.   port: 4322
  6. eureka:
  7.   server:
  8.     #关闭自我保护,默认为true
  9.     enable-self-preservation: false
  10.     # 清理间隔 ms,默认60*1000
  11.     eviction-interval-timer-in-ms: 30000
  12.   instance:
  13.     #注册实例名称,非ip注册时的副本名称
  14.     hostname: eureka-server-2
  15.     #是否将自己的ip注册到eureka中,默认false
  16.     prefer-ip-address: false
  17.   client:
  18.     #是否作为客户端,注册自己到eureka server中
  19.     register-with-eureka: true
  20.     # 是否作为客户端,拉取其他服务
  21.     fetch-registry: true
  22.     service-url:
  23.       defaultZone: http://eureka-server-1:4311/eureka,http://eureka-server-3:4333/eureka
  24. logging:
  25.   config: classpath:logback.xml
复制代码
eureka Server 3设置


  1. spring:
  2.   application:
  3.     name: confucius-eureka-server # 注册到Eureka的实例名称,Application列
  4. server:
  5.   port: 4333
  6. eureka:
  7.   server:
  8.     #关闭自我保护,默认为true
  9.     enable-self-preservation: true
  10.     # 清理间隔 ms,默认60*1000
  11.     eviction-interval-timer-in-ms: 30000
  12.   instance:
  13.     #注册实例名称,非ip注册时的副本名称
  14.     hostname: eureka-server-3
  15.     #是否将自己的ip注册到eureka中,默认false
  16.     prefer-ip-address: false
  17.   client:
  18.     #是否作为客户端,注册自己到eureka server中
  19.     register-with-eureka: true
  20.     # 是否作为客户端,拉取其他服务
  21.     fetch-registry: true
  22.     service-url:
  23.       defaultZone: http://eureka-server-1:4311/eureka,http://eureka-server-2:4322/eureka
  24. logging:
  25.   config: classpath:logback.xml
复制代码
运行状态


无效副本(unavailable-replicas)问题