工具:idea

环境:java8、maven3

版本:spring boot 1.5.15.RELEASE

1.搭建spring boot eureka项目

2. 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>webapp</groupId>
<artifactId>eureka</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>eureka</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.15.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR4</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

3.修改配置文件后缀为yml,application.yml内容如下:

spring:
application:
name: eureka-server
security:
user:
name: admin
password: 123456
eureka:
p1:
hostname: server1
port: 1111
p2:
hostname: server2
port: 1112
p3:
hostname: server3
port: 1113

4. 新建application-peer1.yml、application-peer2.yml、application-peer3.yml

application-peer1.yml:

server:
port: 1111
eureka:
instance:
hostname: ${eureka.p1.hostname}
client:
service-url:
defaultZone: http://${security.user.name}:${security.user.password}@${eureka.p2.hostname}:${eureka.p2.port}/eureka/,http://${security.user.name}:${security.user.password}@${eureka.p3.hostname}:${eureka.p3.port}/eureka/

application-peer2.yml:

server:
port: 1112
eureka:
instance:
hostname: ${eureka.p2.hostname}
client:
service-url:
defaultZone: http://${security.user.name}:${security.user.password}@${eureka.p1.hostname}:${eureka.p1.port}/eureka/,http://${security.user.name}:${security.user.password}@${eureka.p3.hostname}:${eureka.p3.port}/eureka/

application-peer3.yml:

server:
port: 1113
eureka:
instance:
hostname: ${eureka.p3.hostname}
client:
service-url:
defaultZone: http://${security.user.name}:${security.user.password}@${eureka.p1.hostname}:${eureka.p1.port}/eureka/,http://${security.user.name}:${security.user.password}@${eureka.p2.hostname}:${eureka.p2.port}/eureka/

service-url这里是重点,我将server1的service-url设置为server2、server3,将server2的设置为server1、server3,将server3的设置为server1、server2。以此完成3个server服务间的相互注册 。

4. 本地模拟域名配置:

由于我们使用了http://server1这种写法,需要配一下host:

5. 启动类配置@EnableEurekaServer:

package webapp;

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

6. 分别配置和启动3个eureka服务

peer2和peer3类似以上设置,最后如下:

7.分别启动3个服务

8.分别访问各自的端口

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

可以看到图上registered-replicas和available-replicas分别有了对方的地址。
eureka服务端的配置就这样就OK了。

微服务架构eureka集群高可用配置的更多相关文章

  1. Eureka 集群高可用配置.

    SERVER:1 server: port: 1111 eureka: instance: hostname: ${spring.cloud.client.ip-address} instance-i ...

  2. eureka集群高可用配置

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

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

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

  4. 庐山真面目之六微服务架构Consul集群、Ocelot网关集群和Nginx版本实现

    庐山真面目之六微服务架构Consul集群.Ocelot网关集群和Nginx版本实现 一.简介      在上一篇文章<庐山真面目之五微服务架构Consul集群.Ocelot网关和Nginx版本实 ...

  5. 庐山真面目之七微服务架构Consul集群、Ocelot网关集群和IdentityServer4版本实现

    庐山真面目之七微服务架构Consul集群.Ocelot网关集群和IdentityServer4版本实现 一.简介      在上一篇文章<庐山真面目之六微服务架构Consul集群.Ocelot网 ...

  6. Spring Cloud构建微服务架构(六)高可用服务注册中心

    http://blog.didispace.com/springcloud6/ https://www.jianshu.com/p/df9393755a05 http://www.ityouknow. ...

  7. 交付Dubbo微服务到kubernetes集群

    1.基础架构 1.1.架构图 Zookeeper是Dubbo微服务集群的注册中心 它的高可用机制和k8s的etcd集群一致 java编写,需要jdk环境 1.2.节点规划 主机名 角色 ip hdss ...

  8. 庐山真面目之四微服务架构Consul集群和Nginx版本实现

    庐山真面目之四微服务架构Consul集群和Nginx版本实现 一.简介      在上一篇文章<庐山真面目之三微服务架构Consul版本实现>中,我们已经探讨了如何搭建基于单节点Consu ...

  9. 浅谈MySQL集群高可用架构

    前言 高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.对于一个系统而言,可能包含很多模块,比如前端应用,缓存,数据库,搜索,消息队列等,每个模块都需要做到高可用,才能 ...

随机推荐

  1. django中将model转换为dict的方法

    django中将model转换为dict的方法 from django.forms.models import model_to_dict from user.model import userpro ...

  2. web spring 容器

    使用spring的web应用时,不用手动创建spring容器,而是通过配置文件声明式地创建spring容器,因此,在web应用中创建spring容器有如下两种方式: 一.直接在web.xml文件中配置 ...

  3. 1. K-Means原理解析

    1. K-Means原理解析 2. K-Means的优化 3. sklearn的K-Means的使用 4. K-Means和K-Means++实现 1. 前言 我们在一开始的时候应该就说过,机器学习按 ...

  4. Eclipse C++的配置问题launch failed binary not found

    首先下载eclipse c++ 我的是64bit版本 安装好MinGW,并配置好环境变量,参考我的博客 http://www.cnblogs.com/fickleness/p/3273044.html ...

  5. struts工作原理不错的解释___

    Struts 使用 Model 2 架构.Struts 的ActionServlet 控制导航流.其他Struts 类,比如Action, 用来访问业务逻辑类.当 ActionServlet 从容器接 ...

  6. wamp安装xdebug特殊情况win7 64位安装32位wamp

    在wamp上安装xdebug网上很多文章都介绍了方法,但是我这里遇到了一个很特殊的情况,在网上很少有人提及: 我机器是win7 64位的,安装的wamp1.7.4是32位的,这是后来导致出现奇怪现象的 ...

  7. JS正则验证邮箱的格式(转)

    转载自:https://www.cnblogs.com/dyllove98/archive/2013/06/28/3161626.html 一.相关的代码 function test() { var ...

  8. mongo源码学习(四)服务入口点ServiceEntryPoint

    在上一篇博客mongo源码学习(三)请求接收传输层中,稍微分析了一下TransportLayer的作用,这篇来看下ServiceEntryPoint是怎么做的. 首先ServiceEntryPoint ...

  9. u-boot2016.05 有关 4096page size , oob == 224 nand 的移植支持

    大致介绍一下这个 nand 的基础属性 pagesize == 4096 byte oob == 224 byte block size == 256 Kbyte u-boot configs/xxx ...

  10. 各种开源协议介绍 BSD、Apache Licence、GPL V2 、GPL V3 、LGPL、MIT_转

    转自:各种开源协议介绍 BSD.Apache Licence.GPL V2 .GPL V3 .LGPL.MIT 现今存在的开源协议很多,而经过Open Source Initiative组织通过批准的 ...