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
Eureka服务器配置与多实例交互
本文档展示了如何配置Eureka服务器进行独立部署、双实例交互以及多个实例的分裂模式交互。通过修改`application.yml`文件,设置Eureka实例的注册、发现及服务URL,实现不同模式下的服务注册与发现。同时,`prefer-ip-address`属性可以调整为true,使服务使用IP地址而非主机名进行广告宣传。
298

被折叠的 条评论
为什么被折叠?



