基础步骤
1、添加引用
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
2、添加启动注解
@SpringBootApplication
@EnableEurekaServer
public class SpringCloudEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudEurekaApplication.class, args);
}
}
3、配置文件
spring:
application:
name: eureka-server
# 单节点
server:
port: 8761
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
register-with-eureka: false
fetch-registry: false
多节点
和单节点差不多,只是配置文件稍微修改一下而已
双节点
spring:
application:
name: eureka-server
---
# 启动参数 --spring.profiles.active=server1
spring:
profiles: server1
server:
port: 8761
eureka:
client:
service-url:
defaultZone: http://localhost:8762/eureka/
---
# 启动参数 --spring.profiles.active=server2
spring:
profiles: server2
server:
port: 8762
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
三节点
---
spring:
application:
name: spring-cloud-eureka
profiles: peer1
server:
port: 8000
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2:8001/eureka/,http://peer3:8002/eureka/
---
spring:
application:
name: spring-cloud-eureka
profiles: peer2
server:
port: 8001
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1:8000/eureka/,http://peer3:8002/eureka/
---
spring:
application:
name: spring-cloud-eureka
profiles: peer3
server:
port: 8002
eureka:
instance:
hostname: peer3
client:
serviceUrl:
defaultZone: http://peer1:8000/eureka/,http://peer2:8001/eureka/