当前位置:网站首页>eureka的解析
eureka的解析
2022-06-21 21:50:00 【InfoQ】
一、Eureka
基本概念
- Eureka Server\
- Eureka Client\
- 各个节点启动后,会在Eureka Server中进行注册,这样EurekaServer中的服务注册表中将会存储所有可用服务节点的信息,服务节点的信息可以在界面中直观的看到。\
- 多个Eureka Server之间通过复制的方式,来实现服务注册表数据的同步。\
- 客户端同时也包含一个内置的、使用轮询(round-robin)负载算法的负载均衡器。
- 在应用启动后,将会 向Eureka Server发送心跳维持自己的注册状态,默认周期为30秒,如果Eureka Server在多个心跳周期内没有 接收到某个节点的心跳,Eureka Server将会从服务注册表中注销该实例,把这个服务节点移除,默认周期为90 秒。
# 每间隔30s,向服务端发送一次心跳,证明自己依然”存活“
eureka.instance.lease-renewal-interval-in-seconds=30
#告诉服务端,如果我90s之内没有给你发心跳,就代表我“死”了,将我踢出掉
eureka.instance.lease-expiration-duration-in-seconds=90
- Eureka Client 会缓存服务注册表中的信息,所以 Eureka Client 无须每次调用微服务都要先查询Eureka Server,能有效地缓解Eureka Server的压力,而且即使所有的Eureka Server节点都宕掉,Client 依然可以根据缓存中信息找到服务提供者。\
#从注册中心获取注册信息,默认true
eureka.client.fetchRegistry=true
# 从注册中心获取注册信息的时间间隔,默认30s
eureka.client.registryFetchIntervalSeconds=30
二、搭建Eureka服务器
1、父工程中定义Spring Cloud的版本
<dependencyManagement>
<dependencies>
<!--Spring Cloud-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2、创建Eureka服务器模块
3、配置pom
<dependencies>
<!--注册中心-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
4、配置application.properties
#服务端口
server.port=8220
# 服务名
spring.application.name=guli-eureka
# 环境设置:dev、test、prod
spring.profiles.active=dev
#Eureka客户端与Eureka服务端进行通信的地址
eureka.client.service-url.defaultZone=http://192.168.100.100:8220/eureka
#属性表示是否将自己注册到Eureka Server, 默认为true。 由于当前应用就是Eureka Server, 因此设为 false;
# 单节点关闭
eureka.client.register-with-eureka=false
#表示是否从Eureka Server获取注册信息,默认为true。 如果这是一个单点的 Eureka Server,不需要同步其他节点的数据,可以设为false。
# 单节点关闭
eureka.client.fetch-registry=false
5、创建启动类
package com.guli.eureka;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class);
}
}
6、logback.xml
7、启动Eureka注册中心并在浏览器中访问
三、服务注册
1、客户端配置pom
<!--服务注册-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
2、添加服务配置信息
#指定注册中心地址
eureka.client.service-url.defaultZone=http://192.168.100.100:8220/eureka/
#eureka服务器上获取的是服务器的ip地址
eureka.instance.prefer-ip-address=true
3、添加Eureka客户端注解(可选)
@EnableDiscoveryClient@EnableEurekaClient@EnableEurekaClient
@EnableDiscoveryClient@EnableEurekaClient@EnableDiscoveryClient@EnableEurekaClient4、启动客户端微服务
边栏推荐
- RK3568开发笔记(三):RK3568虚拟机基础环境搭建之更新源、安装网络工具、串口调试、网络连接、文件传输、安装vscode和samba共享服务
- uniapp在解决谷歌浏览器跨域问题,在谷歌浏览器运行
- SIGIR2022 | 對話式推薦系統中的用戶偏好建模
- Getting started with reverse debugging - Basics
- Getting to know Vxe table (I)
- Operation and maintenance specification: process template for online fault handling
- 企业综合组网实训二
- 泰山OFFICE技术讲座:微软雅黑字体故意设置的坑,粗体错误
- 微信小程序获取网络状态
- 【深入理解指针】指针的进阶
猜你喜欢

Getting to know Vxe table (I)

It is said that the design of high concurrency system is not difficult at all!

C语言【隐式类型转换】和【显式类型转换】的详解

QT practical skill: close unnecessary warning prompt on the right in the qtcreator editing area
![[understanding pointer] advanced level of pointer](/img/56/2db57773ed2d0c71b05455dd5e0d6c.png)
[understanding pointer] advanced level of pointer

今日睡眠质量记录81分

Enterprise comprehensive networking Training II

Solutions to the problem that Allegro's pcbeditor is often stuck or busy in use

Hardware development notes (III): basic process of hardware development, making a USB to RS232 module (II): design principle diagram Library

Why applets and the industrial Internet can complement each other
随机推荐
QT practical skill: close unnecessary warning prompt on the right in the qtcreator editing area
Solve the problem that the letter of a key in laptop (I) cannot be pressed
Personal stock trading experience
有一说一,高并发系统设计其实一点都不难!
同花顺VIP开户怎么开户,安全吗?
postgres 通过 limit 切片数据
4. esp8266 displays DHT11 temperature and humidity parameters in real time through OLED
Jupyter lab cannot be used after installing the extension
【深入理解指针】指针的进阶
Elementary transformation of numpy matrix
Readjustment of move protocol beta to expand the total prize pool
Wechat applet obtains network status
About the designer of qtcreator the solution to the problem that qtdesigner can't pull and hold controls normally
uniapp微信授权之 有个别用户 无法正常授权
The solution to the error "xxx.pri has modification time XXXX s in the futrue" in the compilation of domestic Kirin QT
關於 麒麟系統開發錯誤“fatal error: GL/gl.h: No such file or directory“ 的解决方法
Using JS function in wxml file of applet
泰山OFFICE技术讲座:微软雅黑字体故意设置的坑,粗体错误
Specific methods of using cloud development to realize wechat payment
Flink real-time risk control rule engine