温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

spring cloud(三):Eureka服务的搭建

发布时间:2020-07-09 02:34:25 来源:网络 阅读:1276 作者:browser123 栏目:软件技术

1、 概念:  Eureka - 云端服务发现,一个基于 REST 的服务,用于定位服务,以实现云端中间层服务发现和故障转移。


2、  搭建:a、首先讲下单机搭建,先新建一个maven项目,在pom里面导入eureka的坐标:

                    <dependencies>

                    <parent>

                        <groupId>org.springframework.boot</groupId>

                        <artifactId>spring-boot-starter-parent</artifactId>

                        <version>1.4.0.RELEASE</version>

                      </parent>

                    <dependency>

                      <groupId>org.springframework.cloud</groupId>

                      <artifactId>spring-cloud-starter-eureka-server</artifactId>

                    </dependency>

                    </dependencies>


                b、新建类EurekaApplication

                        @SpringBootApplication

                        @EnableEurekaServer

                        public class EurekaApplication {

                          public static void main(String[] args) {

                            SpringApplication.run(EurekaApplication.class, args);

                          }

                        }

                   其中@EnableEurekaServer,启动一个服务注册中心提供给其他应用进行对话


               c、application.properties的配置项

                   # 默认的端口 server.port=8761 

                    eureka.client.register-with-eureka=false 

                    eureka.client.fetch-registry=false 

                    eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/


              d、启动springboot,并访问http://localhost:8761/


3、上面只是单机模式环境,商用环境往往是要高可用(HA)的环境,这个时候就要考虑集群,一个节点挂了,还有另外一个节点,集群我们只要改下配置文件就可以了

eureka.client.serviceUrl.defaultZone=http://localhost:8762/eureka/;http://localhost:8763/eureka/;如果ip不同,配置三个节点,则需要三台机器


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI