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

原文地址:https://www.cnblogs.com/cnki/p/8747550.html