技术标签: springcloud eureka spring cloud
需要搭建springcloud项目,eureka是其中的一个模块,依赖主要继承父依赖
学习视频:b站狂神说
便于理解,我修改了本地域名=》这里!!!
127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com
127.0.0.1 eureka7003.com
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<!-- 热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
server:
port: 7001
# eureka 配置
eureka:
instance:
hostname: localhost # Eureka 服务端实例名称
client:
register-with-eureka: false # 表示是否向服务器Eureka注册中心注册自己 这里本身激素服务器 false
fetch-registry: false # 如果为false 则表示自己为注册中心
service-url: # 替换源码 默认this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");
# 单机
defaultZone: http://${
eureka.instance.hostname}:${
server.port}/eureka/
@SpringBootApplication
@EnableEurekaServer // 开启EurekaServer 服务端启动类 可以接收别人注册
public class EurekaServer_7001 {
// 启动访问http://localhost:7001/
public static void main(String[] args) {
SpringApplication.run(EurekaServer_7001.class,args);
}
}
http://localhost:7001/
目前还没有任何服务注册到Eureka 所以显示是No instances available
这是一个普通的springcloud项目,需要注册到Eureka中
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
eureka:
client:
service-url: # 替换源码 默认this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");
defaultZone: http://localhost:7001/eureka/
instance:
instance-id: springcloud-provider-dept8001 # 修改eureka 上 Status默认描述信息
@EnableEurekaClient // 自动在服务启动后自动注册到Eureka中
1.需要先启动Eureka服务
2.访问http://localhost:7001/
在Instances currently registered with Eureka中Application对于的是配置文件中spring.application.name: springcloud-provider-dept
的值,Status对应的是eureka.instance.instance-id
的值。
实际是http://localhost:8001/actuator/info
地址,需要配置信息
解决出现错误页面的问题,下面使用actuator来解决。
<!-- 解决 eureka Status actuator/info 完善监控信息-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
# 导入 actuator
info:
app.name: jiangyl-springcloud
company.name: jiang.yl.com
再次启动springcloud-provider-dept-8001
也就是访问http://localhost:8001/actuator/info
可以在提供者模块的Controller控制层自动注入DiscoveryClient类来实现
// 还需要在启动类中添加 @EnableDiscoveryClient 服务发现 用于团队协助
@GetMapping("/dept/discovery")
//注册进来的微服务 , 获取一些信息
public Object discovery(){
// 获取微服务列表的清单
List<String> services = client.getServices();
System.out.println("discovery->services = " + services);
// Eureka 中Application iD
List<ServiceInstance> instances = client.getInstances("SPRINGCLOUD-PROVIDER-DEPT");
for (ServiceInstance instance : instances) {
System.out.println(
instance.getHost()+"\t"+
instance.getUri()+"\t"+
instance.getPort()+"\t"+
instance.getServiceId());
}
return this.client;
}
重新启动该服务,控制台输出内容:
discovery->services = [springcloud-provider-dept]
localhost http://localhost :8001 8001 SPRINGCLOUD-PROVIDER-DEPT
访问接口。
访问浏览器地址http://localhost:8001/dept/discovery
如果已经注册到Eureka的服务,突然关闭服务了,默认等待90秒后刷新http://localhost:7001/
浏览器会发现出现了下面的英文:
EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.
翻译:紧急!Eureka可能错误地声称实例正在运行,但实际上它们并未运行。由于续订数量低于阈值,因此为了安全起见,这些实例并未过期。
自我保护机制:好死不如赖活着
一句话总结:某时刻某一个微服务不可以用了,eureka不会立刻清理,依旧会对该微服务的信息进行保存!
eureka.server.enable-se1f-preservation = false
禁用自我保护模式【不推荐关闭自我保护机制】Eureka可以很好的应对因网络故障导致部分节点失去联系的情况,而不会像zookeeper那样使整个注册服务瘫痪
为了演示的更接近真实集群环境,首先将C:\Windows\System32\drivers\etc\hosts
文件添加一下配置:
# 模拟有3台主机,
127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com
127.0.0.1 eureka7003.com
复制文章前面提到的springcloud-eureka-7001项目:
只是需要修改对应的配置文件即可:
springcloud-eureka-7001模块中的application.yml修改之后
hostname: eueka7001.com
本机域名
defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
需要关联的主机
server:
port: 7001
# eureka 配置
eureka:
instance:
hostname: eureka7001.com # Eureka 服务端实例名称 电脑1hostname
client:
register-with-eureka: false # 表示是否向服务器Eureka注册中心注册自己 这里本身激素服务器 false
fetch-registry: false # 如果为false 则表示自己为注册中心
service-url: # 替换源码 默认this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");
# 单机
# defaultZone: http://localhost:7001/eureka/
#集群
# 连接其它主机电脑,域名:端口
defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
springcloud-eureka-7002模块中的application.yml
server:
port: 7002
# eureka 配置
eureka:
instance:
hostname: eureka7002.com # Eureka 服务端实例名称 电脑2hostname
client:
register-with-eureka: false # 表示是否向服务器Eureka注册中心注册自己 这里本身激素服务器 false
fetch-registry: false # 如果为false 则表示自己为注册中心
service-url: # 替换源码 默认this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");
# 连接其它主机电脑,域名:端口
# 单机
# defaultZone: http://localhost:7001/eureka/
#集群
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/
springcloud-eureka-7003模块中的application.yml
server:
port: 7003
# eureka 配置
eureka:
instance:
hostname: eureka7003.com # Eureka 服务端实例名称 电脑3hostname
client:
register-with-eureka: false # 表示是否向服务器Eureka注册中心注册自己 这里本身激素服务器 false
fetch-registry: false # 如果为false 则表示自己为注册中心
service-url: # 替换源码 默认this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
访问对应的域名:端口号,如:http://eureka7001.com:7001/
,结果如下:
DS Replicas:注册中心中用于数据同步的相邻备份节点
只需要修改本文章上述提到的springcloud-provider-dept-8001项目中的application.yml文件defaultZone:
的值
server:
port: 8001
eureka:
client:
service-url: # 替换源码 默认this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");
# 端口号 7001 7002 7003 ,实际工作中是3台不同的电脑域名或IP
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7002.com:7003/eureka/
instance:
instance-id: springcloud-provider-dept8001 # 修改eureka 上 Status默认描述信息
先启动eureka集群,再启动提供者
访问三台eureka主机中的任意一个,都可以看到提供者信息,如:http://eureka7001.com:7001/
[每日鸡汤1/1]:
学习不是一场短跑,而是一场马拉松。保持耐心和毅力,你会看到不一样的风景。
文章浏览阅读1.4k次。python 用PIL Matplotlib处理图像的基本操作_jupyter 显示matplotlib图片完全
文章浏览阅读8.6k次,点赞11次,收藏59次。目录一、方法21. 导入库2. 构建关键词3. 构建句子4. 建立统一索引5. 表连接6. 关键词匹配二、方法21. 构建字典2. 关键词匹配3. 结果展示4. 匹配结果展开一、方法2此方法是两个表构建某一相同字段,然后全连接,在做匹配结果筛选,此方法针对数据量不大的时候,逻辑比较简单,但是内存消耗较大1. 导入库import pandas as pdimport numpy as npimport re2. 构建关键词#关键词_pandas 模糊匹配
文章浏览阅读393次。一键快速批量采集JavaScript加载的动态页面数据内容的方法_js动态加载怎么爬取
文章浏览阅读1.1k次。其实docker安装的话,windows和centos没什么区别#拉去es镜像文件docker pull docker.elastic.co/elasticsearch/elasticsearch:7.6.1#启动es单机版docker run-p 0.0.0.0:9200:9200 -p 0.0.0.0:9300:9300--env discovery.type=single-nod..._windows10 docker安装kibana use --allow-root to continue.
文章浏览阅读5.2k次。goalvue-cli脚手架生成的项目,想要配置webpack下的output.publicPath选项配置1module.exports = { configureWebpack: { publicPath: 'http://localhost:8080/', }}报错configuration has an unknown property ‘publicPath’. These properties are valid: output?理解:需要在ou_configuration error: avoid modifying webpack output.path directly. use the
文章浏览阅读2k次。tf中 tensorboard 工具通过读取在网络训练过程中保存到本地的日志文件实现数据可视化,日志数据保存主要用到 tf.summary 中的方法。tf.summary中summary是tf中的一个py文件,位置在 '/tensorflow/python/summary/' 文件夹下,提供了像tf.summary.scalar、tf.summary.histogram等方法,用来把graph图中..._summary_writer.add_summary()
文章浏览阅读7.7k次。iPhone12怎么隐藏底部小白条?很多iPhone 12用户反馈在看手机或者玩游戏的时候,屏幕底部的小白横条非常碍眼,但是又不知道怎么隐藏掉,所以小编今天整理了下iPhone12隐藏底部横条方法,帮大家一键隐藏底部横条,一起来看看吧!iPhone12隐藏底部横条方法:利用“引导式访问“功能。打开 iPhone “设置”-“辅助功能”,下拉找到“引导式访问”并开启: 在使用该功能之前,建议仔细阅..._iphone玩王者荣耀怎么把下面那个横条去掉
文章浏览阅读550次。第一步、安装深度的“显卡驱动器”在deepin v20 中默认没有显卡驱动管理器,需要命令行安装,命令如下(刚开始一直出错,当我第一次打开应用商店,就可以安装了,好神奇):sudo apt install deepin-graphics-driver-manager安装深度的“显卡驱动器”,切换到因特尔默认驱动,然后重启两次,确认切换成功后,进行下一步。第二步、卸载英伟达开源驱动如果刚刚安装好系统..._linux终端命令安装显卡驱动是闭源的吗
文章浏览阅读1.3w次,点赞5次,收藏36次。C++编程常见错误及处理。在 C++ 程序错误一般分类:语法错误;运行错误;语义错误(也称逻辑错误)。本文介绍相关错误产生的原因及处理_c++常见错误及解决方法
文章浏览阅读137次。在安装GRID过程中,运行root.sh脚本时报如下信息:Adding Clusterware entries to upstartCRS-2672: Attempting to start 'ora.mdnsd' on 'rac11g1'CRS-2676: Start of 'ora.mdnsd' on 'rac11g1' succeededCRS-2672: Attempt..._ora-27091 ora-15081
文章浏览阅读145次。行走江湖这么多年,谁还没有几个软件傍身啊。软件如果用学术名词来讲的话,指的是一系列按照特定顺序组织的计算机数据和的集合,一般来说,划分为系统软件、应用软件以及介于两者之间的中间件。随着技术的发展,软件数量也出现了井喷式增长,但是这些软件鱼龙混杂,质量参差不齐。本文就从千千万万的软件中挑几款"良心"软件和大家分享。"情怀良心"——新一代"桌宠"瑞星小狮子相信很多人的朋友圈都曾经被这张图刷过屏,瑞星是..._第一代桌宠
文章浏览阅读1.4k次。通常的,我们点击返回键,如果我们没有做特殊处理,那么我们的activity会被销毁,那他是怎么实现的呢在监听onkeyUP事件上,我们发现父类的处理是这样的,如果是back事件,会走onBackPressed&&!return;if (!return;if (!return;try {});finishAfterTransition 会调用finish 实现销毁if (!finish();通常我们在app需要实现点击两次退出的,可以在onPressed中做文章。_android 关闭activity