nevegiveup

1 版本说明

  Spring boot 版本: 2.1.3.RELEASE 

  Spring Cloud 版本:Greenwich.RELEASE

2 搭建Eureka服务侧

 

pom依赖如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <parent>
 6         <groupId>org.springframework.boot</groupId>
 7         <artifactId>spring-boot-starter-parent</artifactId>
 8         <version>2.1.3.RELEASE</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.linxi.jia</groupId>
12     <artifactId>eureka-server</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <name>eureka-server</name>
15     <description>eureka-server project for Spring Boot</description>
16 
17     <properties>
18         <java.version>1.8</java.version>
19         <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
20     </properties>
21 
22     <dependencies>
23         <dependency>
24             <groupId>org.springframework.cloud</groupId>
25             <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
26         </dependency>
27 
28         <dependency>
29             <groupId>org.springframework.boot</groupId>
30             <artifactId>spring-boot-starter-test</artifactId>
31             <scope>test</scope>
32         </dependency>
33     </dependencies>
34 
35     <dependencyManagement>
36         <dependencies>
37             <dependency>
38                 <groupId>org.springframework.cloud</groupId>
39                 <artifactId>spring-cloud-dependencies</artifactId>
40                 <version>${spring-cloud.version}</version>
41                 <type>pom</type>
42                 <scope>import</scope>
43             </dependency>
44         </dependencies>
45     </dependencyManagement>
46 
47     <build>
48         <plugins>
49             <plugin>
50                 <groupId>org.springframework.boot</groupId>
51                 <artifactId>spring-boot-maven-plugin</artifactId>
52             </plugin>
53         </plugins>
54     </build>
55 
56     <repositories>
57         <repository>
58             <id>spring-milestones</id>
59             <name>Spring Milestones</name>
60             <url>https://repo.spring.io/milestone</url>
61         </repository>
62     </repositories>
63 
64 </project>

 注意:Eureka即是服务端,也是客户端,所以在配置客户端信息的时候,也需要配置客户端注册的地址。

配置文件如下:

  

 

Eureka采用高可用部署方式,提供三个节点,三个配置文件只有 Eureka 服务侧的端口信息不一样,其余信息都一样。

 

application.yml文件:

spring:
  application:
    name: eureka-server
logging:
  level:
    root: info
server:
  port: 8761
eureka:
  client:
  # 是否自身注册到 Eureka 服务器上面
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://127.0.0.1:8762/eureka/ # 当前的eureka版本,服务端同时也是户端,所以必须要个客户端注册到服务端上面去
  instance:
    hostname: server
    # 为注册的 clinet 配置显示的ip值,默认显示的是主机名称
    #perferIpAddress: true
    #instance-id: 0.0.0.0:8888

从客户端的角度分析

节点1的配置如上图,,它被注册到服务侧端口为:8762的主机上面:

节点3的配置文件:

spring:
  application:
    name: eureka-server
logging:
  level:
    root: info
server:
  port: 8763
eureka:
  client:
  # 是否将自身注册到 Eureka 服务器上面
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://127.0.0.1:8761/eureka,http://127.0.0.1:8762/eureka/ # 当前的eureka版本,服务端同时也是户端,所以必须要个客户端注册到服务端上面去
  instance:
    hostname: server
    # 为注册的 clinet 配置显示的ip值,默认显示的是主机名称
    #perferIpAddress: true
    #instance-id: 0.0.0.0:8888

节点3的配置如上图,它同时被注册到了8761和8762上面:

 

从服务端角度分析:

节点1作为Eureka服务侧,三个节点全部注册过来。

 

相关文章:

  • 2021-11-14
  • 2021-07-04
  • 2021-06-25
  • 2021-11-09
  • 2021-05-08
猜你喜欢
  • 2021-11-02
  • 2021-06-15
  • 2021-06-28
  • 2020-06-16
  • 2019-09-24
  • 2021-06-13
  • 2021-12-22
  • 2021-04-13
相关资源
相似解决方案