Spring Cloud Eureka Server 高可用集群搭建
来源:互联网 发布:用java从键盘输入 编辑:程序博客网 时间:2024/06/06 02:12
前言
Eureka 作为一个云端负载均衡,本身是一个基于REST的服务,在 Spring Cloud 中用于发现和注册服务。
那么当成千上万个微服务注册到Eureka Server中的时候,Eureka Server 的负载将会很大,这样一旦Eureka Server服务挂掉了,整个微服务架构也就瘫掉了,所以在实际生产环境中不光要对注册在Eureka Server中的微服务进行集群管理,还要对Eureka Server 本身进行集群管理,使整个微服务更加健壮,更加高可用
这篇文章主要介绍Eureka Server 的集群搭建
一、准备工作
1.1 准备三台机器用于集群搭建
192.168.1.11
192.168.1.12
192.168.1.13
1.2 修改三台机器的host文件
windows目录:C:\Windows\System32\drivers\etc\hosts
linux目录:/etc/hosts
192.168.1.11 peer1192.168.1.12 peer2192.168.1.13 peer3
二、创建Eureka Server工程
2.1 创建一个spring boot 的 maven工程
在pom.xml中加入eureka-server的引用
完整pom.xml 文件内容
<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.caspar.spring.cloud</groupId> <artifactId>eureka-server</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <name>${project.artifactId}</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> </parent> <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> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.RC1</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> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories></project>
2.2 建立三个配置文件
注意 eureka.client.serviceUrl.defaultZone
这行配置,每一个配置里面配置其他的eureka server 地址即可,多个服务用 逗号
分隔
application-s1.properties
server.port=8761spring.application.name = eureka_servereureka.instance.hostname=peer1eureka.client.serviceUrl.defaultZone=http://peer2:8761/eureka/,http://peer3:8761/eureka/
application-s2.properties
server.port=8761spring.application.name = eureka_servereureka.instance.hostname=peer2eureka.client.serviceUrl.defaultZone=http://peer1:8761/eureka/,http://peer3:8761/eureka/
application-s3.properties
server.port=8761spring.application.name = eureka_servereureka.instance.hostname=peer3eureka.client.serviceUrl.defaultZone=http://peer1:8761/eureka/,http://peer2:8761/eureka/
2.3 启用EurekaServer
用 @EnableEurekaServer
注解来表明是一个Eureka Server
@EnableEurekaServer@SpringBootApplicationpublic class ServerApplication { public static void main(String[] args) { SpringApplication.run(ServerApplication.class, args); }}
2.4 工程目录如下:
三、打包发布
用 maven 打成jar包,并将jar包分别放到三个服务器上
在三个服务器上分别启动服务,分别执行下面三行命令
java -jar eureka-server-1.0.0.jar --spring.profiles.active=s1java -jar eureka-server-1.0.0.jar --spring.profiles.active=s2java -jar eureka-server-1.0.0.jar --spring.profiles.active=s3
访问 http://192.168.1.11:8761
在界面中 DS Replicas
下会看到 peer2,peer3 节点
同理访问peer2里面会有peer1和peer3节点,访问peer3里也会有peer1和peer2节点
OK,Eureka Server 集群就已经搭建好了
四、客户端注册
在client端,只需要把 eureka.client.serviceUrl.defaultZone
改成相应的集群地址即可,多个服务用逗号分隔
eureka.client.serviceUrl.defaultZone = http://peer1:8761/eureka/,http://peer2:8761/eureka/,http://peer3:8761/eureka/
五、测试
访问client端资源,能正常访问
停掉Eureka Server 其中1台或者2台,资源依然能正常访问
版权说明
转载请注明出处: http://blog.csdn.net/tuposky/article/details/78343401
文章来源:五只鸭子的专栏
- Spring Cloud Eureka Server 高可用集群搭建
- Spring Cloud之Eureka Server高可用集群学习
- Spring Cloud Eureka 集群高可用
- Spring Cloud (19) | Eureka Server 高可用服务注册中心
- spring cloud eureka-server搭建
- 高可用eureka server搭建
- spring cloud eureka服务发现(高可用)
- spring cloud eureka服务发现(高可用)
- Spring Cloud之Eureka集群搭建
- spring cloud之Eureka Server环境搭建
- [bigdata-105] spring-cloud-02 服务注册 eureka server 双机高可用
- Spring-cloud Eureka 集群
- Spring Cloud-Eureka注册发现高可用(学习实践)
- spring cloud eureka高可用踩的坑
- Spring Cloud---注册中心Eureka的高可用配置
- 搭建Eureka高可用
- 疯狂Spring Cloud连载(5)Eureka集群搭建
- springcloud-eureka搭建高可用服务注册集群
- WebService之WSDL文档深入分析(三)
- 3款强大的BootStrap的可视化制作工具推荐
- composer插件使用方法
- arm64动态链接库通过函数名获取函数偏移
- Git忽略文件不起作用解决方案
- Spring Cloud Eureka Server 高可用集群搭建
- FFmpeg3.3中codec被舍弃后,如何获取源码流的codecpar参数
- Cannot convert 临时用户 of type class java.lang.String to class java.lang.Long
- Java初阶知识总结
- [2017纪中10-25]天才绅士少女助手克里斯蒂娜 线段树
- Drawable、Bitmap、Canvas、Paint和 Matrix 的使用(三)
- Android压力测试四 MonkeyRunner
- Laravel 5.5 FormRequest 自定义错误消息
- 【Codeforces319E】Ping-Pong