Spring Cloud官方文档中文版-服务发现:Eureka服务端
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR3/#spring-cloud-eureka-server
文中例子我做了一些测试在:http://git.oschina.net/dreamingodd/spring-cloud-preparation
Service Discovery: Eureka Server 服务发现:Eureka服务端
How to Include Eureka Server 如何创建Eureka服务端
To include Eureka Server in your project use the starter with group org.springframework.cloud and artifact id spring-cloud-starter-eureka-server. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.
使用Eureka服务需要引入org.springframework.cloud的spring-cloud-starter-eureka-server项目。可以参考http://projects.spring.io/spring-cloud/来创建你的第一个Eureka服务。
How to Run a Eureka Server 如何运行Eureka服务端
@SpringBootApplication
@EnableEurekaServer
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
The server has a home page with a UI, and HTTP API endpoints per the normal Eureka functionality under /eureka/*.
Eureka服务端有一个默认的UI主页,每个Eureka服务端你都有一个HTTP API节点在/eureka/*
Eureka background reading: see flux capacitor and google group discussion.
想了解更多Eureka背景知识,推荐阅读 https://github.com/cfregly/fluxcapacitor/wiki/NetflixOSS-FAQ#eureka-service-discovery-load-balancerhttps://groups.google.com/forum/?fromgroups#!topic/eureka_netflix/g3p2r7gHnN0
TIP Due to Gradle’s dependency resolution rules and the lack of a parent bom feature, simply depending on spring-cloud-starter-eureka-server can cause failures on application startup. To remedy this the Spring Boot Gradle plugin must be added and the Spring cloud starter parent bom must be imported like so:
gradle引入:
build.gradle
buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE")
}
}
apply plugin: "spring-boot"
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.RELEASE"
}
}
High Availability, Zones and Regions 高可用,地区和地域
The Eureka server does not have a backend store, but the service instances in the registry all have to send heartbeats to keep their registrations up to date (so this can be done in memory). Clients also have an in-memory cache of eureka registrations (so they don’t have to go to the registry for every single request to a service).
Eureka服务器并不在后端存储,但注册机中的服务实例都必须用心跳信息维持他们的最新的注册状态(也就是说可以在内存完成)。客户端同样也有一份注册信息缓存存在内存里。
By default every Eureka server is also a Eureka client and requires (at least one) service URL to locate a peer. If you don’t provide it the service will run and work, but it will shower your logs with a lot of noise about not being able to register with the peer. 默认情况下,每一个Eureka服务器也时一个Eureka客户端,同样需要(至少一个)service URL来定位节点。虽然即使开发人员不提供仍然能跑,但是会大量打出无法注册的垃圾log。
See also below for details of Ribbon support on the client side for Zones and Regions.
Standalone Mode 单机模式
The combination of the two caches (client and server) and the heartbeats make a standalone Eureka server fairly resilient to failure, as long as there is some sort of monitor or elastic runtime keeping it alive (e.g. Cloud Foundry). In standalone mode, you might prefer to switch off the client side behaviour, so it doesn’t keep trying and failing to reach its peers. Example:
只要存在某种监控或弹性运行时间来使服务存活(如Cloud Foundry),两个缓存和心跳协议的组合就能让单机的Eureka服务器对故障保有相当的弹性。单机模式下,开发人员可能更喜欢关闭服务器的客户端行为,这样服务端就不必一直尝试失败地访问节点。
application.yml (Standalone Eureka Server)
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Notice that the serviceUrl is pointing to the same host as the local instance.
注意serviceUrl跟本地实例是一样的。
Peer Awareness 节点感知(高可用)
Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. In fact, this is the default behaviour, so all you need to do to make it work is add a valid serviceUrl to a peer, e.g.
Eureka服务器通过跑多个实例并要求注册彼此,可以变得更具弹性。实际上,这是Eureka的默认使用方式,那么你需要给节点加入有效的serviceUrl使其正常工作。例如:
application.yml (Two Peer Aware Eureka Servers)
---
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2/eureka/
---
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1/eureka/
In this example we have a YAML file that can be used to run the same server on 2 hosts (peer1 and peer2), by running it in different Spring profiles. You could use this configuration to test the peer awareness on a single host (there’s not much value in doing that in production) by manipulating /etc/hosts to resolve the host names. In fact, the eureka.instance.hostname is not needed if you are running on a machine that knows its own hostname (it is looked up using java.net.InetAddress by default).
通过运行不同的Spring profile,本例中的YAML配置文件是在不同主机上的同一服务器(节点1和节点2)。开发人员通过操纵/etc/hosts伪造127.0.0.1的主机名,可以在同一主机上测试(这样做生产环境上没有价值)。实际上,eureka.instance.hostname这个配置项在生产环境没有用(PC会查询java.net.InetAddres获取到)。
You can add multiple peers to a system, and as long as they are all connected to each other by at least one edge, they will synchronize the registrations amongst themselves. If the peers are physically separated (inside a data centre or between multiple data centres) then the system can in principle survive split-brain type failures.
只要节点之间互相连接,开发人员可以为系统添加多个节点,它们之间会同步注册信息。如果节点是物理分离的(在一个或多个数据中心),那么系统原则上可以无视split-brain型故障而运行。
Prefer IP Address 使用IP
In some cases, it is preferable for Eureka to advertise the IP Adresses of services rather than the hostname. Set eureka.instance.preferIpAddress to true and when the application registers with eureka, it will use its IP Address rather than its hostname.
某些情况下,使用IP比hostname好。eureka.instance.preferIpAddress=true可以做到这一点。
dreamingodd原创文章,如转载请注明出处。
Spring Cloud官方文档中文版-服务发现:Eureka服务端的更多相关文章
- Spring Cloud官方文档中文版-服务发现:Eureka客户端
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_spring_cloud_netflix 文中例子我做了一些测试在:h ...
- Spring Cloud官方文档中文版-Spring Cloud Config(上)-服务端(配置中心)
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http ...
- Spring Cloud官方文档中文版-客户端负载均衡:Ribbon
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_spring_cloud_netflix 文中例子我做了一些测试在:h ...
- Spring Cloud官方文档中文版-Spring Cloud Config(上)
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http ...
- Spring Cloud官方文档中文版-Spring Cloud Config(下)-客户端等
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_serving_alternative_formats 文中例子我做了 ...
- Spring Cloud官方文档中文版-声明式Rest客户端:Feign
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http ...
- spring cloud官方文档提到的服务开发的12项要素。
I. Codebase 从一个代码库部署到多个环境. II. Dependencies 使用显式的声明隔离依赖,即模块单独运行,并可以显式管理依赖. III. Config 在系统外部存储配置信息. ...
- Spring 4 官方文档学习(十二)View技术
关键词:view technology.template.template engine.markup.内容较多,按需查用即可. 介绍 Thymeleaf Groovy Markup Template ...
- Spring 4 官方文档学习(十一)Web MVC 框架之配置Spring MVC
内容列表: 启用MVC Java config 或 MVC XML namespace 修改已提供的配置 类型转换和格式化 校验 拦截器 内容协商 View Controllers View Reso ...
随机推荐
- bzoj3728: PA2014Final Zarowki
Description 有n个房间和n盏灯,你需要在每个房间里放入一盏灯.每盏灯都有一定功率,每间房间都需要不少于一定功率的灯泡才可以完全照亮. 你可以去附近的商店换新灯泡,商店里所有正整数功率的 ...
- Solr-Centos7 安装部署solr-5.5.4
一 下载安装所需文件 http://archive.apache.org/dist/lucene/solr/ solr-5.5.4.tgz http://archive.apache.org/dist ...
- 学生问的一道javascript面试题[来自腾讯]
function Parent() { this.a = 1; this.b = [1, 2, this.a]; this.c = { demo: 5 }; this.show = function ...
- ASP.NET Core MVC – 自定义 Tag Helpers
ASP.NET Core Tag Helpers系列目录,共四篇: ASP.NET Core MVC Tag Helpers 介绍 ASP.NET Core MVC – Caching Tag Hel ...
- JS实现添加至购物车功能
效果图展示: 当将书拖拽至购物车一览时: 首先将页面的基本结构写出来: <!DOCTYPE html> <html lang="en"> <head& ...
- Mysql事务处理详细讲解及完整实例下载
一.Mysql事务概念 MySQL 事务主要用于处理操作量大,复杂度高的数据.由一步或几步数据库操作序列组成逻辑执行单元,这系列操作要么全部执行,要么全部放弃执行.在 MySQL 中只有使用了 Inn ...
- 用R进行文本分析初探——以《红楼梦》为例
一.写在前面的话~ 刚吃饭的时候同学问我,你为什么要用R做文本分析,你不是应该用R建模么,在我和她解释了一会儿后,她嘱咐我好好写这篇博文,嗯为了娟儿同学,细细说一会儿文本分析. 文本数据挖掘(Text ...
- sqlite 的基本使用1
mac 下自带的sqlite3 直接在终端键入 sqlite3 即进入 sqlite的交互界面 1,创建数据库 sqlite3 命令 被用来创建新的数据库 比如sqlite3 mydb,即创建了一个m ...
- 使用bootstrap网格系统自适应盒子宽度时保持所有盒子高度一致。
使用了bootstrap网格系统的好处是很容易便实现了响应式布局,盒子可以根据设置的样式,随着屏幕的大小改变而自动改变宽度,但是也存在一个问题,那就是盒子的高度是由盒子的内容决定的,如果盒子里的内容不 ...
- 项目管理利器---Maven
Maven快速入门 maven介绍 maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建.报告和软件的项目管理工具.简单来说,maven可以帮助我们更有效的管理项目,也是一套 ...