springcloud(二):注册中心Eureka

搭建注册中心Eureka

 

 1、pom中依赖

复制代码
<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
复制代码

2、添加启动代码中添加@EnableEurekaServer注解

3、配置文件application.properties中新增以下配置

spring.application.name=spring-cloud-eureka

server.port=8000
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

 启动工程后,访问:http://localhost:8000/,可以看到下面的页面,其中还没有发现任何服务

eureka双节点注册中心

 

eureka集群

 

客户端要把自己注册到集群中,只需在default-zone配置两个地址即可

eureka:
   client:
      service-url:
          default-zone:http://discovery1:8761/eureka,http://discovery2:8762/eureka

 

配置defaultZone相互注册。注意:这里的url需要使用对方的hostname,即http://peer1:1111/eureka/中,需要使用peer1,而不能使用localhost或者127.0.0.1,否则Eureka注册中心会认为另外一个注册中心是unavailable的。这里的原因笔者认为是通过hostname来进行判断的,并没有深入了解。不过如果不这样使用,的确会出现问题。

 

https://blog.csdn.net/a60782885/article/details/70146615

 

资料

https://my.oschina.net/happyBKs/blog/1631960

Spring Cloud:Eureka服务治理;Ribbon负载均衡;Hystrix熔断器;API网关Zuul;分布式配置中心;

https://ke.qq.com/webcourse/index.html#course_id=280057&term_id=100331701&taid=1971218190452217&vid=e1424zq6kdw

posted @   ~沐风  阅读(254)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示