【Eureka】服务端和客户端
【Eureka】服务端和客户端
转载:https://www.cnblogs.com/yangchongxing/p/10778357.html
Eureka服务端
1、添加依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ycx</groupId>
<artifactId>eureka-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-server</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties> <dependencies>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency> <!-- spring cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> <!-- other -->
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
2、启用Eureka服务
package ycx.eureka; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication { public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
} }
3、配置Eureka
spring:
application:
name: eureka-server
server:
port:
eureka:
instance:
prefer-ip-address: true
client:
register-with-eureka: false
fetch-registry: false
service-url:
default-zone: http://eureka.ycx.com:8761/eureka
Eureka客户端
1、添加依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ycx</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>admin-server</artifactId>
<name>admin-server</name>
<description>sc server</description> <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties> <dependencies>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!-- spring cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> <!-- other -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency> </dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
2、启用服务发现,仅仅 Eureka 使用 @EnableEurekaClient,其他的服务发现代理使用 @EnableDiscoveryClient
package ycx.admin; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @EnableEurekaClient
@SpringBootApplication
public class AdminServerApplication { public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
} }
3、配置服务发现
spring:
application:
name: admin-server
server:
port:
eureka:
instance:
prefer-ip-address: true
client:
register-with-eureka: true
fetch-registry: true
service-url:
default-zone: http://eureka.ycx.com:8761/eureka
配置信息,参考:https://www.cnblogs.com/tiancai/p/9593648.html
Eureka Instance配置信息
全部保存在org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean配置类里,实际上它是com.netflix.appinfo.EurekaInstanceConfig的实现类,替代了netflix的com.netflix.appinfo.CloudInstanceConfig的默认实现。
appname = unknown
应用名,首先获取spring.application.name的值,如果取值为空,则取默认unknown。 appGroupName = null
应用组名 instanceEnabledOnit = false
实例注册到Eureka上是,是否立刻开启通讯。有时候应用在准备好服务之前需要一些预处理。 nonSecurePort =
非安全的端口 securePort =
安全端口 nonSecurePortEnabled = true
是否开启非安全端口通讯 securePortEnabled = false
是否开启安全端口通讯 leaseRenewalIntervalInSeconds =
实例续约间隔时间 leaseExpirationDurationInSeconds =
实例超时时间,表示最大leaseExpirationDurationInSeconds秒后没有续约,Server就认为他不可用了,随之就会将其剔除。 virtualHostName = unknown
虚拟主机名,首先获取spring.application.name的值,如果取值为空,则取默认unknown。 instanceId
注册到eureka上的唯一实例ID,不能与相同appname的其他实例重复。 secureVirtualHostName = unknown
安全虚拟主机名,首先获取spring.application.name的值,如果取值为空,则取默认unknown。 metadataMap = new HashMap();
实例元数据,可以供其他实例使用。比如spring-boot-admin在监控时,获取实例的上下文和端口。 dataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn);
实例部署的数据中心。如AWS、MyOwn。 ipAddress=null
实例的IP地址 statusPageUrlPath = "/actuator/info"
实例状态页相对url statusPageUrl = null
实例状态页绝对URL homePageUrlPath = "/"
实例主页相对URL homePageUrl = null
实例主页绝对URL healthCheckUrlUrlPath = "/actuator/health"
实例健康检查相对URL healthCheckUrl = null
实例健康检查绝对URL secureHealthCheckUrl = null
实例安全的健康检查绝对URL namespace = "eureka"
配置属性的命名空间(Spring Cloud中被忽略) hostname = null
主机名,不配置的时候讲根据操作系统的主机名来获取 preferIpAddress = false
是否优先使用IP地址作为主机名的标识
Eureka Client客户配置信息
配置全部在org.springframework.cloud.netflix.eureka.EurekaClientConfigBean中,实际上它是com.netflix.discovery.EurekaClientConfig的实现类,替代了netxflix的默认实现。
enabled=true
是否启用Eureka client。 registryFetchIntervalSeconds=
定时从Eureka Server拉取服务注册信息的间隔时间 instanceInfoReplicationIntervalSeconds=
定时将实例信息(如果变化了)复制到Eureka Server的间隔时间。(InstanceInfoReplicator线程) initialInstanceInfoReplicationIntervalSeconds=
首次将实例信息复制到Eureka Server的延迟时间。(InstanceInfoReplicator线程) eurekaServiceUrlPollIntervalSeconds=
拉取Eureka Server地址的间隔时间(Eureka Server有可能增减) proxyPort=null
Eureka Server的代理端口 proxyHost=null
Eureka Server的代理主机名 proxyUserName=null
Eureka Server的代理用户名 proxyPassword=null
Eureka Server的代理密码 eurekaServerReadTimeoutSeconds=
从Eureka Server读取信息的超时时间 eurekaServerConnectTimeoutSeconds=
连接Eureka Server的超时时间 backupRegistryImpl=null
Eureka Client第一次启动时获取服务注册信息的调用的回溯实现。Eureka Client启动时首次会检查有没有BackupRegistry的实现类,如果有实现类,则优先从这个实现类里获取服务注册信息。 eurekaServerTotalConnections=
Eureka client连接Eureka Server的链接总数 eurekaServerTotalConnectionsPerHost=
Eureka client连接单台Eureka Server的链接总数 eurekaServerURLContext=null
当Eureka server的列表在DNS中时,Eureka Server的上下文路径。如http://xxxx/eureka。 eurekaServerPort=null
当Eureka server的列表在DNS中时,Eureka Server的端口。 eurekaServerDNSName=null
当Eureka server的列表在DNS中时,且要通过DNSName获取Eureka Server列表时,DNS名字。 region="us-east-1"
实例所属区域。 eurekaConnectionIdleTimeoutSeconds =
Eureka Client和Eureka Server之间的Http连接的空闲超时时间。 heartbeatExecutorThreadPoolSize=
心跳(续约)执行器线程池大小。 heartbeatExecutorExponentialBackOffBound=
心跳执行器在续约过程中超时后的再次执行续约的最大延迟倍数。默认最大延迟时间= * eureka.instance.leaseRenewalIntervalInSeconds cacheRefreshExecutorThreadPoolSize=
cacheRefreshExecutord的线程池大小(获取注册信息) cacheRefreshExecutorExponentialBackOffBound=
cacheRefreshExecutord的再次执行的最大延迟倍数。默认最大延迟时间= *eureka.client.registryFetchIntervalSeconds serviceUrl= new HashMap();serviceUrl.put(DEFAULT_ZONE, DEFAULT_URL);
Eureka Server的分区地址。默认添加了一个defualtZone。也就是最常用的配置eureka.client.service-url.defaultZone=xxx registerWithEureka=true
是否注册到Eureka Server。 preferSameZoneEureka=true
是否使用相同Zone下的Eureka server。 logDeltaDiff=false
是否记录Eureka Server和Eureka Client之间注册信息的差异 disableDelta=false
是否开启增量同步注册信息。 fetchRemoteRegionsRegistry=null
获取注册服务的远程地区,以逗号隔开。 availabilityZones=new HashMap()
可用分区列表。用逗号隔开。 filterOnlyUpInstances = true
是否只拉取UP状态的实例。 fetchRegistry=true
是否拉取注册信息。 shouldUnregisterOnShutdown = true
是否在停止服务的时候向Eureka Server发起Cancel指令。 shouldEnforceRegistrationAtInit = false
是否在初始化过程中注册服务。
Eureka Server注册中心配置信息
Eureka Server注册中心端的配置是对注册中心的特性配置。Eureka Server的配置全部在org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean里,实际上它是com.netflix.eureka.EurekaServerConfig的实现类,替代了netflix的默认实现。
enableSelfPreservation=true
是否开启自我保护 renewalPercentThreshold = 0.85
自我保护续约百分比阀值因子。如果实际续约数小于续约数阀值,则开启自我保护 renewalThresholdUpdateIntervalMs = * *
续约数阀值更新频率。 peerEurekaNodesUpdateIntervalMs = * *
Eureka Server节点更新频率。 enableReplicatedRequestCompression = false
是否启用复制请求压缩。 waitTimeInMsWhenSyncEmpty= * *
当从其他节点同步实例信息为空时等待的时间。 peerNodeConnectTimeoutMs=
节点间连接的超时时间。 peerNodeReadTimeoutMs=
节点间读取信息的超时时间。 peerNodeTotalConnections=
节点间连接总数。 peerNodeTotalConnectionsPerHost = ;
单个节点间连接总数。 peerNodeConnectionIdleTimeoutSeconds = ;
节点间连接空闲超时时间。 retentionTimeInMSInDeltaQueue = * MINUTES;
增量队列的缓存时间。 deltaRetentionTimerIntervalInMs = * ;
清理增量队列中过期的频率。 evictionIntervalTimerInMs = * ;
剔除任务频率。 responseCacheAutoExpirationInSeconds = ;
注册列表缓存超时时间(当注册列表没有变化时) responseCacheUpdateIntervalMs = * ;
注册列表缓存更新频率。 useReadOnlyResponseCache = true;
是否开启注册列表的二级缓存。 disableDelta=false。
是否为client提供增量信息。 maxThreadsForStatusReplication = ;
状态同步的最大线程数。 maxElementsInStatusReplicationPool = ;
状态同步队列的最大容量。 syncWhenTimestampDiffers = true;
当时间差异时是否同步。 registrySyncRetries = ;
注册信息同步重试次数。 registrySyncRetryWaitMs = * ;
注册信息同步重试期间的时间间隔。 maxElementsInPeerReplicationPool = ;
节点间同步事件的最大容量。 minThreadsForPeerReplication = ;
节点间同步的最小线程数。 maxThreadsForPeerReplication = ;
节点间同步的最大线程数。 maxTimeForReplication = ;
节点间同步的最大时间,单位为毫秒。 disableDeltaForRemoteRegions = false;
是否启用远程区域增量。 remoteRegionConnectTimeoutMs = ;
远程区域连接超时时间。 remoteRegionReadTimeoutMs = ;
远程区域读取超时时间。 remoteRegionTotalConnections = ;
远程区域最大连接数 remoteRegionTotalConnectionsPerHost = ;
远程区域单机连接数 remoteRegionConnectionIdleTimeoutSeconds = ;
远程区域连接空闲超时时间。 remoteRegionRegistryFetchInterval = ;
远程区域注册信息拉取频率。 remoteRegionFetchThreadPoolSize = ;
远程区域注册信息线程数。
Eureka Server注册中心仪表盘配置
path="/"
仪表盘访问路径 enabled=true
是否启用仪表盘
【Eureka】服务端和客户端的更多相关文章
- eureka服务端和客户端的简单搭建
本篇博客简单记录一下,eureka 服务端和 客户端的简单搭建. 目标: 1.完成单机 eureka server 和 eureka client 的搭建. 2.完成eureka server 的添加 ...
- SpringCloud02 Eureka知识点、Eureka服务端和客户端的创建、Eureka服务端集群、Eureka客户端向集群的Eureka服务端注册
1 Eureka知识点 按照功能划分: Eureka由Eureka服务端和Eureka客户端组成 按照角色划分: Eureka由Eureka Server.Service Provider.Servi ...
- 三、eureka服务端获取服务列表
所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 eureka服务端维护了一个服务信息的列表,服务端节点之间相互复制服务信息.而作为eur ...
- Spring Eureka的使用入门--服务端与客户端
接上篇: Eureka作为注册中心,连接服务端与客户端: 服务端: 依赖包: apply plugin: 'org.springframework.boot' apply plugin: 'io.sp ...
- spring cloud eureka 服务端开启密码认证后,客户端无法接入问题
Eureka服务端开启密码的认证比较简单 在pom文件中加入: <dependency> <groupId>org.springframework.boot</group ...
- Spring Cloud官方文档中文版-服务发现:Eureka服务端
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR3/#spring-cloud-eureka-server 文中例子我做了一些 ...
- SpringCloud系列四:Eureka 服务发现框架(定义 Eureka 服务端、Eureka 服务信息、Eureka 发现管理、Eureka 安全配置、Eureka-HA(高可用) 机制、Eureka 服务打包部署)
1.概念:Eureka 服务发现框架 2.具体内容 对于服务发现框架可以简单的理解为服务的注册以及使用操作步骤,例如:在 ZooKeeper 组件,这个组件里面已经明确的描述了一个服务的注册以及发现操 ...
- springcloud(三):Eureka服务端
一. 因为使用一个注册中心服务器端,n个客户端:n个生产者客户端.n消费者客户端....,所有的客户端最好的方式就是通过对象传递参数,因此需要创建一个公共组件项目,为n个客户端传值提供方便 二.创建公 ...
- Eureka 客户端连接Eureka服务端时 报Cannot execute request on any known server 解决办法
报Cannot execute request on any known server 这个错,总的来说就是连接Eureka服务端地址不对. 因为配置eureka.client.serviceUrl. ...
随机推荐
- C语言1博客作业01
1 你对软件工程专业或者计算机科学与技术专业了解是怎样? 主修大数据技术导论.数据采集与处理实践(Python).Web前/后端开发.统计与数据分析.机器学习.高级数据库系统.数据可视化.云计算技术. ...
- Opencv的线性滤波和非线性滤波
线性滤波 :方框滤波 均值滤波 高斯滤波 非线性滤波: 中值滤波 双边滤波 这几个滤波都是起模糊作用 去除噪点 不废话了 下面是代码 #include <opencv2/opencv.h ...
- 如何编译和使用自定义Qt动态链接库 | how to build and use user-defined qt library
本文首发于个人博客https://kezunlin.me/post/cf628dd8/,欢迎阅读! guide to build qt library and use in another proje ...
- Openlayers Overlay导致偏移
说明: 在做项目过程中,用overlay做了一个infowindow弹窗,但是在使用过程中发现一个bug:overlay.setPosition以后,会出现偏移,但是拖动一下地图或者点击一下地图其他地 ...
- VueRouter爬坑第二篇-动态路由
VueRouter系列的文章示例编写时,项目是使用vue-cli脚手架搭建. 项目搭建的步骤和项目目录专门写了一篇文章:点击这里进行传送 后续VueRouter系列的文章的示例编写均基于该项目环境. ...
- Coding,命名是个技术活
来吧 日常编码少不了的事情就是给代码命名,代码中命名的重要性在项目前期不会有太大感受,因为是边做边命名,代码天天见,自然会加深记忆.但到了后期上线后半年一年后,再回过头看的时候,我擦,这个变量是啥意思 ...
- Protues7.8仿真软件有中文路径无法正常运行怎么办?
Protues7.8是一款功能强大的单片机仿真软件,在我们的学习生活中经常会用的到,在装软件时明明已经装好了,却不能报错跳出两行红字,让人心痛. 一般都是因为账户名字是中文的问题,这个软件对中文不兼容 ...
- 安装iris框架
1.导语 目前Go语言已经为大多数人所熟知,越来越多的开发人员选择使用Go语言来进行开发,但是如何使用 Go来进行web开发,在其他编程语言中都有对应的开发框架,当然在Go中也有,就是即将要介绍的-- ...
- python numpy学习
以下代码来源于本博文作者观看大神视频并纯手敲. 目录 numpy的属性 创建array numpy的运算1 随机数生成以及矩阵的运算2 numpy的索引 array合并 array分割 numpy的浅 ...
- VLAN实验2(配置Trunk接口)
本实验基于<HCNA网络技术实验指南> 本实验使用eNSP软件 原理概述: 在以太网中,通过划分VLAN来隔离广播域和增强网络通信的安全性.以太网通常由 多台交换机组成,为了使VLAN的数 ...