Spring Cloud 的 Eureka HA
来源:互联网 发布:古由卡怎么样 知乎 编辑:程序博客网 时间:2024/06/08 14:10
一、Eureka Server HA
在Windows或Linux的hosts文件进行如下修改, 如两台电脑, 进行物理IP设置
127.0.0.1 peer1 127.0.0.1 peer2
复制上一章节的 eureka-server工程, 改名为 eureka-server-ha。
1) 对yml文件进行如下配置:
spring: application: name: microservice-eureka-server-ha1 # 指定 profile=peer1 profiles: peer1server: port: 8761 # 注册服务的端口号 eureka: instance: hostname: peer1 # 指定当profile=peer1时,主机名 client: service-url: defaultZone: http://peer2:8762/eureka/ # 将自己注册到peer2这个Eureka上面去 ---spring: application: name: microservice-eureka-server-ha2 # 指定 profile=peer2 profiles: peer2server: port: 8762eureka: instance: hostname: peer1 client: #register-with-eureka: false #表示是否将自己注册到Eureka Server中,默认为true, 由于当前应用就是 Eureka Server, 故而设置为false #fetch-registry: false #表示是否从 Eureka Server中获取注册信息, 默认为true, 因为这是一个单点的 Eureka Server, 不需要同步其它的 Eureka Server 节点的数据, 故而设置为 false service-url: defaultZone: http://peer1:8761/eureka/ # 设置与Eureka Server交互的地址, 查询服务和注册服务都需要依赖这个地址. 默认http://localhost:8761/eureka; 多个地址可以使用","分隔
2) pom.xml Maven文件配置
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.itmuch.cloud</groupId><artifactId>microservice-eureka-server-ha</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>eureka-server-ha</name><description>Simple for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Dalston.SR3</spring-cloud.version></properties><dependencies><!-- Eureka 服务 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
3) 主程序
package com.itmuch.cloud;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication@EnableEurekaServer // 开启这是一个 Eureka Server 程序public class EurekaServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaServerApplication.class, args);}}
4) Maven 打包
mvn clean package
5) 在DOS中运行
java -jar springcloud-eureka-ha-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1 java -jar springcloud-eureka-ha-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2
二、Eureka Client 的YML文件defaultZone指向配置
只要配置 defaultZone 的指向
server: port: 8081 session: timeout: 30 tomcat: max-threads: 0 uri-encoding: UTF-8 spring: application: #表示注册到Eureka上的应用名称 name: cloud-service datasource: url: jdbc:mysql://localhost:3306/boot username: root password: xshdb driver-class-name: com.mysql.jdbc.Driver jpa: # Specify the DBMS database: MYSQL # Show or not log for each sql query show-sql: true # Hibernate dll auto (create, create-drop, update) hibernate: ddl-auto: updateeureka: client: service-url: #将服务注册到集群上 defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/ instance: prefer-ip-address: true # 表示将自己的IP注册到Eureka Serverk, 如果不配置该属性或将它改为false,则表示注册微服务所在操作系统的hostname到Eureka Server
三、访问 Eureka Web 控制台
阅读全文
0 0
- Spring Cloud 的 Eureka HA
- spring cloud eureka server HA
- spring cloud-实现Eureka注册中心的HA
- spring cloud-实现Eureka注册中心的HA
- Spring Cloud Eureka Server HA With Docker
- Spring Cloud 的 Eureka 的健康检查
- 二、Spring Cloud 的 Eureka 组件
- Spring Cloud 的 Eureka 元数据
- Spring Cloud 的 Eureka 自我保护
- Spring Cloud Eureka的自我保护机制
- spring cloud-eureka
- Spring-cloud Eureka 集群
- spring cloud eureka
- Spring Cloud Eureka
- Spring Cloud Netflix Eureka
- Spring Cloud Eureka详解
- Spring Cloud Eureka
- Spring Cloud Eureka
- C#简易画图程序
- spring cloud zuul
- jQueryday05(动画效果 切换样式 tab切换 DOM基本操作)
- Application
- redis 内存淘汰机制
- Spring Cloud 的 Eureka HA
- Kotlin------类和对象(二)
- [转]opencv实现几幅图像拼接成一整幅大图
- 基于WebRTC的Android数字楼宇对讲系统回声消除
- 百度 UNIT 技术负责人揭秘:如何让你的对话系统更智能
- 挑战程序竞赛系列(55):4.4 双端队列(2)
- ubuntu解压RAR文件
- c++中->和.的区别
- [初学笔记] matlab 中的 function, return,global