0
点赞
收藏
分享

微信扫一扫

动手搭建一个三个节点的eureka集群

说明

搭建一个三个节点的eureka集群

版本说明

jdk1.8、spring boot2.7.1 、spring-cloud2021.0.3

项目结构预览

eureka-colony eureka1 eureka2 eureka3

端口

分别为 8761、8762、8763

主机映射

为了在同一台机器上能同时运行三个eureka而不导致冲突,修改主机host文件(C:\Windows\System32\drivers\etc)

将127.0.0.1映射为如下三个地址:

127.0.0.1 ​​eureka1.com​​ 127.0.0.1 ​​eureka2.com​​ 127.0.0.1 ​​eureka3.com​​

构建

然后依次构建三个微服务,做好配置

测试

访问:​​http://eureka1.com:8761/​​

可以看到你中有我,我中有你

动手搭建一个三个节点的eureka集群_项目结构


自此,eureka集群搭建成功

yml配置参考

spring:
application:
name: eureka1

server:
port: 8761

eureka:

client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://eureka2.com:8762/eureka,http://eureka3.com:8763/eureka
instance:
hostname: eureka1.com
prefer-ip-address: true

主启动类配置参考

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class Eureka1Application {

public static void main(String[] args) {
SpringApplication.run(Eureka1Application.class, args);
}

}

完整源码

​​https://gitee.com/langhu/eureka-colony​​

举报

相关推荐

0 条评论