Euerka环境搭建

机器环境
windows10,IntelliJ IDEA
配置host

单节点Eureka
一、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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>peter.test</groupId>
<artifactId>singleeureka</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>singleeureka</name>
<description>Demo project for Spring Cloud Eureka</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.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>10</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> <!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</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>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
在IDEA中,直接启动调试,会报错,添加进这个依赖就可以执行了。
注释掉 spring-boot-starter-test 是因为暂时不需要单元测试。
二、application.properties文件
spring.application.name=spring-cloud-eureka
server.port=9232
eureka.instance.hostname=peterhost1
eureka.client.service-url.defaultZone=http://peterhost2:9232/eureka/ debug=true
三、启动注解
@EnableEurekaServer
@SpringBootApplication
public class SingleeurekaApplication { public static void main(String[] args) {
SpringApplication.run(SingleeurekaApplication.class, args);
}
}
四、运行
打包
mvn clean package
运行并访问

多节点Euerka
一、pom文件
同单节点一样
二、application.yml文件
使用yml文件可以在命令启动时指定profile
---
spring:
application:
name: spring-cloud-eureka
profiles: peterhost1
server:
port: 9000
eureka:
instance:
hostname: peterhost1
client:
service-url:
defaultZone: http://peterhost2:9001/eureka/,http://peterhost3:9002/eureka/
---
spring:
application:
name: spring-cloud-eureka
profiles: peterhost2
server:
port: 9001
eureka:
instance:
hostname: peterhost2
client:
service-url:
defaultZone: http://peterhost3:9002/eureka/,http://peterhost1:9000/eureka/
---
spring:
application:
name: spring-cloud-eureka
profiles: peterhost3
server:
port: 9002
eureka:
instance:
hostname: peterhost3
client:
service-url:
defaultZone: http://peterhost1:9000/eureka/,http://peterhost2:9001/eureka/
作为高可用,第1个节点指定默认的zone为第2个和第3个节点,以此类推。
三、启动注解
@EnableEurekaServer
@SpringBootApplication
public class ThreeeurekaApplication { public static void main(String[] args) {
SpringApplication.run(ThreeeurekaApplication.class, args);
}
}
四、运行
打包
同上
运行并访问
java -jar 路径\threeeureka-0.0.-SNAPSHOT.jar --spring.profiles.active=peterhost1
java -jar 路径\threeeureka-0.0.-SNAPSHOT.jar --spring.profiles.active=peterhost2
java -jar 路径\threeeureka-0.0.-SNAPSHOT.jar --spring.profiles.active=peterhost3

配置文件中是按照hostname进行配置的,有时我们想直接使用ip,可如下设置:
eureka.instance.prefer-ip-address=true
eureka.ip-address=xxx.xxx.xxx.xxx
这样在Producer或者Consumer获取Eureka中的服务后,如使用Fegin等组件时则会使用ip进行访问。
Euerka环境搭建的更多相关文章
- .NET Core系列 : 1、.NET Core 环境搭建和命令行CLI入门
2016年6月27日.NET Core & ASP.NET Core 1.0在Redhat峰会上正式发布,社区里涌现了很多文章,我也计划写个系列文章,原因是.NET Core的入门门槛相当高, ...
- Azure Service Fabric 开发环境搭建
微服务体系结构是一种将服务器应用程序构建为一组小型服务的方法,每个服务都按自己的进程运行,并通过 HTTP 和 WebSocket 等协议相互通信.每个微服务都在特定的界定上下文(每服务)中实现特定的 ...
- rnandroid环境搭建
react-native 环境搭建具体步骤这个大家已经玩烂了,这个主要是记录下来自己做win7系统遇到的坑 1.com.android.ddmlib.installexception 遇到这个问题,在 ...
- python开发环境搭建
虽然网上有很多python开发环境搭建的文章,不过重复造轮子还是要的,记录一下过程,方便自己以后配置,也方便正在学习中的同事配置他们的环境. 1.准备好安装包 1)上python官网下载python运 ...
- springMVC初探--环境搭建和第一个HelloWorld简单项目
注:此篇为学习springMVC时,做的笔记整理. MVC框架要做哪些事情? a,将url映射到java类,或者java类的方法上 b,封装用户提交的数据 c,处理请求->调用相关的业务处理—& ...
- 【定有惊喜】android程序员如何做自己的API接口?php与android的良好交互(附环境搭建),让前端数据动起来~
一.写在前面 web开发有前端和后端之分,其实android还是有前端和后端之分.android开发就相当于手机app的前端,一般都是php+android或者jsp+android开发.androi ...
- Nexus(一)环境搭建
昨天,成功搭建了自己的 Maven 环境(详见:Maven(一)环境搭建),今天就来研究和探讨下 Nexus 的搭建! 使用背景: 安装环境:Windows 10 -64位 JDK版本:1.7 Mav ...
- 「译」JUnit 5 系列:环境搭建
原文地址:http://blog.codefx.org/libraries/junit-5-setup/ 原文日期:15, Feb, 2016 译文首发:Linesh 的博客:环境搭建 我的 Gith ...
- appium+robotframework环境搭建
appium+robotframework环境搭建步骤(Windows系统的appium自动化测试,只适用于测试安卓机:ios机需要在mac搭建appium环境后测试) 搭建步骤,共分为3部分: 一. ...
随机推荐
- iphone5 A1429国行IOS8.4.1 越狱 完美使用电信3G
国航 8.4.1,越狱,使用电信3G,能打电话,能发短信,正常上网使.(越狱降级方式,请参照本文末端连接) 有好多人说不管怎么试都是无服务,请查看 设置-蜂窝移动网络-漫游里面,必须只有 语音漫游 这 ...
- svg动画 animate
最近使用到svg的动画animate,简单总结下animate的主要属性: 1.定义:SVG 的animate 动画元素放在形状元素的内部,用来定义一个元素的某个属性如何踩着时点改变.在指定持续时间里 ...
- Python 生成个性二维码
1.1 实验内容 本课程通过调用MyQR接口来实现生成个人所需二维码,并可以设置二维码的大小.是否在现有图片的基础上生成.是否生成动态二维码. 本课程主要面向Python3初学者. 1.2 知识点 P ...
- [转]centos7.2 下 nginx 开机启动
1.在系统服务目录里创建nginx.service文件 vi /lib/systemd/system/nginx.service 内容如下 [Unit] Description=nginx After ...
- [Xcode 实际操作]三、视图控制器-(11)在Storyboard中使用表格控件
目录:[Swift]Xcode实际操作 本文将演示表格控件在故事板中的使用. 点击[显示或隐藏检查器按钮],再界面右侧打开检查器面板. 在控制器根视图上点击鼠标,以选择该根视图. 现在往根视图中添加一 ...
- Mybatis插件Plugin
Mybatis开源Plugin中最熟知的pagehelper,重点made in China 很多人开始用pagehelper时候,肯定很纳闷,以mysql为例,明明没有加limit语句,为什么打印出 ...
- Python中print()函数不换行的方法
一.让print()函数不换行 在Python中,print()函数默认是换行的.但是,在很多情况下,我们需要不换行的输出(比如在算法竞赛中).那么,在Python中如何做到这一点呢? 其实很简单.只 ...
- 弹层组件文档 - layui.layer
http://www.layui.com/doc/modules/layer.html
- Matrix Power Series POJ - 3233 矩阵幂次之和。
矩阵幂次之和. 自己想着想着就想到了一个解法,但是还没提交,因为POJ崩了,做了一个FIB的前n项和,也是用了这个方法,AC了,相信是可以得. 提交了,是AC的 http://poj.org/prob ...
- Java面向对象_抽象类应用——模板方法模式
概念:定义一个操作中的算法的骨架,而将一些可变部分的实现延迟到子类中.模板方法模式使得子类可以不改变一个算法的结构即可重新定义该算法的某些特定的步骤. 去个例子分析一下这个概念: public cla ...