当前位置:网站首页>Microservice practice | Eureka registration center and cluster construction
Microservice practice | Eureka registration center and cluster construction
2022-07-02 09:17:00 【_ Time boiled the rain】
Catalog
One 、SpringCloud System introduction
Two 、Eureka Server development
Create a service terminal project
3、 ... and 、Eureka Server cluster construction
Four 、 establish Eureka client
5、 ... and 、 Project startup verification
6、 ... and 、Spring cloud Version introduction
One 、SpringCloud System introduction
Microservice architecture has played an important role in cloud native architecture , and SpingCloud Undoubtedly, it is the integrator of microservice architecture , Cloud computing best business practices .
SpringCloud The system mainly includes the following components :
- Service registration and discovery : Such as Eureka、Consul、Nacos、zookeeper etc. ;
- Service configuration management : Such as SpringCloud config、zookeeper、Nacos、Apollo etc. ;
- The service call : Such as Feign、Ribbon、RestTemplate etc. ;
- Service failure : Such as Hystrix、Sentinel etc. ;
- The service gateway : Such as SpringCloud Gateway、Zuul etc. ;
- Client load balancing : Such as Ribbon etc. ;
- Service link tracking : Such as Sleuth etc. ;
- Service message bus : Such as SpringCloud Bus etc. ;
- Distributed message : Such as SpringCloud Stream+RocketMQ etc. ;
- Distributed transactions : Such as Seata etc. .

Eureka yes Netflix Developed service discovery framework ,SpringCloud Integrate it into your own subproject spring-cloud-netflix in , Realization SpringCloud Service discovery capabilities for .Eureka contain Eureka Server and Eureka Client Two components .
- Eureka Server Provide service registration service , After each node is started , Will be in Eureka Server Register in , such Eureka Server The service registry in will store information about all available service nodes .
- Eureka Client It's a java client , Used with Eureka Server Interaction , The client also has a built-in 、 Use polling (round-robin) Load balancer of load algorithm . After the app starts , Will Eureka Server Send a heartbeat , The default period is 30 second , If Eureka Server The heartbeat of a node is not received in multiple heartbeat cycles ,Eureka Server This service node will be removed from the service registry ( Default 90 second ).
Two 、Eureka Server development
Create project parent project
- newly build maven Parent project parent, For unified management of dependencies .
- introduce pom rely on , the SpringCloud The version is Hoxton.SR3
<modelVersion>4.0.0</modelVersion>
<groupId>com.cxy965</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<description>A maven project to study maven.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/>
</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>Hoxton.SR3</spring-cloud.version>
</properties>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>${tomcat.scope}</scope>
</dependency>
</dependencies>
</dependencyManagement>Create a service terminal project
- Create the first server project of the registry registry
- introduce eureka-server Dependence
<groupId>com.cxy965</groupId>
<artifactId>registry</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.cxy965</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>- Write the startup class , increase @EnableEurekaServer annotation , Expressed as server side
package com.cxy965.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* @Author: official account : The programmer 965
* @create 2022-06-06
**/
@EnableEurekaServer
@SpringBootApplication
public class RegistryApplication {
public static void main(String[] args) {
SpringApplication.run(RegistryApplication.class, args);
}
}- newly build application.yml The configuration file , Define port and other information
server:
port: 8001
spring:
application:
name: registry
eureka:
instance:
hostname: 0.0.0.0
lease-renewal-interval-in-seconds: 10 # Service registration involves heartbeat connection , Default is every 30s
lease-expiration-duration-in-seconds: 30 # The default time when the service is removed is 90s
client:
healthcheck:
enabled: true # Turn on the heartbeat
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
registry-fetch-interval-seconds: 30 #eureka client How often do I get the service registration information , The default is 30 second So the first one Eureka The development of the server is completed , Next, we create a cluster .
3、 ... and 、Eureka Server cluster construction
If you want to build a server cluster , Need to open Eureka Cluster configuration , When each server is started Eureka Server Will send the registration information to other Eureka Server To synchronize , Therefore, to build a highly available cluster architecture, you only need to Eureke Server The configuration points to other available serviceUrl that will do .
- Copy above Eureka Single server project , Create the first service of the cluster eurekaserver1;
- modify application.yml The configuration file ;
on top Eureka Based on a single server project , Modify... In the configuration file register-with-eureka、fetch-registry as well as serviceUrl.defaultZone Parameters , as follows :
server:
port: 8001
spring:
application:
name: registry
eureka:
instance:
hostname: 0.0.0.0
lease-renewal-interval-in-seconds: 10 # Service registration involves heartbeat connection , Default is every 30s
lease-expiration-duration-in-seconds: 30 # The default time when the service is removed is 90s
client:
healthcheck:
enabled: true # Turn on the heartbeat
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://localhost:8002/eureka/,http://localhost:8003/eureka/
registry-fetch-interval-seconds: 30 #eureka client How often do I get the service registration information , The default is 30 second - alike , Copy again eurekaserver1 by eurekaserver2,eurekaserver3 Two projects ;
- take eurekaserver2、eurekaserver3 The ports of are changed to 8002、8003;
- take eurekaserver2、eurekaserver3 The registered address of is changed into 8001/8003 and 8001/8002;
To start, respectively, eurekaserver1、eurekaserver2、eurekaserver3 Three items are enough .
Be careful , Because it is a local test project , All three projects are deployed locally localhost, As a highly available cluster environment , To prevent other items in the cluster from being available after the server crashes , It needs to be deployed on different servers , Deployed on different servers , The port can be changed to the same .
Four 、 establish Eureka client
- Create the first client project client
- The difference with the server is , The client needs to introduce eureka-client Dependence
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>- Write the startup class , Note that @EnableEurekaClient annotation , Indicates that this is a client
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
/**
* @Author: official account : The programmer 965
* @create 2022-06-06
**/
@EnableEurekaClient
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
}
}- establish application.yml The configuration file , Register to the server
server:
port: 8002
spring:
application:
name: app
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/5、 ... and 、 Project startup verification
Start server and client respectively , Open the browser and enter http://localhost:8001/; Display the successful registration of the client :
summary :Eureka Server Data synchronization is completed by means of replication ,Eureka It also provides client caching mechanism , Even if all Eureka Server All hang up , The client can still use the information in the cache to consume other services API. Sum up ,Eureka Through a heartbeat check 、 Client caching and other mechanisms , Ensure the high availability of the system 、 Flexibility and scalability .
6、 ... and 、Spring cloud Version introduction

stay 2020 year 4 Before month , To avoid confusion with subprojects ,SpringCloud Version is based on Name of London Underground Station name , And publish in alphabetical order : such as Angle、Brixton、Camden、Edgware、Finchley、GreenWich、Hoxton etc. . The meaning of the letters in the version number :
- SNAPSHOT: Snapshot version , unstable 、 Version in development ;
- M: MileStone,M1 It means the first one 1 Milestone version ;
- RC:Release Candidate, Candidate version , General Label PRE Show preview , Almost no new features will be added , Repair only bug;
- RELEASE: Official version , If published Edgware SR1 Before , It will be released first Edgware RELEASE;
- SR: Service Release, The release point of a single project accumulates to a critical value , Or there is a key bug It will be released when it needs to be provided to everyone SR edition , Such as SR1 Version may solve a number of key bug, Generally, mark at the same time GA;
- GA:General Availability, Officially released stable version ( Some software may be identified as Stable Version or Production edition , Its meaning and GA identical );
Maybe the release is too fast , The subway station name is not enough ,2020 year 4 The version released after the month is changed to Calendar version (Calendar Versioning) Naming method , The format is “YYYY.MINOR.MICRO-SNAPSHOT/M1/RC2”.
- YYYY: representative 4 Bit year ;
- MINOR: Means a year with 0 The number that starts to increase ;
- MICRO: Suffix indicating version number , .0 Be similar to .RELEASE equally ,.2 Be similar to .SR2.
- The snapshot and pre release version numbers are also changed from the previous . Change it to -, Such as :2020.0.0-SNAPSHOT/M1/RC2;
The possible order of release is as follows :
SNAPSHOT-->M-->RC-->RELEASE-->SR--GA
How to choose so many versions ?
Latest and marked GA Version of , Best choice SR The later version with larger numbers .
边栏推荐
- [staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the
- 「Redis源码系列」关于源码阅读的学习与思考
- Redis安装部署(Windows/Linux)
- 十年開發經驗的程序員告訴你,你還缺少哪些核心競爭力?
- Flink-使用流批一体API统计单词数量
- 西瓜书--第五章.神经网络
- 知识点很细(代码有注释)数构(C语言)——第三章、栈和队列
- 微服务实战|Eureka注册中心及集群搭建
- Mirror protocol of synthetic asset track
- Count the number of various characters in the string
猜你喜欢

A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model

WSL安装、美化、网络代理和远程开发

There is a problem with MySQL installation (the service already exists)

Win10 uses docker to pull the redis image and reports an error read only file system: unknown

Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)

概念到方法,绝了《统计学习方法》——第三章、k近邻法

Cloud computing in my eyes - PAAS (platform as a service)

Matplotlib剑客行——初相识Matplotlib

Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue

QT -- how to set shadow effect in QWidget
随机推荐
Redis sorted set data type API and application scenario analysis
Pdf document of distributed service architecture: principle + Design + practice, (collect and see again)
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
AMQ6126问题解决思路
Knife4j 2.X版本文件上传无选择文件控件问题解决
【Go实战基础】gin 如何设置路由
Leetcode sword finger offer brush questions - day 23
Micro service practice | introduction and practice of zuul, a micro service gateway
十年开发经验的程序员告诉你,你还缺少哪些核心竞争力?
西瓜书--第五章.神经网络
Jingdong senior engineer has developed for ten years and compiled "core technology of 100 million traffic website architecture"
微服务实战|微服务网关Zuul入门与实战
Ora-12514 problem solving method
Matplotlib swordsman line - layout guide and multi map implementation (Updated)
[staff] common symbols of staff (Hualian clef | treble clef | bass clef | rest | bar line)
Matplotlib剑客行——没有工具用代码也能画图的造型师
Troubleshooting and handling of an online problem caused by redis zadd
Introduction to the basic concept of queue and typical application examples
JVM指令助记符
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!