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