SpringCloud Eureka集群入门配置

环境配置

修改hosts文件,添加如下配置:
Windows: C:\Windows\System32\drivers\etc\hosts
Linux: /etc/hosts

127.0.0.1 eureka7001
127.0.0.1 eureka7002
127.0.0.1 eureka7003

创建项目

创建3个一样的项目,如下:

在这里插入图片描述

pom.xml

<?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>cn.zy</groupId>
    <artifactId>uereka7003</artifactId>
    <version>1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.6</version>
<!--        <relativePath/>-->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2021.0.5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

启动类

@SpringBootApplication
@EnableEurekaServer //表示本类是EurekaServer服务端
public class EurekaServer_7003 {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServer_7003.class, args);
    }
}

SpringBoot配置文件

server:
  port: 7003
#  servlet:
#    context-path: /eureka    //1. 这个路径千万不能配置,否则副本会出现在unavailable-replicas中
#Eureka配置
eureka:
  instance:
    hostname: eureka7003
    prefer-ip-address: false
    instance-id: eureka7003  #2. 配置了这个,在status列会显示此配置value,否则会显示主机名:${spring.application.name}:${server.port}
  client:
#    register-with-eureka: false  #3. 表示是否向eureka注册中心注册自己  #配置false,会被放入unavailable-replicas中
    fetch-registry: false  #如果为false,表示自己是注册中心
    service-url:
      defaultZone: http://eureka7001:7001/eureka,http://eureka7002:7002/eureka
spring:
  application:
    name: eureka-registration-center

上面代码中说明2配图展示如下:

在这里插入图片描述

最终界面展示

在这里插入图片描述

GitHub地址

待给~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值