栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

eureka服务单节点搭建以及集群的搭建

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

eureka服务单节点搭建以及集群的搭建

eureka服务单节点搭建以及集群的搭建
  • 1.单节点搭建
    • 1.1 依赖
    • 1.2 application.properties
    • 1.3 开启eureka服务的功能
    • 1.4 查看eureka注册中心相关信息
  • 2.集群搭建
    • 2.1 eureka集群概念
    • 2.2 先去这个目录下C:WindowsSystem32driversetc,找到host文件并做修改
    • 2.3 依赖
    • 2.4 application-a.properties
    • 2.5 application-b.properties
    • 2.6 开启eureka服务功能
    • 2.7 项目打包,以java-jar命令启动两个实例
    • 2.8 访问eurekaA注册中心
    • 2.9 访问eurekaB注册中心

1.单节点搭建 1.1 依赖


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.7.2
         
    
    com.yl
    eureka
    0.0.1-SNAPSHOT
    eureka
    Demo project for Spring Boot
    
        11
        2021.0.3
    
    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



1.2 application.properties
# 服务名称
spring.application.name=eureka
# 端口号
server.port=1111
# 其本身即是一个服务,也是一个注册中心,这里设置不把自己注册到注册中心去
eureka.client.register-with-eureka=false
# 从注册中心获取注册信息
eureka.client.fetch-registry=false

1.3 开启eureka服务的功能
package com.yl.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer // 开启eureka服务的功能
public class EurekaApplication {

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

}

1.4 查看eureka注册中心相关信息

2.集群搭建 2.1 eureka集群概念

eureka集群可以理解成是启动了多个eureka实例,然后这几个实例之间相互注册,以达到同步数据的目的!

2.2 先去这个目录下C:WindowsSystem32driversetc,找到host文件并做修改

2.3 依赖


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.7.2
         
    
    com.yl
    eureka
    0.0.1-SNAPSHOT
    eureka
    Demo project for Spring Boot
    
        11
        2021.0.3
    
    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



2.4 application-a.properties
# 服务名称
spring.application.name=eurekaA
# 端口号
server.port=1112
# 实例名称
eureka.instance.hostname=eurekaA
# 其本身即是一个服务,也是一个注册中心,这里设置把自己注册到注册中心去
eureka.client.register-with-eureka=true
# 从注册中心获取注册信息
eureka.client.fetch-registry=true
# A服务注册到B服务中
eureka.client.service-url.defaultZone=http://eurekaB:1113/eureka

2.5 application-b.properties
# 服务名称
spring.application.name=eurekaB
# 端口号
server.port=1113
# 实例名称
eureka.instance.hostname=eurekaB
# 其本身即是一个服务,也是一个注册中心,这里设置把自己注册到注册中心去
eureka.client.register-with-eureka=true
# 从注册中心获取注册信息
eureka.client.fetch-registry=true
# B服务注册到A服务中
eureka.client.service-url.defaultZone=http://eurekaA:1112/eureka

2.6 开启eureka服务功能
package com.yl.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer // 开启eureka服务的功能
public class EurekaApplication {

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

}

2.7 项目打包,以java-jar命令启动两个实例

2.8 访问eurekaA注册中心

2.9 访问eurekaB注册中心

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1031345.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号