Building Eureka cluster of spring cloud for microservice learning

Keywords: Spring Windows

In this cluster, three Eureka services are created on the local machine.

The configuration of each registry is basically the same. Only some services have different addresses. The whole cluster architecture is as follows

Let's talk about some configurations

yml corresponding to port 7001

server:
  port: 7001

eureka:
  instance:
    hostname: eureka7001.com #Instance name of eureka server
  client:
    register-with-eureka: false     #false means that you do not register yourself with the registry.
    fetch-registry: false     #false means that my client is the registry. My responsibility is to maintain the service instance. I don't need to retrieve the service
    service-url:
      #stand-alone defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka / ා set the address query service and registration service that interact with Eureka Server need to rely on this address (stand-alone).
      defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/



Cluster yml corresponding to port 7002

server:
  port: 7002

eureka:
  instance:
    hostname: eureka7002.com #Instance name of eureka server
  client:
    register-with-eureka: false     #false means that you do not register yourself with the registry.
    fetch-registry: false     #false means that my client is the registry. My responsibility is to maintain the service instance. I don't need to retrieve the service
    service-url:
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka / ා set the address query service and registration service that interact with Eureka Server need to rely on this address.
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/

yml corresponding to port 7003

server:
  port: 7003

eureka:
  instance:
    hostname: eureka7003.com #Instance name of eureka server
  client:
    register-with-eureka: false     #false means that you do not register yourself with the registry.
    fetch-registry: false     #false means that my client is the registry. My responsibility is to maintain the service instance. I don't need to retrieve the service
    service-url:
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka / ා set the address query service and registration service that interact with Eureka Server need to rely on this address.
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/

pom dependency files are the same for three eureka configurations

   <dependencies>
        <!--eureka-server Server side -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <!-- Effective immediately after modification, hot deployment -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

In addition, configure the windows address mapping

hosts file address

C:\Windows\System32\drivers\et

Add the following map at the bottom of the file

127.0.0.1  eureka7001.com
127.0.0.1  eureka7002.com
127.0.0.1  eureka7003.com

Such a simple cluster will be built and the service will be started.

In our Eureka monitoring center, we can see such a page

This indicates that the cluster has been set up.

Posted by salmon on Thu, 14 Nov 2019 11:32:32 -0800