- Eureka
- Zookeeper
- Consul
- Nacos
需要的依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-client
配置文件的配置(单机和集群):
server.port=7001
# eureka服务端的实例名称(单机版)
#eureka.instance.hostname=localhost
# eureka服务端的实例名称(集群版)
eureka.instance.hostname=eureka7001.com
# 不向服务中心注册自己
eureka.client.register-with-eureka=false
# 表明自己这端就是注册中心,职责是维护服务实例,并不需要检索服务
eureka.client.fetch-registry=false
# 设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址。
#单机配置
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
#集群配置,集群配置时,默认空间为其他集群的url
#eureka.client.service-url.defaultZone=http://eureka7002.com:7002/eureka/
主启动类配置:
@SpringBootApplication
@EnableEurekaServer
public class EurekaMain7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaMain7001.class, args);
}
}
需要加上EnableEurekaServer注解。
客户端配置需要的依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-server
配置文件:
server.port=8001 spring.application.name=CLOUD-PAYMENT-SERVICE #表明自己是客户端,需要注册到注册中心 eureka.client.register-with-eureka=true eureka.client.fetch-registry=true #单机版: #eureka.client.service-url.defaultZone=http://localhost:7001/eureka #集群版: eureka.client.service-url.defaultZone=http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/ # 在eureka服务端的微服务的status进行设置 eureka.instance.instance-id=payment8001 # 在eureka服务端能够看到微服务的ip地址 eureka.instance.prefer-ip-address=true
主启动类:
@SpringBootApplication
@EnableEurekaClient
public class PaymentMain8001 {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(PaymentMain8001.class, args);
}
}
注意加上@EnableEurekaClient注解。



