本文只有一个eureka server项目,运行在不同的端口,模拟两台eureka服务。开发使用eclipse 4.8

先说pom.xml文件,如果出现问题,首先考虑springboot和其他包版本冲突

<?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>com.xing</groupId>
<artifactId>springboot-eureka</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.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>
</properties> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR3</version><!--Edgware.SR4 Finchley.RELEASE -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <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-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- 仓库管理 -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<!-- 指定profiles -->
<profiles>
<profile>
<id>first</id>
<activation>
<!-- 默认激活 -->
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>first</spring.profiles.active>
</properties>
</profile>
<profile>
<id>second</id>
<properties>
<spring.profiles.active>second</spring.profiles.active>
</properties>
</profile>
</profiles>
</project>

因为是使用eclipse,想要多个实例好像只能采用多个yml或properties配置文件

application.ym如下:

spring:
profiles:
active: first

application-first.yml如下:

spring:
application:
name: xing-eurekaServer #指定服务名
prifiles: first
server:
port: #服务端口 eureka:
client:
registerWithEureka: true #是否将自己注册到Eureka服务中,本身就是所有无需注册
fetchRegistry: true #是否从Eureka中获取注册信息
serviceUrl: #Eureka客户端与Eureka服务端进行交互的地址
defaultZone: http://xing-eurekaServer:/eureka/
instance:
prefer-ip-address: true #将自己的ip地址注册到Eureka服务中
ip-address: 127.0.0.1
instance-id: xing-eurekaServer:8090 #指定实例id
hostname: 127.0.0.1
server:
enable-self-preservation: false #禁用自我保护模式
eviction-interval-timer-in-ms: 60000 #清理间隔(单位毫秒,默认是60*1000)

application-second.yml如下:

spring:
application:
name: xing-eurekaServer #指定服务名
prifiles: second
server:
port: #服务端口 eureka:
client:
registerWithEureka: true #是否将自己注册到Eureka服务中,本身就是所有无需注册
fetchRegistry: true #是否从Eureka中获取注册信息
serviceUrl: #Eureka客户端与Eureka服务端进行交互的地址
defaultZone: http://xing-eurekaServer:/eureka/
instance:
prefer-ip-address: true #将自己的ip地址注册到Eureka服务中
ip-address: 127.0.0.1
instance-id: xing-eurekaServer:8091 #指定实例id
hostname: 127.0.0.1
server:
enable-self-preservation: false #禁用自我保护模式
eviction-interval-timer-in-ms: 60000 #清理间隔(单位毫秒,默认是60*1000)

其中后面两个yml文件中的

serviceUrl:
defaultZone: http://xing-eurekaServer:8090/eureka/要使用xing-eurekaServer之类的域名,通过host映射到127.0.0.1,此处不讲如何配置c盘的host文件,如果不采用域名的话可能刚启动服务的时候是有两个服务,但是后面刷新着就只剩一个服务了,此时查看后台日志会
发现eureka在cancle服务,并且页面上的registered-replicas为空,推荐配置host。
 
从上面的两个yml中可以看出来,first向second中注册,second向first中注册。这样相互注册,当你其他的服务想往这两台eureka server服务器中注册服务时,只需要向其中一台注册,两台eureka中都会有你注册的服务,实现了高可用性。

启动类SpringDemoApplication 如下:
package com.xing.springboot;

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

启动项目配置如下:

启动之后访问http://127.0.0.1:8090/可以看到如下页面,页面上部分的红字是因为单机状态,eureka给的警告,可以不用管

 源码地址:https://github.com/OnlyXingxing/SpringCloud

eureka多实例,模拟多台机器的更多相关文章

  1. 如何在同一台机器上安装多个MySQL的实例

    转自:'http://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的 ...

  2. 如何在同一台机器上安装多个MySQL的实例 转

    https://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MyS ...

  3. kubernetes要实现的目标——随机关掉一台机器,看你的服务能否正常;减少的应用实例能否自动迁移并恢复到其他节点;服务能否随着流量进行自动伸缩

    Kubernetes 是来自 Google 云平台的开源容器集群管理系统.基于 Docker 构建一个容器的调度服务.该系统可以自动在一个容器集群中选择一个工作容器供使用.其核心概念是 Contain ...

  4. 如何在同一台机器上安装多个MySQL的实例(转)

    最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MySQL的实例). 先说下,什么是mysql的多实例,简单的来说就是一台机器上安装了多个mysql的服务 ...

  5. 在一台机器上搭建多个redis实例

    默认Redis程序安装在/usr/local/redis目录下: 配置文件:/usr/local/redis/redis.conf,该配置文件中配置的端口为默认端口:6379: Redis的启动命令路 ...

  6. 使用ARP欺骗, 截取局域网中任意一台机器的网页请求,破解用户名密码等信息

    ARP欺骗的作用 当你在网吧玩,发现有人玩LOL大吵大闹, 用ARP欺骗把他踢下线吧 当你在咖啡厅看上某一个看书的妹纸,又不好意思开口要微信号, 用arp欺骗,不知不觉获取到她的微信号和聊天记录,吓一 ...

  7. centos 安装redis(一台机器可以安装多个redis)

    我在运行时redis版本是2.8 操作前设置以管理员身份: 打开终端输入 su - 安装redis需要确保系统已经安装了(gcc gcc-c++)# yum -y install gcc gcc-c+ ...

  8. 在同一台机器上让Microsoft SQL Server 2000/ SQL2005/ SQL2008共存

    可能很多朋友都遇到想同时在自己的机器上运行Microsoft SQL Server 2000以及Microsoft SQL Server 2005和Microsoft SQL Server 2008. ...

  9. 【技术贴】同一台机器Tomcat7多版本共存配置文档

    首先准备好自己下载的Tomcat7的绿色版,一定要是解压的绿色版不能使exe安装包.因为exe安装版很多变量不好配置,我以前最喜欢exe版了,方便快捷,但是我发现还是绿色解压版比较好,优化配置等也很好 ...

随机推荐

  1. Linux/x86-64 - setuid(0) & chmod ("/etc/passwd", 0777) & exit(0) - 63 byes

    /* Title: Linux/x86-64 - setuid(0) & chmod ("/etc/passwd", 0777) & exit(0) - 63 by ...

  2. change transformation file in PI interface

    1. Jane extends the ZTMMASKU sap table 2. Jane write the program to write the new attribute to the t ...

  3. 案例-3D旋转木马

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. LeetCode Array Easy 88. Merge Sorted Array

    Description Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted ar ...

  5. WPF 从服务器下载文件

    1.先获取服务器下载地址,给出要下载到的目标地址 public void DownloadFileFromServer() { string serverFilePath = "http:/ ...

  6. HDU-4747 二分+线段树

    题意:给出长度为n的序列,问任两个区间的mex运算结果的总和. 解法:直接讲线段树做法:我们注意到mex(1,1),mex(1,2),mex(1,3)...mex(1,i)的结果是单调不减的,那么我们 ...

  7. codeforces round 433 C. Planning 贪心

    题目大意: 输入n,k,代表n列航班,初始始发实践为1,2,3分钟以此类推,然后输入n个整数分别代表延迟1分钟第i个航班损失多少钱,然后调整后的始发时间表是这样的,任何一辆航班的始发时间不能在他的初始 ...

  8. vue element-ui NavMenu错位问题

    原因:子菜单全部打开后太长超过100% 解决方法:设置只能点击打开当前的菜单

  9. 在Kubernetes下部署Prometheus

    使用ConfigMaps管理应用配置 当使用Deployment管理和部署应用程序时,用户可以方便了对应用进行扩容或者缩容,从而产生多个Pod实例.为了 能够统一管理这些Pod的配置信息,在Kuber ...

  10. css盒模型宽高混合计算calc

    例如: .element{ width:calc(expression); } 兼容性:在IE9+.FF4.0+.Chrome19+.Safari6+都得到了较好支持,但是在移动端的支持不是很好. 其 ...