1.开启注解:
@SpringBootApplication
@EnableEurekaServer
public class SpringCloudEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudEurekaApplication.class, args);
}
}
2.application.yml
---
spring:
application:
name: spring-cloud-eureka
profiles: peer1
server:
port: 8001
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2:8002/eureka/,http://peer3:8003/eureka/
---
spring:
application:
name: spring-cloud-eureka
profiles: peer2
server:
port: 8002
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1:8001/eureka/,http://peer3:8003/eureka/
---
spring:
application:
name: spring-cloud-eureka
profiles: peer3
server:
port: 8003
eureka:
instance:
hostname: peer3
client:
serviceUrl:
defaultZone: http://peer1:8001/eureka/,http://peer2:8002/eureka/
3. IDEA的run configration中通过配置
第一个cluster-peer1:
main class:com.neo.SpringCloudEurekaApplication
program arguments: --spring.profiles.active=peer1
选中 allow parrallel run。
第二个cluster-peer2:
main class:com.neo.SpringCloudEurekaApplication
program arguments: --spring.profiles.active=peer2
选中 allow parrallel run。
第三个cluster-peer3:
main class:com.neo.SpringCloudEurekaApplication
program arguments: --spring.profiles.active=peer3
选中 allow parrallel run。
4. hosts文件增加配置
127.0.0.1 peer1
127.0.0.1 peer2
127.0.0.1 peer3
5. 启动cluster-peer1、cluster-peer2、cluster-peer3