springcloud注册中心eureka高可用配置(本地测试)

1.引入springcloud相关jar包

<!-- 注册中心 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>

2.application.yml

#服务配置
spring:
  profiles:
    active: peer2
  application: demo-eureka

3.application-peer1.yml

server:
  port: 1111 # 服务端口

spring:
  application:
    name: eureka

eureka:
  client:
    service-url:
      defaultZone: http://${spring.cloud.client.ipAddress}:1112/eureka/
    register-with-eureka: true  #是否向服务注册中心注册自己
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ipAddress}:${server.port}
  server:
    renewal-percent-threshold: 0.5  #留存的服务示例低于多少比例进入保护模式
    enable-self-preservation: false #是否开启保护模式

ribbon:
  MaxAutoRetriesNextServer : 1
  MaxAutoRetries: 0
  ConnectTimeout: 60000
  ReadTimeout: 60000

4.application-peer2.yml

server:
  port: 1112 # 服务端口

spring:
  application:
    name: eureka

eureka:
  client:
    service-url:
      defaultZone: http://${spring.cloud.client.ipAddress}:1111/eureka/
    register-with-eureka: true  #是否向服务注册中心注册自己
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ipAddress}:${server.port}
  server:
    renewal-percent-threshold: 0.5  #留存的服务示例低于多少比例进入保护模式
    enable-self-preservation: false #是否开启保护模式

ribbon:
  MaxAutoRetriesNextServer : 1
  MaxAutoRetries: 0
  ConnectTimeout: 60000
  ReadTimeout: 60000

5.启动类EurekaApplication

/**
 * FileName: EurekaApplication
 * Date:     2018/12/4 10:57
 * Description: 注册中心启动类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.XXXX.demo.eureka;

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

/**
 * 〈一句话功能简述〉<br> 
 * @create 2018/12/4
 * @since 1.0.0
 */
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
    public static void main(String[] args) {
       SpringApplication.run (EurekaApplication.class,args);
    }
}

6.启动主类EurekaApplication,并访问注册中心

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值