Spring Cloud中,Eureka常见问题总结。
指定Eureka的Environment
|
|
参考文档:https://github.com/Netflix/eureka/wiki/Configuring-Eureka
指定Eureka的DataCenter
|
|
参考文档:https://github.com/Netflix/eureka/wiki/Configuring-Eureka
文中指出,配置-Deureka.datacenter=cloud,这样eureka将会知道是在AWS云上。
如何解决Eureka注册服务慢的问题
使用配置项:
|
|
参考文档:
http://cloud.spring.io/spring-cloud-static/Camden.SR1/#_why_is_it_so_slow_to_register_a_service
原文:
|
|
翻译:
|
|
Eureka的自我保护模式
如果在Eureka Server的首页看到以下这段提示,则说明Eureka已经进入了保护模式。
|
|
保护模式主要用于一组客户端和Eureka Server之间存在网络分区场景下的保护。一旦进入保护模式,Eureka Server将会尝试保护其服务注册表中的信息,不再删除服务注册表中的数据(也就是不会注销任何微服务)。
详见:https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication
如何解决Eureka Server不踢出已关停的节点的问题
在开发过程中,我们常常希望Eureka Server能够迅速有效地踢出已关停的节点,但是新手由于Eureka自我保护模式,以及心跳周期长的原因,常常会遇到Eureka Server不踢出已关停的节点的问题。解决方法如下:
(1) Eureka Server端:配置关闭自我保护,并按需配置Eureka Server清理无效节点的时间间隔。
|
|
(2) Eureka Client端:配置开启健康检查,并按需配置续约更新时间和到期时间。
|
|
示例:
服务器端配置:
|
|
客户端配置:
|
|
注意:
更改Eureka更新频率将打破服务器的自我保护功能,生产环境下不建议自定义这些配置。
详见:https://github.com/spring-cloud/spring-cloud-netflix/issues/373
自定义Eureka的Instance ID
在Spring Cloud中,服务的Instance ID的默认值是${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}}
,也就是机器主机名:应用名称:应用端口
。因此在Eureka Server首页中看到的服务的信息类似如下:itmuch:microservice-provider-user:8000
。如果想要自定义这部分的信息怎么办?
示例:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true
instance-id: ${spring.cloud.client.ipAddress}:${server.port} # 将Instance ID设置成IP:端口的形式
Eureka配置最佳实践参考
https://github.com/spring-cloud/spring-cloud-netflix/issues/203
注意点:eureka.client.healthcheck.enabled=true配置项必须设置在application.yml中
eureka.client.healthcheck.enabled=true
只应该在application.yml中设置。如果设置在bootstrap.yml中将会导致一些不良的副作用,例如在Eureka中注册的应用名称是UNKNOWN等。
以上内容转自:http://www.itmuch.com/spring-cloud-sum-eureka/
持续更新中ing...
SpringBoot的Admin端,邮件提醒Maven包引入问题
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.netflix.governator.annotations.binding.Primary;
import de.codecentric.boot.admin.notify.Notifier;
import de.codecentric.boot.admin.notify.RemindingNotifier;
/**
*
* @Title: 为监控的服务添加邮件通知
* @Package com.lovnx
* @author yezhiyuan
* @date 2017年6月14日 上午10:18:13
* @version V1.0
*/
@Configuration
@EnableScheduling
public class NotifierConfiguration {
@Autowired
private Notifier notifier;
//服务上线或者下线都通知
private String[] reminderStatuses = { "DOWN" };
@Bean
@Primary
public RemindingNotifier remindingNotifier() {
RemindingNotifier remindingNotifier = new RemindingNotifier(notifier);
//设定时间,5分钟提醒一次
// remindingNotifier.setReminderPeriod(TimeUnit.MINUTES.toMillis(5));
//设定监控服务状态,状态改变为给定值的时候提醒
remindingNotifier.setReminderStatuses(reminderStatuses);
return remindingNotifier;
}
// @Scheduled(fixedRate = 60_000L)
// public void remind() {
// remindingNotifier().sendReminders();
// }
}
com.netflix.governator.annotations.binding.Primary <--无法找到
在Idea编辑器内就算引入了如下包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
也会有无法找到的情况,需要引入。但是在Eclipse或STS内无此问题
<dependency>
<!--
add by rock.jiang
添加如下引用不好用,因为依赖太少无法编译通过
<groupId>com.netflix.governator</groupId>
<artifactId>governator</artifactId>
<version>1.9.3</version>
以下版本尝试过过1.9.3/1.10.5都可以编译通过,之后的版本无法编译通过
-->
<groupId>com.netflix.governator</groupId>
<artifactId>governator-annotations</artifactId>
<version>1.10.5</version>
</dependency>