springcloud (four): Eureka's configuration in detail

In the service management system in Eureka, divided into server and client in two different roles, the server for the service registry, the client for the provision of micro-service applications of each interface, introduced here Eureka configuration.

Eureka server configuration

In practice, we do is to configure the content of client operations, while Eureka the server is more like a ready-made product, in most cases we do not need to modify its configuration.

If you want to know, you can go to this class view org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean, server attributes are prefixed with eureka.server.

The main configuration Eureka client

Service registry configuration information, including the address of the service registry, service acquisition interval, the available area and so on.
Service instance configuration information, including the name of the service instance, IP address, port number, path and other health checks.


Class service registry configuration

Configuration information about class registration services available to view through org.springframework.cloud.netflix.eureka.EurekaClientConfigBean, configuration information prefixes are eureka.client.

Specify registration center: realized by eureka.client.serviceUrl parameter, this parameter is defined as follows, the configuration values ​​stored in the HashMap type, and has a set of default values, the default key is defaultzone, the default value is http: // localhost : 8761 / eureka. We can reset the registry by this setting: eureka.client.serviceUrl.defaultZone = http: // localhost: 1111 / eureka /. If the registry is highly available comma between multiple addresses.

private Map <String, String> serviceUrl = new HashMap <> ();
other configurations

These configurations are beginning to eureka.client

 

 

Class service instance configuration

Configuration information about the service instances of a class can be viewed in org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean class, these prefixes configuration information is eureka.instance.

Metadata

Org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean in the configuration information, the configuration has a large content of the service instance metadata, the metadata refers Eureka when the client sends a registration request to the service registry, to service information describing the object itself, which contains a number of standardized metadata, such as the service name, instance name, instance IP, strength ports.

When using Spring Cloud Eureka, all configuration information is loaded through org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean, but in the real service registration will still be packaged into com.netflix.appinfo.InstanceInfo object to the customer Eureka end. These two class definitions are very similar, in com.netflix.appinfo.InstanceInfo class Map <String, String> metadata = new ConcurrentHashMap <String, String> () custom metadata information, while others are normalized element Data information.

我们可以通过eureka.instance.<properties>=<value>的格式对标准化的元数据信息直接进行配置,其中<properties>就是EurekaInstanceConfigBean对象中的成员变量名。而对于自定义元数据,可以通过eureka.instance.metadataMap.<key>=<value>的格式进行配置,比如:

eureka.instance.metadataMap.zone=shanghai
实例名配置

它是区分同一服务不同实例的唯一标识。在Netflix Eureka的原生实现中,默认是以主机名作为默认值,这样的设置使得在同一主机上无法启动多个相同的服务实例。所以在Spring Cloud Eureka中针对同一主机启动多个实例的情况,对实例名的默认命名做了更合理的扩展,采用如下规则

 ${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}
我们可以通过eureka.instance.instanceId来配置实例名。当我们在本地做负载均衡调试时,采用的是指定多个端口来启动同一服务的多个实例,但这样你会发现实例名其实还是一样的只是端口不一样,我们可以这样设置指定不同的实例名

eureka.instance.instanceId=${spring.application.name}:${random.int}
这样就可以通过不指定端口就启动同一服务的多个实例。

端点配置

在org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean类中,有一些URL的配置信息,如homePageUrl、statusPageUrl、healthCheckUrl。其中状态页和健康检查的URL默认是使用actuator提供的info和health端点。我们必须保证客户端的health端点是一个可以被注册中心正确访问到的地址,否则注册中心不会根据应用的健康检查来改变应用状态(仅当开启了healthcheck功能时,以该端点信息作为健康检查标准而不是心跳)。如果info端点不能正常访问,则在Eureka面板单击服务时不能访问到服务实例提供的信息接口。一般情况下我们不需要配置这些信息,如果你修改了info端点和health端点的路径,那么就需要修改这个配置了,只需要和actuator的做同样修改即可,比如加上相同的前缀、改为同样的新路径等。

eureka.instance.statusPageUrlPath=info端点的路径
eureka.instance.healthCheckUrlPath=health端点的路径
上述配置是使用相对路径进行配置,如果客户端应用以HTTPS的方式而不是HTTP的方式来暴露服务和监控端点时,要使用绝对路径。

eureka.instance.statusPageUrlPath=https://${eureka.instance.hostname}/actuator/info
eureka.instance.healthCheckUrlPath=https://${eureka.instance.hostname}/actuator/health
其他配置

 

 

除了前三个可能会修改外,其余使用默认配置就可以。


---------------------
作者:myCat、
来源:CSDN
原文:https://blog.csdn.net/WYA1993/article/details/82288605
版权声明:本文为博主原创文章,转载请附上博文链接!

Guess you like

Origin www.cnblogs.com/holly8/p/11225894.html