- 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.2 application.properties4.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
# 服务名称 spring.application.name=eureka # 端口号 server.port=1111 # 其本身即是一个服务,也是一个注册中心,这里设置不把自己注册到注册中心去 eureka.client.register-with-eureka=false # 从注册中心获取注册信息 eureka.client.fetch-registry=false1.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 依赖2.4 application-a.properties4.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
# 服务名称 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/eureka2.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/eureka2.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注册中心



