一、版本说明:

SpringBoot:2.1.6.RELEASE

SpringCloud:Greenwich.RELEASE

二、作用及功能说明:

注册中心:是将多个微服务统计进行管理,主要起注册及发现的作用,是微服务架构的一个总要环节,是多个微服务之间通讯的保障及支撑;

Eureka:可以做为服务端,同时也可以作为客户端,支持高可用;

三、Maven主要配置说明

 1 <modelVersion>4.0.0</modelVersion>2 <parent>3     <groupId>org.springframework.boot</groupId>4     <artifactId>spring-boot-starter-parent</artifactId>5     <version>2.1.6.RELEASE</version>6     <relativePath/> <!-- lookup parent from repository -->7 </parent>8 <groupId>【项目自定义】</groupId>9 <artifactId>【项目自定义】</artifactId>
10 <version>【版本自定义】</version>
11 <name>【名称自定义】</name>
12 <packaging>jar</packaging>
13 <description>服务注册中心——独立启动项目</description>
14
15 <properties>
16     <java.version>1.8</java.version>
17 </properties>
18
19 <dependencies>
20    <!-- 注册中心Jar-->
21     <dependency>
22         <groupId>org.springframework.cloud</groupId>
23         <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
24     </dependency>
25   <!-- 提供注册中心用户名及密码的支持 -->
26     <dependency>
27         <groupId>org.springframework.boot</groupId>
28         <artifactId>spring-boot-starter-security</artifactId>
29     </dependency>
30 </dependencies>
31 <!--spring cloud版本-->
32 <dependencyManagement>
33     <dependencies>
34         <dependency>
35             <groupId>org.springframework.cloud</groupId>
36             <artifactId>spring-cloud-dependencies</artifactId>
37             <version>Greenwich.RELEASE</version>
38             <type>pom</type>
39             <scope>import</scope>
40         </dependency>
41     </dependencies>
42 </dependencyManagement>
43
44 <!-- 打包spring boot应用 -->
45 <build>
46     <finalName>【打包文件名称】</finalName>
47     <plugins>
48         <plugin>
49             <groupId>org.springframework.boot</groupId>
50             <artifactId>spring-boot-maven-plugin</artifactId>
51             <configuration>
52                 <fork>true</fork>
53             </configuration>
54         </plugin>
55     </plugins>
56     <resources>
57         <resource>
58             <directory>src/main/java</directory>
59             <includes>
60                 <include>**/*.xml</include>
61             </includes>
62             <filtering>true</filtering>
63         </resource>
64     </resources>
65 </build>

四、配置文件(application.properties)

 1 #注册中心端口2 server.port=【自定义】3 4 #日志级别5 logging.level.root=error6 7 spring.application.name=registration-center-independent-service8 9 #主机名,会在控制页面中显示
10 eureka.instance.hostname=【IP】
11 #使用ip替代实例名
12 eureka.instance.prefer-ip-address=false
13 #设置实例的ID为ip:port
14 eureka.instance.instance-id=${eureka.instance.hostname}:${server.port}
15
16 spring.security.user.name=【登录或链接的用户名】
17 spring.security.user.password=【登录或链接的密码】
18 #eureka.datacenter=trmap
19 #eureka.environment=product
20 # 关闭自我保护
21 eureka.server.enable-self-preservation=true
22 # 清理服务器时间
23 eureka.server.eviction-interval-timer-in-ms=5000
24 #通过eureka.client.registerWithEureka:false和fetchRegistry:false来表明自己是一个eureka server.
25 eureka.client.register-with-eureka=false
26 eureka.client.fetch-registry=false
27 eureka.client.serviceUrl.defaultZone=http://【登录或链接的用户名】:【登录或链接的密码】@【IP】:7000/eureka/

注意:上面红字部分,在服务端,一定要设置为False;

这里科普一下:在后台的代码处理逻辑中存在名称规范,例如:

1)eureka.client.register-with-eureka与eureka.client.registerWithEureka等价;

2)eureka.client.fetch-registry与eureka.client.fetchRegistry等价;

五、代码部分

代码部分比较简单,仅需要在启动入口类上进行处理即可;

 1 /**2 * 类描述: 注册中心启动入口3 * @author : 王雷4 * @date : 2019/6/28 0028 下午 4:565 */6 @EnableEurekaServer7 @SpringBootApplication8 public class RegistrationCenterIndependentServiceApplication {9
10     public static void main(String[] args) {
11         SpringApplication.run(RegistrationCenterIndependentServiceApplication.class, args);
12     }
13
14     /**
15      * 功能描述:最近版本(Boot:2.1.6.RELEASE;Cloud:Greenwich.RELEASE)下,若需要通过用户名及密码访问必须添加下面的处理
16      * 升级有风险;入坑须谨慎;
17      *
18      * @author : 王雷
19      * @date : 2019/6/25 0025 上午 11:26
20      */
21     @EnableWebSecurity
22     static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
23         @Override
24         protected void configure(HttpSecurity http) throws Exception {
25             http.csrf().disable().authorizeRequests()
26                     .anyRequest()
27                     .authenticated()
28                     .and()
29                     .httpBasic();
30         }
31     }
32 }

六、项目开源地址

目前项目再进行一些调整,后期再进行开放

七、结束语

在整个使用过程中,发现SpringBoot的升级迭代版本间变化比较大,所以在升级版本的时候需要多尝试,阅读相关资料,不然很多错误都不知道在哪里;

SpringBoot2.1+SpringCloud:注册中心搭建(Eureka)相关推荐

  1. SpringCloud注册中心高可用搭建

    转载自 SpringCloud注册中心高可用搭建 Spring Cloud的注册中心可以由Eureka.Consul.Zookeeper.ETCD等来实现,这里推荐使用Spring Cloud Eur ...

  2. SpringCloud知识点梳理 - 1.服务注册中心组件--Eureka

    提纲挈领 注册中心的作用:对各个微服务的管理.记录与监控. 1.核心概念 如下图,服务提供者和服务的消费者,本质上也是 Eureka Client 角色.整体上可以分为两个主体:Eureka Serv ...

  3. 服务注册中心:Eureka

    目录 第一章 注册中心介绍 1.1.什么是注册中心 1.2.为啥用注册中心 1.3.常见的注册中心 第二章 Eureka介绍 2.1.Eureka的介绍 2.2.Eureka的三种角色 2.3.Eur ...

  4. Linux-Nacos-服务注册中心搭建

    Linux-Nacos-服务注册中心搭建 由于springcloud 注册中心 Eureka 早已停止维护所以我们使用Nacos 官方: https://nacos.io/zh-cn/docs/wha ...

  5. 6.SpringCloud -- 注册中心与配置中心 Nacos、网关 Gateway

    6.SpringCloud -- 注册中心与配置中心 Nacos.网关 Gateway 一.了解一下 SpringCloud Alibaba 1.1 SpringCloudAlibaba (1)简单说 ...

  6. 微服务注册中心:Eureka详解

    文章目录 Eureka基础概念 Eureka概述 Eureka架构图 Eureka集群架构图 Eureka关键概念 Eureka的自我保护模式 创建Eureka服务端 服务提供者cloud-provi ...

  7. eruke注册中心搭建

    2019独角兽企业重金招聘Python工程师标准>>> eruke注册中心搭建 配置pom.xml <dependencyManagement> <dependen ...

  8. SpringCloud注册与发现Eureka

    SpringCloud注册于发现Eureka服务学习: 简介 Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中 ...

  9. springboot2 springcloud Greenwich.SR3 构建微服务--1.eureka注册中心搭建

    本一系列springcloud的文章主主要讲应用, 也会涉及到一些原理的讲解. 写了几句自己这段时间看书,总结的微服务的东西送给你们 : 道为源,源分多支为术,如龙生九子,九子各不同,然皆为龙也. 凡 ...

最新文章

  1. Hdu 1217 最短路.cpp
  2. 直播预告 | 高效视频理解模型的设计及ICCV比赛冠军方案解读
  3. 夯实基础js - 语句篇
  4. centos09-nodejs与vue搭建
  5. 分布式监控系统Zabbix3.2监控数据库的连接数
  6. irc ubuntu_让我们聊聊写作:在IRC上加入我们
  7. java导出excel 客户端_Java poi导出Excel下载到客户端
  8. 服务器安装win7系统蓝屏,安装win7系统出现蓝屏| win7安装过程中蓝屏|安装win7系统时蓝屏...
  9. Golang标准库RPC实践及改进
  10. 以太网交换芯片行业调研报告 - 市场现状分析与发展前景预测(2021-2027年)
  11. Excel 【数据透视表】 -【动态表图】 之核心 -【切片器】
  12. 将图的广度优先遍历在邻接矩阵和邻接表存储结构上分别实现_《青岛大学-王卓-数据结构》B站学习...
  13. POJ2104 K-TH NUMBER 传说中的主席树
  14. 2010年年度 “中国智能建筑品牌奖”获奖名单
  15. Linux进程间通信之信号量
  16. STM32单片机课程自学知识点整理 - 指南版
  17. 前沿 | 复活逝者?他在用聊天机器人复制一个自己
  18. 关于分销体系是怎么理解的?
  19. linux下rename用法--批量重命名
  20. mysql的gis_MySQL的GIS功能

热门文章

  1. javascript小游戏_javaScript小游戏——网页版别踩白块
  2. php实战https请求,用php发https请求
  3. 关于HTTP中40X和50X的问题(介绍,可根据介绍找出问题解决方案)
  4. mysql不用left join_MySQL在右表数据不唯一的情况下使用left join的方法_MySQL - join
  5. clickhouse原理解析与应用实践_Hybrid App (混合应用) 技术全解析 方案原理篇
  6. java 如何忽略异常_java中如何解决异常
  7. yolov3权重_目标检测之 YOLOv3 (Pytorch实现)
  8. android wms,Android解析WindowManagerService(一)WMS的诞生
  9. blob转成json js_javascript – 文件API – Blob到JSON
  10. php怎么自定义设置打印区域,JavaScript_jQuery实现区域打印功能代码详解,使用CSS控制打印样式,需要设 - phpStudy...