springcloud注册中心eureka高可用配置(本地测试)
1.引入springcloud相关jar包<!-- 注册中心 --><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter
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)