Create multiple Eureka server clusters using IDEA from scratch (2)


Preface

Tip: The last chapter introduced how to build the first Eureka server from scratch. Unread students can click on the portal: Use IDEA to create multiple Eureka server clusters from scratch (1)

This chapter will introduce how to build multiple Eureka servers and realize information interconnection


One, add local address mapping

Add mapping configuration under c:\windows\system32\drivers\etc/hosts under windows.
Find the hosts configuration file and right-click to open it (notepad is also available)

Insert picture description here
Add mapping address, as shown in the figure below
Insert picture description here


Two, create multiple Eureka servers

1. Open our project space, copy the detailcloud-eureka we have built, paste under the parent project detailcloud, and modify the copied module name to detailcloud-eureka2 and detailcloud-eureka3

If you do not copy under the project space, the root path may be disordered!
Insert picture description here


2. Modify the configuration of detailcloud-eureka2 and detailcloud-eureka3

First, we first register two new sub-modules under the pom file of the parent module (the new version of IDEA will be added automatically)

 <modules>
        <!-- 子版块 -->
        <module>detailcloud-eureka</module>
        <module>detailcloud-eureka2</module>
        <module>detailcloud-eureka03</module>
    </modules>

Then update the module information in the pom files of detailcloud-eureka2 and detailcloud-eureka3, and refresh maven at this time, you can see that the module name is bolded, that is, the module is activated

 <artifactId>detailcloud-eureka2</artifactId>
    <name>detailcloud-eureka2</name>
 <artifactId>detailcloud-eureka3</artifactId>
    <name>detailcloud-eureka3</name>

Modify the class name of the startup class to be consistent with the newly added server name for easy distinction.
Insert picture description here
After the same is true for detailcloud-eureka3 , change the port and hostname configuration in the application.yml files of the two servers to be consistent with their own module information (port and The other two servers are different)

server:
  port: 7002
eureka:
  instance:
    hostname: eureka2
server:
  port: 7003
eureka:
  instance:
    hostname: eureka3

At this point, our Eureka server cluster has been created, and we start the service to check the effect.

eureka1
Insert picture description here
eureka2
Insert picture description here
eureka3 is the same. So
far, our Eureka server cluster has been activated and registered with each other and shared information


Three, possible errors

1. Maven configuration issues

The maven warehouse path must be configured correctly. IDEA will create the maven path by itself, and it is recommended to change back to its own maven path.

2. The module is not registered

If the name of the created module is not in bold; as shown in the figure, insert the picture description here, it
may be that the submodule is not registered under the parent module!
View the parent module pom file, plus

<modules>
        <!-- 子版块 -->
        <module>detailcloud-eureka</module>
        <module>detailcloud-eureka2</module>
        <module>detailcloud-eureka3</module>
    </modules>

Refresh the maven configuration, the module name becomes bold, indicating activation

3. Service startup failed: Failed to load property source from location'classpath:/application.yml'

If there is an errorInsert picture description here

The source of the error here is:
Failed to load property source from location'classpath:/application.yml'

Indicates that springboot cannot read the ymal file in the resource

Solution:
Modify the character configuration of IDEA, as shown in
the figure, change all character sets to UTF-8 and save

Insert picture description here
Test, the service started successfully.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_38149225/article/details/109102221