微服务注册中心-基于spring boot 搭建 eureka-
2020-04-09 本文已影响0人
yufw
基于spring boot 搭建 集群
环境版本
spring cloud Greenwich.SR5
spring boot 2.1.6.RELEASE
jdk 11
pom文件:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
配置文件
application-dev0.yml
application-dev1.yml
application-dev2.yml
- application-dev0.yml
## server
server:
port: 8010
# spring
spring:
application:
name: eureka-server
# eureka
eureka:
instance:
hostname: eureka0
server:
enable-self-preservation: false
client:
# false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: true
# false表示不向注册中心注册自己。
register-with-eureka: true
serviceUrl:
defaultZone: http://eureka1:8011/eureka, http://eureka2:8012/eureka
- application-dev1.yml
## server
server:
port: 8011
# spring
spring:
application:
name: eureka-server
# eureka
eureka:
instance:
hostname: eureka1
server:
enable-self-preservation: false
client:
# false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: true
# false表示不向注册中心注册自己。
register-with-eureka: true
serviceUrl:
defaultZone: http://eureka0:8010/eureka, http://eureka2:8012/eureka
- application-dev2.yml
## server
server:
port: 8012
# spring
spring:
application:
name: eureka-server
# eureka
eureka:
instance:
hostname: eureka2
server:
enable-self-preservation: false
client:
# false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: true
# false表示不向注册中心注册自己。
register-with-eureka: true
serviceUrl:
defaultZone: http://eureka0:8010/eureka, http://eureka1:8011/eureka
- 启动时 使用 --spring.profiles.active=dev2 指定不同的环境
启动类添加注解
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
FAQ:
路径不能使用localhost
defaultZone: http://eureka0:8010/eureka, http://eureka1:8011/eureka中的 不饿能使用localhost
开启相互注册
# false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: true
# false表示不向注册中心注册自己。
register-with-eureka: true