前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringCloud2020 学习笔记(十)cloud-eureka-server7001 cloud-eureka-server7002 Eureka集群安装

SpringCloud2020 学习笔记(十)cloud-eureka-server7001 cloud-eureka-server7002 Eureka集群安装

作者头像
cookily
发布2020-10-22 15:21:19
6310
发布2020-10-22 15:21:19
举报
文章被收录于专栏:cookilycookilycookily

SpringCloud2020 学习笔记(十)cloud-eureka-server7001 cloud-eureka-server7002 Eureka集群安装

我使用spring boot 2.2.2

我使用spring cloud Hoxton.SR1

我使用spring cloud alibaba 2.1.0.RELEASE

为什么使用这个三个版本,是有讲究的;spring boot 2.2.2,spring cloud Hoxton.SR1,spring cloud alibaba 2.1.0.RELEASE 开始引入注册中心,概念待补充… 计划Eureka集群2个节点,一个cloud-eureka-server7001,另一个cloud-eureka-server7002

一.修改cloud-eureka-server7001 EurekaServer服务端模块的配置文件

1.修改eureka服务端实例名称

把 hostname: eureka7001.com 改为: hostname: localhost

hostname: eureka7001.com

2.修改defaultZone

把 defaultZone: http://{eureka.instance.hostname}: {server.port}/eureka/ 改为:defaultZone: http://eureka7002.com:7002/eureka/ 你没看错,是eureka7002.com:7002,要互相注册,相互守护

完整配置文件

server:
  port: 7001


eureka:
  instance:

    #eureka服务端的实例名称
    #hostname: localhost
    hostname: eureka7001.com

  client:

    #false表示不向注册中心注册自己。
    register-with-eureka: false

    #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    fetch-registry: false

    service-url:

      #设置与Eureka Server交互的地址查询服务和注册服务都要依赖这个地址
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
     
      #单机就是7001自己
      #defaultZone: http://eureka7001.com:7001/eureka/

      #集群指向其它eureka
      defaultZone: http://eureka7002.com:7002/eureka/

3.修改hosts文件

windows的hosts在xxx mac下 直接 终端sudo vim /etc/hosts

###################SpringCloud2020##############
127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com

二.新建cloud-eureka-server7002 EurekaServer服务端模块

1.参考SpringCloud2020 学习笔记(七)cloud-eureka-server7001 EurekaServer服务端安装

2.把cloud-eureka-server7001的pom复制到cloud-eureka-server7002记得更改如下

artifactId和name记得改为7002

<artifactId>cloud-eureka-server7002</artifactId>

<name>cloud-eureka-server7002</name>

完成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">
    <parent>
        <artifactId>cloud2020</artifactId>
        <groupId>cn.cookily.springcloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cloud-eureka-server7002</artifactId>

    <name>cloud-eureka-server7002</name>

    <dependencies>

        <!--eureka-server 2.x版本 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <!-- 引入自己定义的api通用包,可以使用Payment支付Entity -->
        <dependency>
            <groupId>cn.cookily.springcloud</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>${project.version}</version>
        </dependency>
        <!--boot web actuator-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--一般通用配置-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
    </dependencies>

</project>

3.主启动类

代码如下

@SpringBootApplication
@EnableEurekaServer
public class EurekaMain7002 {
    public static void main(String[] args) {
        SpringApplication.run(EurekaMain7002.class, args);
    }
}

4.配置文件修改

端口 hostname defaultZone,别看花了

server:
  port: 7002


eureka:
  instance:

    #eureka服务端的实例名称
    #hostname: localhost
    hostname: eureka7002.com

  client:

    #false表示不向注册中心注册自己。
    register-with-eureka: false

    #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    fetch-registry: false

    service-url:

      #设置与Eureka Server交互的地址查询服务和注册服务都要依赖这个地址
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

      #单机就是7002自己
      #defaultZone: http://eureka7002.com:7002/eureka/

      #集群指向其它eureka
      defaultZone: http://eureka7001.com:7001/eureka/

7002模块不在Dashboard里的话,刷新一下maven

三.启动eureka集群测试

项目地址: https://github.com/cookily/cloud2020.git

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-10-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • SpringCloud2020 学习笔记(十)cloud-eureka-server7001 cloud-eureka-server7002 Eureka集群安装
  • 我使用spring boot 2.2.2
  • 我使用spring cloud Hoxton.SR1
  • 我使用spring cloud alibaba 2.1.0.RELEASE
  • 一.修改cloud-eureka-server7001 EurekaServer服务端模块的配置文件
    • 1.修改eureka服务端实例名称
      • 2.修改defaultZone
        • 3.修改hosts文件
        • 二.新建cloud-eureka-server7002 EurekaServer服务端模块
          • 1.参考SpringCloud2020 学习笔记(七)cloud-eureka-server7001 EurekaServer服务端安装
            • 2.把cloud-eureka-server7001的pom复制到cloud-eureka-server7002记得更改如下
              • 3.主启动类
                • 4.配置文件修改
                • 三.启动eureka集群测试
                相关产品与服务
                微服务引擎 TSE
                微服务引擎(Tencent Cloud Service Engine)提供开箱即用的云上全场景微服务解决方案。支持开源增强的云原生注册配置中心(Zookeeper、Nacos 和 Apollo),北极星网格(腾讯自研并开源的 PolarisMesh)、云原生 API 网关(Kong)以及微服务应用托管的弹性微服务平台。微服务引擎完全兼容开源版本的使用方式,在功能、可用性和可运维性等多个方面进行增强。
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档