Spring Cloud 如何搭建eureka
Eureka Server 的搭建
eureka 是 Spring Cloud 的注册中心,提供服务注册和服务发现的功能。
利用idea 快速创建一个eureka应用
File - NewProject-Spring Initalizr
1.利用 https://start.spring.io 创建spring cloud eureka应用

填写应用的maven等信息,下一步

选择 Eureka Server,我们的构建基于Spring Boot 2.2.0-RELEASE版本

选择路径后完成创建工程
2.可以看到构建工程的过程中,pom文件中,已经把我门需要的 eureka server 的包引入到了工程
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
3.添加配置(习惯使用yml,可以把application.properties 改成 application.yml)
spring:
application:
name: spring-eureka
server:
port: 8761 #spring eureka 注册地址
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8761/eureka/
register-with-eureka: false #是否注册到eureka上
fetch-registry: false #是否从eureka上获取同步信息,单节可以设置为false
server:
eviction-interval-timer-in-ms: 10000 #清理无效节点时间
enable-self-preservation: false #是否开启自我保护 ,Eureka 会统计15分钟之内心跳失败的比例低于85%将会触发保护机制,不剔除服务提供者,如果关闭服务注册中心将不可用的实例正确剔除
4.启动类添加注解 @EnableEurekaServer
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication
@EnableEurekaServer
public class SpringEurekaApplication { public static void main(String[] args) {
SpringApplication.run(SpringEurekaApplication.class, args);
} }
5.启动
6.启动多个eureka实例的配置
只需要把 service-url 中的url设置未多个,中间用逗号隔开

各个应用往eureka上注册
1.引入配置
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
2.application.yml 配置
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: true
3.启动类注解
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication
@EnableEurekaClient
public class SpringUserApplication { public static void main(String[] args) {
SpringApplication.run(SpringUserApplication.class, args);
} }
Spring Cloud 如何搭建eureka的更多相关文章
- Spring Cloud环境搭建: Eureka Server
项目目录结构, 总共三个文件 ├── pom.xml └── src ├── main │ ├── java │ │ └── com │ │ └── rockbb │ │ ...
- spring cloud config搭建说明例子(二)-添加eureka
添加注册eureka 服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</ ...
- Spring Cloud 入门 之 Eureka 篇(一)
原文地址:Spring Cloud 入门 之 Eureka 篇(一) 博客地址:http://www.extlight.com 一.前言 Spring Cloud 是一系列框架的有序集合.它利用 Sp ...
- SpringCloud实战之初级入门(三)— spring cloud config搭建git配置中心
目录 1.环境介绍 2.配置中心 2.1 创建工程 2.2 修改配置文件 2.3 在github中加入配置文件 2.3 修改启动文件 3. 访问配置中心 1.环境介绍 上一篇文章中,我们介绍了如何利用 ...
- spring cloud config搭建说明例子(四)-补充配置文件
服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</groupId> ...
- spring cloud config搭建说明例子(三)-添加actuator
添加心跳 服务端 ConfigServer pom.xml添加actuator包 <dependency> <groupId>org.springframework.cloud ...
- Spring Cloud 系列之 Eureka 实现服务注册与发现
如果你对 Spring Cloud 体系还不是很了解,可以先读一下 Spring Cloud 都有哪些模块 Eureka 是 Netflix 开源的服务注册发现组件,服务发现可以说是微服务架构的核心功 ...
- 基于Spring cloud Ribbon和Eureka实现客户端负载均衡
前言 本案例将基于Spring cloud Ribbon和Eureka实现客户端负载均衡,其中Ribbon用于实现客户端负载均衡,Eureka主要是用于服务注册及发现: 传统的服务端负载均衡 常见的服 ...
- spring cloud config与eureka配合使用
前面两篇介绍了Spring Cloud Config服务端和客户端的简单配置,本篇介绍Spring Cloud Config与Eureka配合使用 前言 默认情况下,配置客户端启动时,都是通过配置属性 ...
随机推荐
- jquery 常用选择器基础语法学习
siblings方法的常用应用场景:选中高亮 实现代码 <!DOCTYPE html> <html> <head> <meta charset="U ...
- SSH框架之Spring第四篇
1.1 JdbcTemplate概述 : 它是spring框架中提供的一个对象,是对原始JdbcAPI对象的简单封装.spring框架为我们提供了很多的操作模板类. ORM持久化技术 模板类 JDBC ...
- HTML入门(列表、表单、常用表单控件、浮动框架、iframe、 摘要与细节、度量标签)
一.列表 1.作用:默认显示方式为从上到下的显示数据 2.列表的组成 列表类型和列表项 3.列表的分类:有序列表 无序列表 自定义列表 无序列表语法为ul>li, 语法:ul代表列表,l ...
- SpringBoot中使用Zuul
Zuul提供了服务网关的功能,可以实现负载均衡.反向代理.动态路由.请求转发等功能.Zuul大部分功能是通过过滤器实现的,除了标准的四种过滤器类型,还支持自定义过滤器. 使用@EnableZuulPr ...
- PHP switch的写法
switch switch (expression) { case label1: expression = label1 时执行的代码 ; break; case label2: expressio ...
- MySQL解惑——GROUP BY隐式排序
MySQL中GROUP BY隐式排序是什么概念呢? 主要是其它RDBMS没有这样的概念,如果没有认真了解过概念,对这个概念会感觉有点困惑,我们先来看看官方文档的介绍: 官方文档MySQL 5.7 Re ...
- 服务治理-Resilience4j(限流)
Bulkhead Bulkhead一般用于服务调用客户端,用于限定对特定的服务的并发请求数量,起到一下作用:1.防⽌下游依赖被并发请求冲击2.防⽌发⽣连环故障 1.配置规则“order” //允许最大 ...
- [CodeForces - 1272D] Remove One Element 【线性dp】
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...
- Python:requests库、BeautifulSoup4库的基本使用(实现简单的网络爬虫)
Python:requests库.BeautifulSoup4库的基本使用(实现简单的网络爬虫) 一.requests库的基本使用 requests是python语言编写的简单易用的HTTP库,使用起 ...
- Java题库——Chapter4 循环
1)How many times will the following code print "Welcome to Java"? int count = 0; while (co ...