当前位置:网站首页>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 .
边栏推荐
- Cloudreve自建云盘实践,我说了没人能限制得了我的容量和速度
- Move a string of numbers backward in sequence
- gocv opencv exit status 3221225785
- Microservice practice | fuse hytrix initial experience
- Actual combat of microservices | discovery and invocation of original ecosystem implementation services
- 机器学习之数据类型案例——基于朴素贝叶斯法,用数据辩男女
- Essay: RGB image color separation (with code)
- Watermelon book -- Chapter 5 neural network
- Knife4j 2.X版本文件上传无选择文件控件问题解决
- 《统计学习方法》——第五章、决策树模型与学习(上)
猜你喜欢

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

西瓜书--第六章.支持向量机(SVM)

Talk about the secret of high performance of message queue -- zero copy technology

微服务实战|手把手教你开发负载均衡组件

MYSQL安装出现问题(The service already exists)

Redis zadd导致的一次线上问题排查和处理

QT -- how to set shadow effect in QWidget

查看was发布的应用程序的端口

Watermelon book -- Chapter 6 Support vector machine (SVM)

Redis installation and deployment (windows/linux)
随机推荐
Gocv split color channel
Redis zadd导致的一次线上问题排查和处理
以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
Amq6126 problem solving ideas
CSDN Q & A_ Evaluation
Microservice practice | load balancing component and source code analysis
Cloudreve自建云盘实践,我说了没人能限制得了我的容量和速度
"Interview high frequency question" is 1.5/5 difficult, and the classic "prefix and + dichotomy" application question
Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
Oracle修改表空间名称以及数据文件
Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
Hengyuan cloud_ Can aiphacode replace programmers?
[go practical basis] how to bind and use URL parameters in gin
Micro service practice | introduction and practice of zuul, a micro service gateway
聊聊消息队列高性能的秘密——零拷贝技术
机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
Long summary (code with comments) number structure (C language) -- Chapter 4, string (Part 1)
Solution to amq4036 error in remote connection to IBM MQ
Leetcode sword finger offer brush questions - day 22
2022/2/13 summary