springcloud宕机问题

任何服务器都有宕机的危险,而springcloud简单的解决了这个问题。
用通俗的话来说就是完成了:你中有我,我中有你。
假如有两台服务器A,B。正常情况下A工作,当发生A宕机时,B工作。
我们只需要完成将A注册到B,将B注册到A即可
所以我们只需要修改两个springcloud的application.yml即可。
A:端口8761

server:
  port: 8761
spring:
   application:
      name: app-itmayiedu-order
  
eureka:
  instance:
  ###注册中心ip地址
    hostname: 127.0.0.1
  client:
    serverUrl: 
      defaultZone: http://${eureka.instance.hostname}:8861/eureka/ 
       ###如果有三台服务器,这里就要写其他两台
    register-with-eureka: true
    fetch-registry: true

B:端口8861

server:
  port: 8861
spring:
  application: 
    name: app-itmayiedu-order
eureka:
  instance:
  ###注册中心ip地址
    hostname: 127.0.0.1
  client:
    serverUrl: 
      defaultZone: http://${eureka.instance.hostname}:8761/eureka/
    register-with-eureka: true
    fetch-registry: true

这样即完成了服务器宕机时的转移

当然开启A时,必然会报错,因为找不到B,但不影响,继续开启B,然后在A的Application中看到B
A:8761
在这里插入图片描述
B:8861
在这里插入图片描述

此时我们开启一个微服务来测试下
A:8761在这里插入图片描述
B:8861在这里插入图片描述

现在关闭A服务,即宕机
在这里插入图片描述
此时他就在B服务中出现了 (注意,这个不是实时的,会有一定的延迟)
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44714808/article/details/89390107