Spring Cloud 之服务注册中心高可用
2017-12-07 18:05
507 查看
服务注册中心高可用
服务注册中心 eureka-server 高可用实施版本
Spring Boot 版本
# Spring Boot 版本: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> </parent>
Spring Cloud 版本
# Spring Cloud 版本: <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Edgware.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
主机
修改hosts 模拟两台主机C:\Windows\System32\drivers\etc\hosts
# Copyright (c) 1993-1999 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: 127.0.0.1 localhost 127.0.0.1 www.galsang.org 127.0.0.1 www.galsang.io
服务注册中心
一台机器模拟出的两台主机规划如下:项目名称 | spring.application.name | eureka.client.serviceUrl.defaultZone | eureka.instance.hostname | 端口 |
---|---|---|---|---|
spring-cloud-server | spring-cloud-server-discovery-eureka-ha | http://www.galsang.io:8999/eureka/ | www.galsang.org | 9000 |
spring-cloud-server-available | spring-cloud-server-discovery-eureka-ha | http://www.galsang.org:9000/eureka/ | www.galsang.io | 8999 |
spring-cloud-server
pom.xml
<?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>org.galsang.cloud</groupId> <artifactId>spring-cloud-server</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>spring-cloud-server</name> <description>注册中心</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.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> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Edgware.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
application-pro.yml
## 生产环境 启用服务注册中心高可用 spring: profiles: pro cloud: inetutils: preferred-networks: - 192.168 server: port: 9000 context-path: / # 服务治理中心实例 eureka: instance: hostname: www.galsang.org leaseRenewalIntervalInSeconds: 1 leaseExpirationDurationInSeconds: 2 # 是否作为服务进行注册,在此仅作为服务治理中心,不作为服务进行注册 client: register-with-eureka: true fetch-registry: true serviceUrl.defaultZone: http://www.galsang.io:8999/eureka/ # 关闭自我保护 server: enableSelfPreservation: false
spring-cloud-server-available
pom.xml
<?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>org.galsang.cloud</groupId> <artifactId>spring-cloud-server-available</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>spring-cloud-server-available</name> <description>注册中心</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.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> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Edgware.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-s b17a tarter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
application-pro.yml
## 生产环境 启用服务注册中心高可用 spring: profiles: pro cloud: inetutils: preferred-networks: - 192.168 server: port: 8999 context-path: / # 服务治理中心实例 eureka: instance: hostname: www.galsang.io leaseRenewalIntervalInSeconds: 1 leaseExpirationDurationInSeconds: 2 # 是否作为服务进行注册,在此仅作为服务治理中心,不作为服务进行注册 client: register-with-eureka: true fetch-registry: true serviceUrl.defaultZone: http://www.galsang.org:9000/eureka/ # 关闭自我保护 server: enableSelfPreservation: false
启动项目
浏览器打开
http://www.galsang.org:9000
或
http://www.galsang.io:8999
说明 服务注册中心 eureka-server 高可用已经成功
源码请移步: https://gitee.com/vimx86/SpringCloud-Learning
参考资料
Spring基础:快速入门spring cloud(2):服务发现之eurekaSpringCloud系列(2)—Netfilx-Eureka
相关文章推荐
- Spring Cloud构建微服务架构(六)高可用服务注册中心
- SpringCloud 笔记 (一)---- 简单搭建服务注册中心与服务,实现服务注册中心高可用
- Spring Cloud构建微服务架构(六)高可用服务注册中心
- 4--SpringCloud搭建高可用的服务注册中心
- Spring Cloud Learning | 第二篇:高可用服务注册中心
- SpringCloud之高可用的服务注册中心(Eureka) |第八章 -yellowcong
- springcloud实战之3 高可用服务注册中心(eureka集群)
- Spring cloud微服务实战——高可用注册中心(二)
- Spring Cloud构建微服务架构(六)高可用服务注册中心
- 一起来学SpringCloud之 - 高可用服务注册中心(Eureka-Cluster)
- SpringCloud的服务注册中心(四)- 高可用服务注册中心的搭建
- Spring Cloud构建微服务架构(六)高可用服务注册中心
- Spring Cloud构建微服务架构(六)高可用服务注册中心
- 【Spring Cloud】Eureka服务注册中心搭建
- 【Spring Cloud】Eureka服务注册中心搭建
- 笔记:Spring Cloud Eureka 高可用注册中心
- 【微服务架构】SpringCloud之Eureka(注册中心集群篇)(三)
- 【Spring Cloud】Eureka服务注册中心搭建
- SpringCloud的服务注册中心(三) - 进一步了解 Eureka
- Spring Cloud Eureka 服务注册与发现中心(一)