4

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

 1 year ago
source link: https://blog.51cto.com/u_15696939/5487165
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

搭建一个三个节点的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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK