1. What is eureka cluster?
In the past, we only had one eureka service registration center, but if this one service is suddenly interrupted in the registration center and no registration service is provided, wouldn't it be very dangerous. Consumers will not be able to get the service. The whole process Just stopped.
Therefore, based on this, with the eureka cluster, a single node crashes without affecting the normal operation of other nodes, and service registration can still be accepted, so that service providers and service consumers can be normally associated.
Second, use steps
1. Create springcloud-eureka-7002, springcloud-eureka-7003 project
Depend on the same
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
Modify the hosts file: C:\Windows\System32\drivers\etc
127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com
127.0.0.1 eureka7003.com
In order to demonstrate the effect of the cluster, replace eureka with a different name, but essentially the same address.
application.yml
server:
port: 7001
#Eureka配置
eureka:
instance:
hostname: eureka7001.com #Eureka服务的实例名称
client:
register-with-eureka: false #表示是否向注册中心注册自己
fetch-registry: false #false表示自己为注册中心
service-url: #监控页面
#单机:defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
#集群(关联):
defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
server:
port: 7002
#Eureka配置
eureka:
instance:
hostname: eureka7002.com #Eureka服务的实例名称
client:
register-with-eureka: false #表示是否向注册中心注册自己
fetch-registry: false #false表示自己为注册中心
service-url: #监控页面
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/
server:
port: 7003
#Eureka配置
eureka:
instance:
hostname: eureka7003.com #Eureka服务的实例名称
client:
register-with-eureka: false #表示是否向注册中心注册自己
fetch-registry: false #false表示自己为注册中心
service-url: #监控页面
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
2. Modify the yml file of springcloud-provider-emp-8001:
Change defaultZone: http://eureka7001.com:7001/eureka/ to
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
3. Start the service
Start springcloud-eureka-7001, 7002, 7003 and springcloud-provider-emp-8001