Part XVII. Appendix: Compendium of Configuration Properties
现在来讨论一下Eureka的常用配置,Eureka有非常多的配置项
Appendix:Compendium of Configuration Properties
https://cloud.spring.io/spring-cloud-static/Finchley.RELEASE/multi/
multi__appendix_compendium_of_configuration_properties.html
所有SpringCloud的配置项都在这里
那我们看一下Eureka有哪些,可能有上百个
eureka.client.allow-redirects
允许重定向
eureka.client.availability-zones
这个是AWS里面用的
eureka.client.decoder-name
解码器的名称
This is a transient config and once the latest codecs are stable, can be removed
(as there will only be one)
eureka.client.enabled
Flag to indicate that the Eureka client is enabled.
表明Eureka Client是否可用的一个标识
eureka.client.fetch-registry
在standalone里面我们有用过
Indicates whether this client should fetch eureka registry information from eureka server.
表明此客户端是否从eureka服务器端拉取eureka注册表的信息,也就是他要不要从eureka服务器上拉数据,
eureka.client.g-zip-content
发现他默认是true,说明eureka他传输的内容是不是通过gzip压缩的
eureka.client.heartbeat-executor-thread-pool-size
线程池的大小
eureka.client.prefer-same-zone-eureka
eureka.client.region
在us-east-1里面,默认是美东,这个region,
Gets the region (used in AWS datacenters) where this instance resides.
eureka.client.register-with-eureka
In some cases, you do not want your instances to be discovered whereas you just want do
discover other instances.
单点的eureka模式
eureka.client.registry-fetch-interval-seconds
这个是30秒
Indicates how often(in seconds) to fetch the registry information from the eureka server.
从eureka服务器获取注册信息的频率,一秒为单位
eureka.client.service-url
他是个map,
/**
* Map of availability zone to list of fully qualified URLs to communicate with eureka
* server. Each value can be a single URL or a comma separated list of alternative
* locations.
*
* Typically the eureka server URLs carry protocol,host,port,context and version
* information if any. Example:
* http://ec2-256-156-243-129.compute-1.amazonaws.com:7001/eureka/
*
* The changes are effective at runtime at the next service url refresh cycle as
* specified by eurekaServiceUrlPollIntervalSeconds.
*/
private Map<String, String> serviceUrl = new HashMap<>();
看下它是什么
Map of availability zone to list of fully qualified URLs to communicate with eureka server.
Each value can be a single URL or a comma separated list of alternative locations.
Typically the eureka server URLs carry protocol,host,port,context and version information if any.
Example: http://ec2-256-156-243-129.compute-1.amazonaws.com:7001/eureka/
The changes are effective at runtime at the next service url refresh cycle as specified by
eurekaServiceUrlPollIntervalSeconds.
可用区的一个map,可用区的一个映射,可以理解为一个完整的URL,然后多个之间可以用逗号分隔,可以是一个
URL,如果是多个的话可以用逗号分隔,通常包含很多东西,协议http,host,端口,上下文,版本信息,我们可以去
改变配置,他有一个刷新周期
eureka.dashboard.enabled
eureka.dashboard.enabled=false
会有什么效果呢,发现404了,dashboard是什么,其实就是eureka的首页,就是他的界面
eureka.dashboard.path
默认是/,那这个有什么应用场景呢,假设我现在用的是高可用的eureka,那是不是每一个eureka都可以访问,
我可能不想记那么多,只允许一个可以进行dashboard,其他的把它禁用,我只要记住端口IP就可以了,另外一个他
可以自定义路径,这样我可以做一些伪装之类的,就像有的时候一些系统,他默认的管理路径是admin,我就可以自定义,
当然适用场景也非常有限了
eureka.instance.appname
druid德鲁伊 eureka我找到了!
eureka.instance.appname=USER-SERVICE-HAHA
#debug=true
server.port=7900
#server.context-path=/boot02
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
logging.level.com.learn=trace
#logging.file=D:/springboot.log
logging.file=springboot.log
logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%n
#spring.resources.static-locations=classpath:/hello,classpath:/learn
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://59.110.158.145:3306/SpringCloud?useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
mybatis.config-location=classpath:mybatis/mybatis-config.xml
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
eureka.client.serviceUrl.defaultZone=http://admin:1234@10.40.8.152:8761/eureka
spring.application.name=microservice-simple-provider-user
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
#eureka.client.healthcheck.enabled=true
spring.redis.host=10.40.8.152
spring.redis.password=aztech
spring.redis.port=6379
eureka.instance.appname=USER-SERVICE-HAHA
eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://admin:1234@10.40.8.152:8761/eureka
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean.appname
/**
* Get the name of the application to be registered with eureka.
*/
private String appname = UNKNOWN;
private static final String UNKNOWN = "unknown";
他的作用是填坑,swagger(api document)它是可以支持声明式的注解,然后通过注解帮我们自动的生成API文档,
它是这样的一个工具
https://swagger.io/
简单的说就是我写几个注解,Swagger的注解,跟Spring Cloud结合使用是有一定的冲突的,
appname才是最原本的注册到eureka上面的app的名称
eureka.instance.data-center-info
也是AWS的
eureka.instance.hostname
在高可用的Eureka里面,指定这个eureka的主机名是什么,假设我现在在用户微服务上面,配置hostname等于user,
说明user的主机名是user,我就可以用http:user:7900/去访问,我就会把这个信息注册给eureka了
Changing the Eureka Instance ID
https://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/1.3.1.RELEASE/
A vanilla Netflix Eureka instance is registered with an ID that is equal to its host name
(i.e. only one service per host). Spring Cloud Eureka provides a sensible default that
looks like this:
${spring.cloud.client.hostname}:${spring.application.name}
:${spring.application.instance_id:${server.port}}}.
For example myhost:myappname:8080.
eureka.instance.ip-address
eureka.instance.metadata-map
获取metadata的键值对,跟instance有关系的键值对,信息发送给eureka server
Gets the metadata name/value pairs associated with this instance. This information is sent to
eureka server and can be used by other instances.
eureka.instance.namespace
Get the namespace used to find properties. Ignored in Spring Cloud.
eureka.instance.non-secure-port
eureka.instance.prefer-ip-address
鼠标拖上去的时候显示的是IP,也就是链接是IP,注册到eureka上面的是IP
eureka.instance.secure-health-check-url
eureka.instance.secure-port
默认HTTPS的端口,是否启用HTTPS
默认是不启用
eureka.instance.secure-virtual-host-name
虚拟的主机名
eureka.instance.status-page-url
状态页面的URL
eureka.instance.virtual-host-name
使用HTTP的虚拟主机名
eureka.server.peer-eureka-status-refresh-time-interval-ms
eureka对等体状态的刷新时间,刷新周期是毫秒