SpringCloud2.0 Eureka Server 服务中心 基础教程(二)
1、创建【服务中心】,即 Eureka Server
1.1、新建 Spring Boot 工程,工程名称: springcloud-eureka-server
1.2、工程 pom.xml 文件添加如下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
1.3、在工程启动类中,添加注解 @EnableEurekaServer
package com.miniooc.eurekaserver; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; /**
* EurekaServerApplication
*
* @author 宋陆
* @version 1.0.0
*/
@EnableEurekaServer // 启用 eureka server 相关默认配置
@SpringBootApplication // 等价于 @Configuration、@EnableAutoConfiguration、@ComponentScan
public class EurekaServerApplication { public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
} }
1.4、新建工程配置文件 application.yml ,配置内容:
server:
port: 9527 spring:
application:
name: eureka-server eureka:
instance:
hostname: localhost
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
register-with-eureka: false # 默认为 true。设为 false,仅作为服务中心,不作为服务客户端。
fetch-registry: false # 默认为true。设为false,不从服务中心检索注册的服务。
server:
eviction-interval-timer-in-ms: 5000 #清理间隔(单位毫秒,默认是60*1000)
enable-self-preservation: true # 默认为true。设为false,关闭自我保护。
# Eureka Server 在运行期间会去统计心跳失败比例在 15 分钟之内是否低于 85%
renewal-percent-threshold: 0.1 # 默认是0.85
1.5、启动 服务中心 工程,打开浏览器,访问 服务中心 前台页面:http://localhost:9527

红框处 No instances available :没有可用的实例。目前还任何服务注册到服务中心。
至此,一个简单的单点服务中心搭建完成。
为了保证服务的高可用,我们需要把单点应用改成集群应用。
接下来,我们对服务中心工程做些配置修改,来完成集群部署。
2、搭建【服务中心】集群
2.1、创建工程配置文件 application-server1.yml ,配置内容:
server:
port: 9527 spring:
application:
name: eureka-server eureka:
instance:
hostname: localhost
client:
serviceUrl:
defaultZone: http://localhost:9527/eureka/,http://localhost:9528/eureka/,http://localhost:9529/eureka/
register-with-eureka: false # 默认为 true。设为 false,仅作为服务中心,不作为服务客户端。
fetch-registry: false # 默认为true。设为false,不从服务中心检索注册的服务。
server:
eviction-interval-timer-in-ms: 5000 #清理间隔(单位毫秒,默认是60*1000)
enable-self-preservation: true # 默认为true,设为false,关闭自我保护
# Eureka Server 在运行期间会去统计心跳失败比例在 15 分钟之内是否低于 85%
renewal-percent-threshold: 0.49 # 默认是0.85,本地单机测试设为0.49
参照2.1,创建工程配置文件 application-server2.yml,并修改 server.port 为 9528
参照2.1,创建工程配置文件 application-server3.yml,并修改 server.port 为 9529
2.2、在 IntelliJ IDEA 集成开发环境中,添加 spring boot 启动配置 EurekaServerS1,修改 Active profiles 为 server1



参照2.2, spring boot 启动配置 EurekaServerS2,修改 Active profiles 为 server2
参照2.2, spring boot 启动配置 EurekaServerS3,修改 Active profiles 为 server3
2.3、按照启动配置 EurekaServerS1、EurekaServerS2、EurekaServerS3 依次启动服务中心

2.4、打开浏览器,访问 服务中心 前台页面:http://localhost:9527,http://localhost:9528,http://localhost:9529

如果三个服务都启动成功的话,三个页面都应该看到如上图所示。
至此,一个简单的服务中心集群搭建完成。
3、本章小结
本章主要讲解了 Eureka Server 服务中心的搭建,并讲解如果扩展为集群应用。但服务中心的使用以及集群的优点,本章并未讲解,因为这需要 Eureka Client 服务提供者和 Eureka Discovery Client 服务发现者配合使用,后续的章节我们会讲解后两者的使用。
下一章,我们将讲解,如何创建 Eureka Client 服务提供者,并把我们的服务注册到服务中心,以及如何搭建服务提供者集群。
SpringCloud2.0 Eureka Server 服务中心 基础教程(二)的更多相关文章
- SpringCloud2.0 Feign 服务发现 基础教程(五)
1.启动[服务中心]集群,即 Eureka Server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) 2.启动[服务提供者]集群,即 Eureka Cli ...
- SpringCloud2.0 Ribbon 服务发现 基础教程(四)
1.启动[服务中心]集群,即 Eureka Server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) 2.启动[服务提供者]集群,即 Eureka Cli ...
- SpringCloud2.0 Zuul 网关路由 基础教程(十)
1.启动基础工程 1.1.启动[服务注册中心],工程名称:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) ...
- SpringCloud2.0 Eureka Client 服务注册 基础教程(三)
1.创建[服务提供者],即 Eureka Client 1.1.新建 Spring Boot 工程,工程名称:springcloud-eureka-client 1.2.工程 pom.xml 文件添加 ...
- 升级微服务架构1:搭建Eureka Server服务中心
Spring Cloud中使用Eureka来做服务注册和发现,来统一管理微服务实例. 1.使用IDEA创建一个空的Maven项目做父模块 (也可以不用父项目,所有模块都用平行结构) 删除父模块src文 ...
- MySQL8.0数据库基础教程(二)-理解"关系"
1 SQL 的哲学 形如 Linux 哲学一切都是文件,在 SQL 领域也有这样一条至理名言 一切都是关系 2 关系数据库 所谓关系数据库(Relational database)是创建在关系模型基础 ...
- Java基础教程——二维数组
二维数组 Java里的二维数组其实是数组的数组,即每个数组元素都是一个数组. 每个数组的长度不要求一致,但最好一致. // 同样有两种风格的定义方法 int[][] _arr21_推荐 = { { 1 ...
- numpy基础教程--二维数组的转置
使用numpy库可以快速将一个二维数组进行转置,方法有三种 1.使用numpy包里面的transpose()可以快速将一个二维数组转置 2.使用.T属性快速转置 3.使用swapaxes(1, 0)方 ...
- AngularJS 基础教程二:
5.过滤器 过滤器的主要功能是格式化数据 可以使用Angular提供的过滤器,也可以自定义过滤器 Angular过滤器: currency(货币).date(日期).filter(子串匹配).json ...
随机推荐
- HTML5 - websocket的应用 之 简易聊天室
需要知识点: 前端知识 jq操作dom nodejs socket.io 关于websocket api的知识点,见上篇章<HTML5-Websocket>. 聊天室思路/原理: A和B聊 ...
- javascript系列--认识并理解构造函数,原型和原型链
一.前言 介绍构造函数,原型,原型链.比如说经常会被问道:symbol是不是构造函数:constructor属性是否只读:prototype.[[Prototype]]和__proto__的区别:什么 ...
- centos7.5 搭建上FTP服务
1.安装FTP # 查看ftp 是否安装 rpm -qa | grep vftpd # 安装vsftp yum install -y vsftpd # 设置ftp 开机启动 systemctl ena ...
- 小程序报错 “渲染层错误” Expect END descriptor with depth 0 but get another
项目中有几个页面在控制台出现这个“渲染层错误”,虽然不影响业务操作,怕存在潜在风险,今天抽时间找了下原因,解决这个问题. 控制台报错日志如下: (中国标准时间) 渲染层错误 Error: Expect ...
- Typescript 学习 - 类
class class 并不是一种新的数据结构,只是在函数原型基础上的语法糖 class People { hand: number; constructor(hand: number) { this ...
- 解决wireshark抓包校验和和分片显示异常
问题描述: 在使用wireshark抓取报文时,发现从10.81.2.92发过来的报文绝大部分标记为异常报文(开启IPv4和TCP checksum) 分析如下报文,发现http报文(即tcp pay ...
- 超级简单POI多sheet导出Excel实战
本章节主要基于上一章节单sheet导出的基础上进行改造实现多sheet的导出,上一章节参考地址:https://www.cnblogs.com/sunny1009/p/11437005.html 1. ...
- 修改dedecms 一些配置cfg_softname,cfg_soft_enname,cfg_soft_devteam
1.找到include 中的common.inc.php 直接修改就可以了.
- 更新.net core 3.0,dotnet ef命令无法使用的解决办法
之前项目采用.net core 2.2 实现,今天更新vs2019,系统.net core也被升级到3.0,在cmd中使用dotnet ef命令出现 “无法执行,因为找不到指定的命令或文件.可能的原因 ...
- ASP.NET Core 静态文件
静态文件(HTML,CSS,图片和Javascript之类的资源)会被ASP.NET Core应用直接提供给客户端. 静态文件通常位于网站根目录(web root) <content-root& ...