Eureka集群搭建

高可用集群配置

当注册中心扛不住高并发的时候,这时候 要用集群来扛;

普通操作

我们再新建两个module  microservice-eureka-server-2002  microservice-eureka-server-2003

1、pom.xml 把依赖加下;

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion>
<parent>
<groupId>com.jt</groupId>
<artifactId>microservice</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>microservice-eureka-server-</artifactId> <properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 修改后立即生效,热部署 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

2、2002  2003的主启动类EurekaServerApplication_2002,EurekaServerApplication_2003复制修改下;

package com.jt.microserviceeurekaserver2002;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer
@SpringBootApplication
public class MicroserviceEurekaServer2002Application { public static void main(String[] args) {
SpringApplication.run(MicroserviceEurekaServer2002Application.class, args);
} }

3、前面单机的时候 eureka注册中心实例名称 是localhost,现在是集群,不能三个实例都是localhost,这里复杂的办法是搞三个虚拟机,麻烦,这里有简单办法,直接配置本机hosts,来实现本机域名映射;

找到 C:\Windows\System32\drivers\etc  打开hosts,加配置

127.0.0.1  eureka2001.jt.com
127.0.0.1 eureka2002.jt.com
127.0.0.1 eureka2003.jt.com

修改三个项目的application.yml文件,主要是修改 hostname和defaultZone,

2001修改:

server:
port:
context-path: / eureka:
instance:
hostname: eureka2001.jt.com
client:
register-with-eureka: false
service-url:
defaultZone: http://eureka2002.jt.com:2002/eureka/,http://eureka2003.jt.com:2003/eureka/ # 集群

2002

server:
port:
context-path: / eureka:
instance:
hostname: eureka2002.jt.com
client:
register-with-eureka: false
service-url:
defaultZone: http://eureka2001.jt.com:2001/eureka/,http://eureka2003.jt.com:2003/eureka/

2003

server:
port:
context-path: / eureka:
instance:
hostname: eureka2003.jt.com
client:
register-with-eureka: false
service-url:
defaultZone: http://eureka2001.jt.com:2001/eureka/,http://eureka2002.jt.com:2002/eureka/

骚操作

上面eureka服务搭建,除了yml文件不一样,其他文件都一样,那么我们有什么办法能够将多个eureka服务集合到一个工程中去呢?

创建一个microservice-eureka-server(三合一)子工程

Pom依赖

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion>
<parent>
<groupId>com.jt</groupId>
<artifactId>microservice</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>microservice-eureka-server</artifactId> <properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 修改后立即生效,热部署 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

Yml文件

---
server:
port:
context-path: /
eureka:
instance:
hostname: eureka2001.jt.com
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://eureka2002.jt.com:2002/eureka/,http://eureka2003.jt.com:2003/eureka/
spring:
profiles: eureka2001
---
server:
port:
context-path: /
eureka:
instance:
hostname: eureka2002.jt.com
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://eureka2001.jt.com:2001/eureka/,http://eureka2003.jt.com:2003/eureka/
spring:
profiles: eureka2002
---
server:
port:
context-path: /
eureka:
instance:
hostname: eureka2003.jt.com
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://eureka2001.jt.com:2001/eureka/,http://eureka2002.jt.com:2002/eureka/
spring:
profiles: eureka2003

启动类MicroserviceEurekaServerApplication.java

package com.jt.microserviceeurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer
@SpringBootApplication
public class MicroserviceEurekaServerApplication { public static void main(String[] args) {
SpringApplication.run(MicroserviceEurekaServerApplication.class, args);
} }

跑起来的效果跟普通操作的效果是一致的;

Eureka自我保护机制

开发环境,我们经常会遇到这个红色的警告;

当我们长时间为访问服务以及变更服务实例名称的时候,就会出现这个红色警告;

默认情况,如果服务注册中心再一段时间内没有接收到某个微服务实例的心跳,服务注册中心会注销该实例(默认90秒)。

由于正式环境,经常会有网络故障,网络延迟问题发生,服务和注册中心无法正常通信,此时服务是正常的,不应该注销该服务,Eureka这时候,就通过“自我保护模式”来解决问题,当短时间和服务失去通信时,保留服务信息,当恢复网络和通信时候,退出“自我保护模式”;

通过“自我保护模式”,使Eureka集群更加的健壮和稳定;

Eureka集群的更多相关文章

  1. 微服务架构:Eureka集群搭建

    版权声明:本文为博主原创文章,转载请注明出处,欢迎交流学习! 服务注册.发现是微服务架构的关键原理之一,由于微服务架构是由一系列职责单一的细粒度服务构成的网状结构,服务之间通过轻量机制进行通信,这就必 ...

  2. 基于dns搭建eureka集群

    eureka集群方案: 1.通常我们部署的eureka节点多于两个,根据实际需求,只需要将相邻节点进行相互注册(eureka节点形成环状),就达到了高可用性集群,任何一个eureka节点挂掉不会受到影 ...

  3. eureka集群基于DNS配置方式

    https://www.cnblogs.com/relinson/p/eureka_ha_use_dns.html   最近在研究spring cloud eureka集群配置的时候碰到问题:多台eu ...

  4. eureka集群的两种配置方式:配置文件方式与DNS方式

    eureka client获取serviceUrls(eureka server地址)列表的过程: 1. 根据use-dns-for-fetching-service-urls属性判断是从dns还是从 ...

  5. SpringCloud之Eureka集群

    前面我们介绍了SpringCloud注册中心Eureka,但是存在一个单点故障的问题,一个注册中心远远不能满足实际的生产环境,现在我们介绍一下如何搭建一个Eureka集群. 一:集群环境搭建 我们先建 ...

  6. eureka集群高可用配置

    譬如eureka.client.register-with-eureka和fetch-registry是否要配置,配不配区别在哪里:eureka的客户端添加service-url时,是不是需要把所有的 ...

  7. Eureka集群试验的一点总结

    先简单描述一下试验: 试验在一台机器上进行,假设有host文件中配置了以下内容 127.0.0.1 left 127.0.0.1 center 127.0.0.1 right 试验中搭建三个注册中心实 ...

  8. 【spring cloud】spring cloud中启动eureka集群时候,发生端口已经绑定的报错The Tomcat connector configured to listen on port 8000 failed to start. The port may already be in use or the connector may be misconfigured.

    在分别设置 进行微服务eureka集群启动时候,执行命令行启动jar包时候,报错前面一个端口8000已经被使用,而我这里启动的配置文件中端口号是8001,怎么会导致端口冲突呢?? 但是报错我的端口冲突 ...

  9. eureka集群高可用配置,亲测成功配置(转)

    转自大神的文章:https://blog.csdn.net/tianyaleixiaowu/article/details/78184793 网上讲这个东西的很多,抄来抄去的,大部分类似,多数没讲明白 ...

  10. Eureka集群搭建

    服务注册.发现是微服务架构的关键原理之一,由于微服务架构是由一系列职责单一的细粒度服务构成的网状结构,服务之间通过轻量机制进行通信,这就必然引入一个服务注册发现的问题,也就是说服务提供方要注册报告服务 ...

随机推荐

  1. Codeves-5037线段树4加强版(线段树? 。。。分块)

    维护一个序列,要求支持下列2种操作: add a b c:区间[a,b]中每个数加上c count a b:查询区间[a,b]中有多少数是k的倍数(k为给定常数) 输入描述 Input Descrip ...

  2. 使用g++编译器扩大程序可用栈空间

    如题,在写一些程序的时候我们有时会开一个比较大的数组或进行层数较多的dfs.这时候,程序常常会报错,于是就很无奈. 其实,虽然Windows给程序的默认栈空间比较小,我们还是有办法去扩大这个程序运行栈 ...

  3. JSP+Servlet 实现:理财产品信息管理系统

    一.接业务,作分析 1.大致业务要求 1.1 使用 JSP+Servlet 实现理财产品信息管理系统,MySQL5.5 作为后台数据库,实现查看理财 和增加理财功能 1.2 查询页面效果图 1.3 添 ...

  4. ARTS-S pytorch中Conv2d函数padding和stride含义

    padding是输入数据最边缘补0的个数,默认是0,即不补0. stride是进行一次卷积后,特征图滑动几格,默认是1,即滑动一格.

  5. jq触发oninput事件

    之前一直在用jq的change()方法来处理输入框的值变化事件,以及触发输入框的变化事件. 后来发现change()方法有个弊端,change事件的发生条件是:输入框的值value发生变化,并且输入框 ...

  6. cd ..、cd / 和 cd ~ 的区别

    cd ..是回到上一级目录 cd . 是当前目录 cd / 是回到根目录 cd ~ 回到用户主目录

  7. Java连载63-异常处理try...catch...、方法getMessageyu printStackTrace

    一.处理异常的第二种方法 1.try......catch... 语法: try{ 可能出现异常的代码: }catch{ 处理异常的代码: }catch{ 注意: (1)引入了什么异常,catch里面 ...

  8. More than one file was found with OS independent path 'lib/armeabi-v7a/libgnustl_shared.so'

    More than one file was found with OS independent path 'xxx/xxx' 这个错误是在路径中出现了重复依赖. 解决办法是配置打包选项, 在 and ...

  9. windows客户端访问FTP服务器

    客户端访问FTP服务器步骤: 首先双击此电脑,在弹出的窗口输入如下信息 刚安装完的FTP服务器只有一个pub目录,因为这里是使用匿名用户登录的 FTP服务器默认的匿名目录在/var/ftp/pub/下 ...

  10. Leetcode92: Reverse Linked List II 翻转链表问题

    问题描述 给定一个链表,要求翻转其中从m到n位上的节点,返回新的头结点. Example Input: 1->2->3->4->5->NULL, m = 2, n = 4 ...