1、建一个springboot项目,加上@EnableEurekaServer注解
2、pom.xml加入依赖:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
3、配置文件3台机器,我的是一台机器更改端口号为例:
eureka.instance.prefer-ip-address和 eureka.client.register-with-eureka 和 eureka.client.fetch-registry要设置成true
eureka.client.service-url.defaultZone 写上另外两台eureka服务的地址。
4、另外两台改下端口号、实例名称eureka.instance.hostname、eureka.client.service-url.defaultZone就可以了
eureka: instance: hostname: localhost # prefer-ip-address: true client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://admin:admin@localhost2:10002/register/eureka/,http://admin:admin@localhost1:10001/register/eureka/ server: #(设置为false,关闭自我保护 enable-self-preservation: true #清理间隔(单位毫秒,默认是60*1000) eviction-interval-timer-in-ms: 60000