Eureka-server
pom
<?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">
<parent>
<artifactId>spring-clould-Official</artifactId>
<groupId>com.wx</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Eureka-server</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
</project>
EurekaServerApplication.java(启动程序)
package com.wx;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class,args);
}
}
application.yml(独立部署模式)
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
独立部署demo
application.yml(两个交互模式模式)
The First one >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
# registerWithEureka: false
# fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8762/eureka/
spring:
application:
name: eureka-server
The Second one >>>>>>>>>>>>>>>>>>
server:
port: 8762
eureka:
instance:
hostname: localhost
client:
# registerWithEureka: false
# fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/
spring:
application:
name: eureka-server-01
两个交互demo
application.yml(多个交互分裂模式模式)
The First one >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
# registerWithEureka: false
# fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/,http://${eureka.instance.hostname}:8762/eureka/,http://${eureka.instance.hostname}:8763/eureka/
spring:
application:
name: eureka-server
The Second one >>>>>>>>>>>>>>>>>>
server:
port: 8762
eureka:
instance:
hostname: localhost
client:
# registerWithEureka: false
# fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/,http://${eureka.instance.hostname}:8762/eureka/,http://${eureka.instance.hostname}:8763/eureka/
spring:
application:
name: eureka-server-01
The Third one >>>>>>>>>>>>>>>>>>>>>>>
server:
port: 8763
eureka:
instance:
hostname: localhost
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/,http://${eureka.instance.hostname}:8762/eureka/,http://${eureka.instance.hostname}:8763/eureka/
spring:
application:
name: eureka-server-02
多个交互分裂模式模式demo
When to Prefer IP Address
In some cases, it is preferable for Eureka to advertise the IP addresses of services rather than the hostname. Set eureka.instance.preferIpAddress to true and, when the application registers with eureka, it uses its IP address rather than its hostname.
prefer-ip-address: true