new spring start project
application.yml
server:
port: ${eureka.server.port}
eureka:
server:
port: 8761
hostname: eureka.com
instance:
hostname: ${eureka.hostname}
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
spring:
application:
name: eureka-server
- register-with-eureka:服务注册中心自己注册自己;
- fetch-registry:服务检索功能;
- 当注册中心为单机时,register-with-eureka、fetch-registry 为false;
- 当注册中心为集群时,register-with-eureka、fetch-registry 为true;
启动类
添加注解 @EnableEurekaServer
@SpringBootApplication
@EnableEurekaServer
public class BaseEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(BaseEurekaApplication.class, args);
}
}
eureka集群 yml文件
server:
port: ${eureka.server.port}
eureka:
server:
port: 8761
port2: 8762
port3: 8763
hostname: eureka.com
instance:
hostname: ${eureka.hostname}
client:
#register-with-eureka: false
#fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${eureka.server.port}/eureka/,http://${eureka.instance.hostname}:${eureka.server.port2}/eureka/,http://${eureka.instance.hostname}:${eureka.server.port3}/eureka/
spring:
application:
name: eureka-server
server:
port: ${eureka.server.port2}
server:
port: ${eureka.server.port3}