企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
集群是在不同的机器上面<mark>配置相同的服务</mark>对外做一个超大运算的整体。 <br/> 对于集群要有高可用性,所以需要配置多个Eureka注册中心,防止当其中某一个Eurera注册机器宕机时不能够对外提供服务。 <br/> 搭建步骤如下: **1. 搭建思路** 先搭建三个Eureka注册中心,然后分别往这三个Eureka中注册 8001 微服务。 ``` 三个Eureka服务注册中心我已经提前搭建好了,模块名称如下: cloud-eureka-server7001 cloud-eureka-server7002 cloud-eureka-server7003 ``` **2. 三个Eureka注册中心的`resource/application.yml`** (1)7001注册中心配置。 ```yml server: port: 7001 spring: application: name: cloud-eureka-server eureka: instance: hostname: www.eureka7001.com client: fetch-registry: false register-with-eureka: false service-url: #将其它两个注册中心的注册地址配置到当前模块 #当前模块的注册地址不用写 defaultZone: http://www.eureka7002.com:7002/eureka/,http://www.eureka7003.com:7003/eureka/ server: enable-self-preservation: false eviction-interval-timer-in-ms: 2000 ``` (2)7002注册中心配置。 ```yml server: port: 7002 spring: application: name: cloud-eureka-server eureka: instance: hostname: www.eureka7002.com client: register-with-eureka: false fetch-registry: false service-url: #将其它两个注册中心的注册地址配置到当前模块 #当前模块的注册地址不用写 defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7003.com:7003/eureka/ server: enable-self-preservation: false eviction-interval-timer-in-ms: 2000 ``` (3)7003注册中心配置。 ```yml server: port: 7003 spring: application: name: cloud-eureka-server eureka: instance: hostname: www.eureka7003.com client: register-with-eureka: false fetch-registry: false service-url: #将其它两个注册中心的注册地址配置到当前模块 #当前模块的注册地址不用写 defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7002.com:7002/eureka/ server: enable-self-preservation: false eviction-interval-timer-in-ms: 2000 ``` **3. 将 8001 微服务注册到三个Eureka注册中心中** `resources/application.yml` ```yml server: port: 8001 spring: application: name: cloud-payment-service eureka: client: service-url: #eureka提供的注册中心地址 defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7002.com:7002/eureka/,http://www.eureka7003.com:7003/eureka/ instance: instance-id: ${project.artifactId} prefer-ip-address: true lease-renewal-interval-in-seconds: 1 lease-expiration-duration-in-seconds: 2 ####actuator#### info: app.name: ${spring.application.name} company.name: www.atguigu.com build.artifactId: ${project.artifactId} build.version: ${project.version} ``` **4. 验证集群是否搭建成功** (1)先分别启动三个Eureka注册中心,然后再启动 8001微服务。 分别访问三个Eureka注册中心,可以看到每个Eureka除了自己外,还有两个备用的,并且8001这个微服务都入住了三个Eureka注册中心。 <br/> :-: ![](https://img.kancloud.cn/0f/8b/0f8b6ec89dca50811a85fba62b4c7cad_1514x444.jpg) http://www.eureka7001.com:7001/ ![](https://img.kancloud.cn/72/e4/72e43c73ef4aadb38da9d0f6aa5a4e34_1511x439.jpg) http://www.eureka7002.com:7002/ ![](https://img.kancloud.cn/87/be/87beabbe384f2baef37088e5ab5b74e1_1493x471.jpg) http://www.eureka7003.com:7003/