当前位置:网站首页>Eureka cluster setup

Eureka cluster setup

2022-06-11 06:15:00 Grumpy procedural ape

preparation Because we use a computer to simulate , All we modify the computer etc Under folder host file Join in :

127.0.0.1  eureka8001.cn
127.0.0.1  eureka8002.cn

Our access to these two addresses is equivalent to accessing the local 127.0.0.1 route

The official start of the
To configure a cluster, you need to register multiple registries with each other Such as : stay 8001 Register in 8002 stay 8002 Register in 8001
Create two eureka The registry serves a port 8001 One port is 8002

 Insert picture description here

8001pom rely on

<dependencies>
        <!-- The new version eureka-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <artifactId>cloud-api-commons</artifactId>
            <groupId>com.rpf.springcloud</groupId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

8001 yml Profile contents

server:
  port: 8001
eureka:
  instance:
    hostname: eureka8001.cn
  client:
    register-with-eureka: false     #false Does not register itself with the registry .
    fetch-registry: false     #false It means that its own end is the registration center , My job is to maintain service instances , There's no need to retrieve Services 
    service-url:
      defaultZone: http:/eureka8002.cn:8002/eureka

8001 Start class

@SpringBootApplication
@EnableEurekaServer
public class EurekaMain8001 {
    
    public static void main(String[] args) {
    
        SpringApplication.run(EurekaMain8001.class,args);
    }
}

8002pom rely on

<dependencies>
        <!-- The new version eureka-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <artifactId>cloud-api-commons</artifactId>
            <groupId>com.rpf.springcloud</groupId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

8002yml The configuration file

server:
  port: 8002
eureka:
  instance:
    hostname: eureka8002.cn
  client:
    register-with-eureka: false     #false Does not register itself with the registry .
    fetch-registry: false     #false It means that its own end is the registration center , My job is to maintain service instances , There's no need to retrieve Services 
    service-url:
      defaultZone: http:/eureka8001.cn:8001/eureka

8002 Start class

@SpringBootApplication
@EnableEurekaServer
public class EurekaMain8002 {
    
    public static void main(String[] args) {
    
        SpringApplication.run(EurekaMain8002.class,args);
    }
}

Then we can start two projects
visit eureka8001.cn:8001
or
eureka8002.cn:8002

You can see that each other has registered their services

原网站

版权声明
本文为[Grumpy procedural ape]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110600539718.html