【SpringCloud】(十):高可用 Eureka

  提高系统的可靠性,我们使用Eureka集群,搭建的过程很简单,在Eureka工程的配置文件application.yml中进行配置。


1.使Eureka之间相互注册

2.用户微服务,注册到任意一个Eureka Server上都会进行同步。


Eureka 配置文件application.yml

Peer Awareness:同伴意识。

spring:
  application:
    name: EUREKA-HA
---
server:
  port: 8761
spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2:8762/eureka/,http://peer2:8763/eureka/

---
server:
  port: 8762
spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/,http://peer3:8763/eureka/
---
server:
  port: 8763
spring:
  profiles: peer3
eureka:
  instance:
    hostname: peer3
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/  
    


启动类

package com.dynamic.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer//	声明一个server:@EnableEurekaServer
public class EurekaApplication 
{
    public static void main( String[] args )
    {
    	SpringApplication.run(EurekaApplication.class, args);    	
    }
}

去掉POM.xml中的认证依赖

	
	    <dependency>
	    	<groupId>org.springframework.boot</groupId>
	    	<artifactId>spring-boot-starter-security</artifactId>
	    </dependency>

  用户微服务配置文件application.yml将服务注册到Eureka

eureka:
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/ #http://user:pass123@localhost:8761/eureka
  instance:
    prefer-ip-address: true
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}


修改计算机的host配置

win + r   -----> drivers ------> etc ------>hosts








刚启动的时候,相互之间注册,其他相互依赖服务没有正常启动,所以会出现异常。





  通过修改心跳检测的时长,可以提高服务注册的速度,但是线上不建议修改。


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值