贵州省住房和城乡建设厅网站报名网,百度文库网页版登录入口,如何做wordpress主题,wordpress要钱么SpringCloud------Eureka修改实例显示信息、服务发现Discovery、自我保护#xff08;六#xff09;
1.actuator微服务信息完善 2.服务发现Discovery 3.Eureka自我保护
actuator微服务信息完善
web和actuator依赖用于图形化监控
1.主机名称#xff1a;服务名称修改
新增…SpringCloud------Eureka修改实例显示信息、服务发现Discovery、自我保护六
1.actuator微服务信息完善 2.服务发现Discovery 3.Eureka自我保护
actuator微服务信息完善
web和actuator依赖用于图形化监控
1.主机名称服务名称修改
新增instance-id
eureka:client:register-with-eureka: true # 表示是否将自己注册进EurekaServer默认为true# 是否从EurekaServer抓取已有的注册信息,默认为true,单节点无所谓,集群必须为true,才能配合ribbon使用负载均衡fetch-registry: trueservice-url:#defaultZone: http://localhost:7001/eureka#defaultZone: http://eureka7001.com/7001/eureka,http://eureka7002.com/7002/eurekadefaultZone: http://localhost:7001/eureka,http://localhost:7002/eurekainstance:instance-id: payment8001 #8002的改为payment8002修改完重启后
健康检查
点击对应的服务名 会进入对应的地址 http://01za3zd23001166.corp.haier.com:8001/actuator/info 改为health: http://01za3zd23001166.corp.haier.com:8001/actuator/health 会打印出 {“status”:“UP”}
2.访问信息有IP信息提示 instance:instance-id: payment8001prefer-ip-address: true # 访问路径可以显示IP地址如图所示
服务发现Discovery
对于注册进eureka里面的微服务可以通过服务发现来获得该服务的信息。 对于服务提供者Controller进行改造 新增如下代码
import org.springframework.cloud.client.discovery.DiscoveryClient;Resourceprivate DiscoveryClient discoveryClient;GetMapping(/discovery)public Object discovery(){/*** 获取服务清单列表*/ListString services discoveryClient.getServices();for (String element:services){log.info(***element:*element);}/*** 服务名获取这个服务下多个实例*/ListServiceInstance instances discoveryClient.getInstances(CLOUD-PAYMENT-SERVICE);for (ServiceInstance instance:instances){// 实例id/实例IP/实例端口/实例的urllog.info(instance.getInstanceId() 。instance.getHost()。instance.getPort()。instance.getUri());}return this.discoveryClient;}接下来在对生产者的启动类新增 EnableDiscoveryClient注解
SpringBootApplication
EnableEurekaClient
EnableDiscoveryClient
public class PaymentMain8001 {public static void main(String[] args) {SpringApplication.run(PaymentMain8001.class,args);}
}
调用该接口测试效果如图 返回结果 { “services”: [ “cloud-payment-service”, “cloud-consumer-service” ], “order”: 0 } Eureka自我保护
保护模式主要用于一组客户端和Eureka Server之间存在网络分区场景下的保护。 一旦进入保护模式Eureka Server将会尝试保护其服务注册表中的信息不再删除服务注册表中的数据也就是不会注销任何微服务。 如果Eureka Serve页面中看到如下信息说明Eureka进入了保护模式
意思是 某一时刻某个微服务不可用了Eureka不会立刻清理依旧会对该微服务的信息进行保存。 属于CAP理论中的AP分支 设计原因 为了防止Client可以正常运行但是Eureka Server网络不通情况下Eureka Server不会立刻将Client服务剔除。 默认时间是90s 简单地说就是防止因为网络原因错误注销正常的服务。 宁可保护错误的服务注册信息也不盲目注销任何可能健康的服务实例 如何禁止自我保护
修改注册端的配置
默认开启自我保护 eureka.server.enable-self-preservation: true 默认为true开启 eviction-interval-timer-in-ms: 2000 # 心跳时间改为2s,2000毫秒 改为false即可禁止自我保护。
eureka:client:register-with-eureka: true # 表示是否将自己注册进EurekaServer默认为true# 是否从EurekaServer抓取已有的注册信息,默认为true,单节点无所谓,集群必须为true,才能配合ribbon使用负载均衡fetch-registry: trueservice-url:#defaultZone: http://localhost:7001/eureka#defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eurekadefaultZone: http://localhost:7001/eureka# ,http://localhost:7002/eurekaserver:enable-self-preservation: false # 禁用自我保护eviction-interval-timer-in-ms: 2000 # 心跳时间改为2s,2000毫秒客户端同样可以修改发送心跳时间间隔 lease-renewal-interval-in-seconds: 10 #默认为30s,发送一次心跳, 修改客户端向服务器端发送心跳的时间间隔,单位为秒 lease-expiration-duration-in-seconds: 2 #eureka服务器端在收到最后一次心跳后等待时间的上线,单位为秒默认为90s # 超时将剔除服务 eureka:client:register-with-eureka: true # 表示是否将自己注册进EurekaServer默认为true# 是否从EurekaServer抓取已有的注册信息,默认为true,单节点无所谓,集群必须为true,才能配合ribbon使用负载均衡fetch-registry: trueservice-url:#defaultZone: http://localhost:7001/eureka#defaultZone: http://eureka7001.com/7001/eureka,http://eureka7002.com/7002/eurekadefaultZone: http://localhost:7001/eureka# ,http://localhost:7002/eurekainstance:instance-id: payment8001prefer-ip-address: true # 访问路径可以显示IP地址lease-renewal-interval-in-seconds: 1 #默认为30s,发送一次心跳, 修改客户端向服务器端发送心跳的时间间隔,单位为秒lease-expiration-duration-in-seconds: 2 #eureka服务器端在收到最后一次心跳后等待时间的上限,单位为秒默认为90s# 超时将剔除服务以上是Eureka的全部内容。
Eureka停更后怎么办
切换其他的注册中心或者继续使用。 目前是停更不停用的阶段。 https://github.com/Netflix/eureka/wiki 2.0以后就不再更新 1.x依然是一个活动的工程