This article only has one Eureka server project, which runs on different ports and simulates two Eureka services. Use eclipse 4.8
Let's talk about the Pom. xml file first.If any problem occurs, first consider conflicts between springboot and other package versions.
<? XML version = "1.0" encoding = "UTF-8"?> <Project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion> 4.0.0 </modelversion> <groupid> COM. xing </groupid> <artifactid> springboot-Eureka </artifactid> <version> 1.0.0-Snapshot </version> <packaging> jar </packaging> <parent> <groupid> org. springf Ramework. Boot </groupid> <artifactid> spring-boot-starter-parent </artifactid> <version> 1.4.0.release </version> <relativepath/> <! -- Lookup parent from repository --> </parent> <Properties> <project. build. sourceencoding> UTF-8 </project. build. sourceencoding> <project. reporting. outputencoding> UTF-8 </project. reporting. outputencoding> <Java. version> 1.8 </Java. version> </Properties> <dependencymanagement> <dependencies> <dependency> <groupid> Org. springframework. cloud </groupid> <artifactid> spring-cloud-dependencies </artifactid> <vers Ion> Camden. sr3 </version> <! -- Edgware. sr4 Finchley. release --> <type> pom </type> <scope> Import </scope> </dependency> </dependencies> </dependencymanagement> <dependencies> <dependency> <groupid> org. springframework. cloud </groupid> <artifactid> spring-cloud-starter-Eureka-server </artifactid> </dependency> <! -- Health check --> <dependency> <groupid> Org. springframework. boot </groupid> <artifactid> spring-boot-starter-actuator </artifactid> </dependency> </dependencies> <build> <plugins> <plugin> <groupid> org. springframework. boot </groupid> <artifactid> spring-boot-Maven-plugin </artifactid> </plugin> </plugins> </build> <! -- Repository Management --> <repositories> <repository> <ID> spring-milestones </ID> <Name> spring milestones </Name> <URL> https://repo.spring.io/milestone </URL> <snapshots> <enabled> false </enabled> </snapshots> </Repository> </repositories> <! -- Specify profiles --> <profiles> <profile> <ID> first </ID> <activation> <! -- Default activation --> <activebydefault> true </activebydefault> </activation> <Properties> <spring. profiles. active> first </spring. profiles. active> </Properties> </profile> <ID> second </ID> <Properties> <spring. profiles. active> second </spring. profiles. active> </Properties> </profile> </profiles> </Project>
Because eclipse is used, it seems that multiple instances can only use multiple yml or properties configuration files.
Application. ym is as follows:
spring: profiles: active: first
Application-first.yml is as follows:
Spring: Application: Name: Xing-eurekaserver # specify the service name prifiles: firstserver: Port: 8090 # service port Eureka: Client: registerwitheureka: true # whether to register yourself to the Eureka service, in itself, there is no need to register fetchregistry: true # Whether to obtain registration information from Eureka serviceurl: # defaultzone: http: // Xing-eurekaserver: 8091/Eureka/instance: prefer-IP-Address: true # register your IP address in the Eureka service IP-Address: 127.0.0.1 instance-ID: Xing-eurekaserver: 8090 # specify the instance id hostname: 127.0.0.1 server: Enable-self-preservation: false # disable self-protection mode eviction-interval-timer-in-MS: 60000 # cleaning interval (unit: milliseconds, the default value is 60*1000)
Application-second.yml is as follows:
Spring: Application: Name: Xing-eurekaserver # specify the service name prifiles: secondserver: Port: 8091 # service port Eureka: Client: registerwitheureka: true # whether to register yourself to the Eureka service, in itself, there is no need to register fetchregistry: true # Whether to obtain registration information from Eureka
Serviceurl: # defaultzone: http: // Xing-eurekaserver: 8090/Eureka/instance: prefer-IP-address: true # register your IP address in the Eureka service IP Address: 127.0.0.1 instance-ID: Xing-eurekaserver: 8091 # specify instance id hostname: 127.0.0.1 server: Enable-self-preservation: false # disable self-protection mode eviction-interval-timer-in-MS: 60000 # cleanup interval (in milliseconds, the default value is 60*1000)
In the following two yml files
Serviceurl: defaultzone: http: // Xing-eurekaserver: 8090/Eureka/use a domain name such as Xing-eurekaserver, Which is mapped to 127.0.0.1 through host ,, if the domain name is not used, there may be two services when the service is started, but there will be only one service after the refresh, and
In this step, the host file will not be listed. From the above two yml examples, we can see that first registers with second and second registers with first. In this way, mutual registration is implemented when you
To register services with these two Eureka servers, you only need to register with one of them.
Eureka multi-instance, simulating multiple machines