Spring Cloud Sleuth+Zipkin 构建微服务链路跟踪系统

article/2025/9/20 20:58:14

什么是链路跟踪系统?

在微服务中,多个服务分布在不同物理机器上,各个服务之间相互调用。如何清晰地记录服务调用过程,并在出现问题的时候能够通过查看日志和服务之间的调用关系来定位问题,这样的系统就叫做链路跟踪系统。

分布式服务跟踪系统主要由五部分组成:

  1. 数据采集
  2. 数据传输
  3. 数据存储
  4. 数据分析
  5. 数据可视化

为什么需要链路跟踪系统?

在微服务出现服务调用过程慢服务无法调用成功等问题,都需要用到链路跟踪系统来进一步排查问题,否则就是盲人摸象,无从下手。

Spring Cloud Sleuth

Spring Cloud Sleuth 是为了对微服务之间的调用链路进行跟踪的一个组件,提供了非常多的整合方案,比如可以整合zipkin

在了解sleth前,必须要掌握如下几个概念:

  • Span:采集的基本工作单元,有一个64位ID唯一标识,还包含摘要、时间戳事件、关键值注释(tags)、进度ID(通常是IP地址),span在不断的启动和停止,同时记录了时间信息。
  • Trace:由一系列的span组成一个树状结构
  • Annotation:用来及时记录一个事件的存在,一些核心annotations用来定义一个请求的开始和结束,如下:
    • cs(Client Sent):客户端发起一个请求,这个annotation描述了这个span的开始
    • sr(Server Received):服务端收到请求并准备开始处理它。sr-cr=网络延迟
    • ss(Server Sent):服务端处理完成,准备返回客户端。ss-sr=服务端处理请求花费的时间
    • cr(Client Received):标识span结束,客户端接收到服务端的回复。cr-cs=整个请求所花费的所有时间
  • 采样率
    在网络流量很大的情况下,如果全部采集对传输、存储、性能压力都会比较大。这时可以通过设置采样率来采样部分信息,sleuth可以通过配置spring.sleuth.sampler.probability=1.0,则表示采样率为100%(采集服务的全部追踪数据),默认值为0.1(10%)。
    也可以通过Bean的方式设置采样率为全部采样(AlwaysSampler)或不采样(NeverSampler
    @Bean
    public Sampler defaultSampler() {return new AlwaysSampler();
    }
    

了解了以上几个概念后,我们来看下具体的链路跟踪过程来加深下印象:
在这里插入图片描述
链路跟踪基本过程:

  1. server1开启一个trace100和span1,然后发送请求到server2,span1包含在trace100中
  2. server2收到请求后,开启一个span2,父级为span1,向server3请求并返回,span2结束
  3. server2再开启一个span3,父级为span1,向server4请求并返回,span3结束
  4. 在server2中的span2、span3都结束后,server2返回请求到server1,span1结束,trace100结束

Zipkin

sleuth是spring cloud提供的平台无关性的链路跟踪组件,可以整合不同的实现,这里整合的就是zipkin。

zipkin是Twitter的一个开源项目,它致力于收集服务的定时数据,以解决微服务架构中的延迟问题,包括数据的收集、存储、查找和发现

可以借助zipkin来收集各个服务器上请求链路的跟踪数据,并通过REST API接口来查询跟踪数据以实现对分布式系统的监控程序,从而及时地发现系统中出现的延迟升高、请求丢失等问题并找出系统的性能瓶颈
除了API的方式,也提供了可视化组件来帮助我们直观的搜索跟踪信息和分析请求链路与花费时间。比如需要查询某段时间内各个用户请求的处理花费时间。

在这里插入图片描述
如图可知:

  • Zipkin提供了多种存储方式:In-Memory、MySQL、Cassandra以及Elasticsearch(生产环境推荐ES)
  • Zipkin提供了多种数据展现方式:REST API查询接口和可视化的界面展示

手把手教你实现微服务链路跟踪系统

接下来我们通过示例来演示如何实现并使用链路跟踪系统。
此示例中,会搭建两个模块,一个是sale模块,一个是user模块,通过sale模块调用user模块,看看zipkin能不能跟踪到

Zipkin 环境搭建

  • 安装jdk8、mysql

  • 下载zipkin包:https://search.maven.org/remote_content?g=io.zipkin&a=zipkin-server&v=LATEST&c=exec

  • 建立一个名为zipkin数据库,并初始化zipkin默认的几个表:

	 CREATE TABLE IF NOT EXISTS zipkin_spans (`trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',`trace_id` BIGINT NOT NULL,`id` BIGINT NOT NULL,`name` VARCHAR(255) NOT NULL,`remote_service_name` VARCHAR(255),`parent_id` BIGINT,`debug` BIT(1),`start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',`duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query',PRIMARY KEY (`trace_id_high`, `trace_id`, `id`)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds';ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';ALTER TABLE zipkin_spans ADD INDEX(`remote_service_name`) COMMENT 'for getTraces and getRemoteServiceNames';ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';CREATE TABLE IF NOT EXISTS zipkin_annotations (`trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',`trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',`span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',`a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1',`a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB',`a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',`a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',`endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',`endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',`endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',`endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null') ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds';ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames';ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces and autocomplete values';ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces and autocomplete values';ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'for dependencies job';CREATE TABLE IF NOT EXISTS zipkin_dependencies (`day` DATE NOT NULL,`parent` VARCHAR(255) NOT NULL,`child` VARCHAR(255) NOT NULL,`call_count` BIGINT,`error_count` BIGINT,PRIMARY KEY (`day`, `parent`, `child`)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
  • 然后以mysql为存储方式启动zipkin
    • 在zipkin.jar同级目录下创建zipkin-server.properties文件,内容为
      zipkin.storage.type=mysql
      zipkin.storage.mysql.host=localhost
      zipkin.storage.mysql.port=3306
      zipkin.storage.mysql.username=root
      zipkin.storage.mysql.password=123456
      
  • 运行zipkin:java -jar zipkin.jar在这里插入图片描述

sleuth 示例

  1. 开始之前,我们先新建一个user表,一起放在zipkin数据库中

    SET NAMES utf8mb4;
    SET FOREIGN_KEY_CHECKS = 0;-- ----------------------------
    -- Table structure for tb_user
    -- ----------------------------
    DROP TABLE IF EXISTS `tb_user`;
    CREATE TABLE `tb_user` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID ',`name` varchar(255) NOT NULL COMMENT '用户名',PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;-- ----------------------------
    -- Records of tb_user
    -- ----------------------------
    BEGIN;
    INSERT INTO `tb_user` VALUES (1, 'Kitty');
    INSERT INTO `tb_user` VALUES (2, 'Mon');
    COMMIT;SET FOREIGN_KEY_CHECKS = 1;
    
  2. 创建一个名为sleuth-demo的maven项目,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.siqi.sleuth</groupId><artifactId>sleuth-demo</artifactId><packaging>pom</packaging><version>1.0-SNAPSHOT</version><modules><module>sleuth-sale</module><module>sleuth-user</module></modules><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><spring-boot.version>2.3.4.RELEASE</spring-boot.version><sleuth.version>2.2.6.RELEASE</sleuth.version></properties><dependencyManagement><!--maven的多继承情况下需要这么配置,否则无法多继承--><dependencies><!--分布式链路追踪父工程--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-sleuth-dependencies</artifactId><version>${sleuth.version}</version><type>pom</type><scope>import</scope></dependency><!--spring boot 父工程--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
    </project>
    

    继承两个父工程:spring boot和sleuth

  3. 创建sale子模块

    <?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"><parent><artifactId>sleuth-demo</artifactId><groupId>org.siqi.sleuth</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>sale</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- 通过http发送跟踪数据到zipkin(默认为 http://localhost:9411/api/v2/spans) --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId></dependency></dependencies>
    </project>
    

    新建一个Sale实体

    public class Sale {/*** ID*/private Long id;/*** 名称*/private String name;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}
    }
    

    新建一个SaleController

    @RestController
    public class SaleController {@AutowiredRestTemplate restTemplate;/*** 通过sale服务向user服务请求数据* http://localhost:8081/sales/1** @param id* @return*/@RequestMapping(value = "/sales/{id}", method = GET, produces = {APPLICATION_JSON_VALUE})public Sale describeSale(@PathVariable(value = "id") Long id) {// 向user服务请求数据return restTemplate.getForObject("http://localhost:8091/users/{1}", Sale.class, id);}@BeanRestTemplate restTemplate() {return new RestTemplate();}
    }
    

    模块配置为:

    spring.application.name=sale
    server.port=8081
    #
    #
    logging.level.org.springframework.web=DEBUG
    spring.sleuth.traceId128=true
    spring.sleuth.sampler.probability=1.0
    # Adds trace and span IDs to logs (when a trace is in progress)
    logging.pattern.level=[%X{traceId}/%X{spanId}] %-5p [%t] %C{2} - %m%n
    # Propagates a field named 'user_name' downstream
    # Note: In sleuth 3.x it is spring.sleuth.baggage.remote-fields=user_name
    spring.sleuth.propagation-keys=user_name
    
  4. 新建一个user模块,供sale模块进行服务调用
    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"><parent><artifactId>sleuth-demo</artifactId><groupId>org.siqi.sleuth</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>user</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- 通过http发送跟踪数据到zipkin(默认为 http://localhost:9411/api/v2/spans) --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId></dependency><dependency><groupId>io.zipkin.brave</groupId><artifactId>brave-instrumentation-mysql8</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency></dependencies></project>
    

    新建一个User实体:

    public class User {/*** ID*/private Long id;/*** 名称*/private String name;public User() {}public User(Long id, String name) {this.id = id;this.name = name;}public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}
    }
    

    新建一个UserRepository,来访问数据库获取用户数据:

    @Repository
    public class UserRepository {private static final Logger logger = LoggerFactory.getLogger(UserRepository.class);@Resourceprivate JdbcTemplate jdbcTemplate;/*** 根据用户ID查询用户信息** @param id ID* @return 用户信息*/public User queryById(Long id) {logger.info("query user by id ");// 由于是演示,所以使用最简单的方式查询数据库数据return (User) jdbcTemplate.queryForObject("select id, name from tb_user where id = ?",new Object[]{id},new BeanPropertyRowMapper(User.class));}
    }
    

    新建一个UserController

    @RestController
    public class UserController {@Resourceprivate UserRepository userRepository;/*** 查看用户信息* http://localhost:8091/users/1** @param id* @return json格式*/@ResponseBody@RequestMapping(value = "/users/{id}", method = GET, produces = {APPLICATION_JSON_VALUE})public User describeUser(@PathVariable(value = "id") Long id) {if (id == null) {throw new IllegalArgumentException("id can't be null");}return userRepository.queryById(id);}
    }
    

    配置文件为:

    spring.application.name=user
    server.port=8091# 日志等级
    logging.level.org.springframework.web=DEBUG
    logging.pattern.level=[%X{traceId}/%X{spanId}] %-5p [%t] %C{2} - %m%n
    #
    # sleuth配置
    spring.sleuth.traceId128=true
    spring.sleuth.sampler.probability=1.0
    # Adds trace and span IDs to logs (when a trace is in progress)# Propagates a field named 'user_name' downstream
    # Note: In sleuth 3.x it is spring.sleuth.baggage.remote-fields=user_name
    spring.sleuth.propagation-keys=user_name
    #
    # 数据库配置
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/zipkin?\useSSL=false\&queryInterceptors=brave.mysql8.TracingQueryInterceptor\&exceptionInterceptors=brave.mysql8.TracingExceptionInterceptor\&zipkinServiceName=userDB\&useUnicode=true&characterEncoding=utf8\&allowMultiQueries=true\&serverTimezone=UTC
    spring.datasource.username=root
    spring.datasource.password=123456
    

链路跟踪验证

  1. 启动sale、user模块,并访问地址:http://localhost:8081/sales/1
    这时我们发出了一个请求,通过浏览器-》sale-》user,然后返回数据
    在这里插入图片描述
    访问成功说明项目搭建没问题

  2. 我们来看看zipkin的跟踪情况,打开zipkin控制台:http://localhost:9411/

  3. 通过依赖,并选择指定的时间,可以查询出我们刚才发除的请求,从sale->user->userDB
    在这里插入图片描述

  4. 通过点击TRACES,可以查看指定请求花费时间
    在这里插入图片描述

  5. 至此,我们完成了从示例构建到zipkin链路跟踪演示

常见的链路追踪技术

  1. cat
    由大众点评开源,基于java开发的实时应用监控平台,包括实时应用监控,业务监控。继承方案是通过代码埋点的方式来实现监控,比如:拦截器,过滤器等。对代码的入侵性很大,集成成本较高,风险较大。

  2. zipkin
    由Twitter公司开源,开放源代码分布式的跟踪系统,用于手机服务的定时数据,以解决微服务架构中的延迟问题,包括数据的收集、存储、查找和展现。该产品结合spring-cloud-sleuth使用较为简单,集成很方便,但功能较简单

  3. pinpoint
    由韩国人开源的基于字节码注入的调用链分析,以及应用监控分析工具,特点是支持多种插件,UI功能较强,接入端无代码入侵。

  4. skywalking(推荐使用
    是本土开源的基于字节码注入的调用链分析,以及应用监控分析工具。特点和pinpoint差不多。
    在这里插入图片描述

扩展

  • sleuth采样算法
    Reservoir sampling(水塘抽样)。实现类是 PercentageBasedSampler
    附水塘抽样算法:https://www.cnblogs.com/krcys/p/9121487.html

相关文档

  • https://github.com/openzipkin/zipkin
  • https://spring.io/projects/spring-cloud-sleuth
  • https://github.com/openzipkin-attic/sleuth-webmvc-example
  • http://skywalking.apache.org/
  • https://segmentfault.com/a/1190000015977174

http://chatgpt.dhexx.cn/article/9tGQ4pAI.shtml

相关文章

SpringCloud Sleuth入门介绍

案例代码:https://github.com/q279583842q/springcloud-e-book 一、Sleuth介绍 为什么要使用微服务跟踪?它解决了什么问题&#xff1f; 1.微服务的现状&#xff1f; 微服务的现状   随着业务的发展&#xff0c;单体架构变为微服务架构&#xff0c;并且系统规模也变得越来…

Spring Cloud Sleuth HTTP详解

目录 1版本关系 2简介 2.1术语 2.2调用链可视化 2.2.1使用Zipkin进行分布式跟踪 2.2.2错误可视化 2.2.3使用Brave进行分布式跟踪 2.2.4将Sleuth添加到项目中 3调用信息生成与上报原理 3.1初始化配置类 3.2过滤器-请求过滤 3.3调用信息拦截 3.4调用信息上报 4日志…

Sleuth链路追踪

文章目录 Spring-Cloud-Alibaba-Sleuth链路追踪一、链路追踪介绍二、Sleuth入门演示&#xff1a; 三、ZipKin介绍ZipKin服务端安装ZipKin数据持久化 Spring-Cloud-Alibaba-Sleuth链路追踪 一、链路追踪介绍 在大型的微服务项目中&#xff0c;一个系统被拆分成许多模块&#xf…

sleuth原理详解

sleuth原理 1、关键术语 Span&#xff1a;Span基本工作单元&#xff0c;发送一个远程调度任务就会产生一个Span, Span 是用 64ID唯一标识的&#xff0c;Trace是用另一个64ID唯一标识的。Span还包含了其他的信息&#xff0c;例如摘要、时间戳事件、Span的ID以及进程 ID。Trace…

07-搭建微服务-链路追踪Sleuth

1、为什么使用链路追踪&#xff1f; 在微服务中&#xff0c;随着服务越来越多&#xff0c;对调用链的分析越来越复杂。 出现问题&#xff1a; 1、微服务之间的调用错综复杂&#xff0c;用户发送的请求经历哪些服务&#xff0c;调用链不清楚&#xff0c;没有一个自动化的工具类来…

sleuth入门

Sleuth介绍 SpringCloud Sleuth主要功能就是在分布式系统中提供追踪解决方案。它大量借用了Google Dapper的设计&#xff0c; 先来了解一下Sleuth中的术语和相关概念。 Trace 由一组Trace Id&#xff08;贯穿整个链路&#xff09;相同的Span串联形成一个树状结构。为了实现请求…

集成sleuth_Spring Cloud Sleuth整合zipkin过程解析

这篇文章主要介绍了Spring Cloud Sleuth整合zipkin过程解析,文中通过示例代码介绍的非常详细&#xff0c;对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 SpringCloud Sleuth 简介 Spring Cloud Sleuth为Spring Cloud实现了分布式跟踪解决方案。 Spring Clo…

集成sleuth_整合Sleuth

Sleuth是 springcloud 分布式跟踪解决方案。 Sleuth 术语&#xff1a; 跨度(span ) &#xff1a;Sleuth 的基本工作单元&#xff0c;他用一个64位的id唯一标识。出ID外&#xff0c;span还包含 其他的数据&#xff0c;如 描述&#xff0c;时间戳事件&#xff0c;键值对注解等&am…

Spring Boot 中的 Sleuth 是什么, 如何使用

Spring Boot 是一个非常流行的 Java Web 开发框架&#xff0c;它提供了许多方便的功能&#xff0c;其中之一就是 Sleuth。Sleuth 是一个分布式跟踪系统&#xff0c;用于跟踪应用程序中的请求和操作。在本文中&#xff0c;我们将探讨 Spring Boot 中的 Sleuth 是什么&#xff0c…

sleuth原理分析

背景 微服务模式下&#xff0c;一次请求可能会经过多个服务。如果没有日志链将单次请求的日志串起来&#xff0c;定位问题时很容易陷入海量的日志中&#xff0c;无法快速定位问题。 sleuth是spring cloud中日志链&#xff08;调用链解决方案&#xff09;&#xff0c;引入该依赖…

快速学习-Sleuth--链路追踪

Sleuth–链路追踪 6.1 链路追踪介绍 在大型系统的微服务化构建中&#xff0c;一个系统被拆分成了许多模块。这些模块负责不同的功能&#xff0c;组合成 系统&#xff0c;最终可以提供丰富的功能。在这种架构中&#xff0c;一次请求往往需要涉及到多个服务。互联网应用构建 在…

SpringCloud学习笔记(十二)Sleuth 分布式请求链路跟踪

目录 一、Sleuth介绍 1、为什么会出现这个技术&#xff1f;需要解决哪些问题&#xff1f; 2、是什么 二、搭建链路监控步骤 1、zipkin搭建安装 1&#xff09;下载 2&#xff09;运行jar 3&#xff09;运行控制台 4&#xff09;术语 2、服务提供者 cloud-provider-pa…

MySQL5种索引类型

一、简介 MySQL目前主要有以下几种索引类型&#xff1a; 1.普通索引 2.唯一索引 3.主键索引 4.组合索引 5.全文索引 二、语句 CREATE TABLE table_name[col_name data type] [unique|fulltext][index|key][index_name](col_name[length])[asc|desc] 1.unique|fulltext为可选…

mysql索引类型和索引方式

1.什么是索引 在MySQL中&#xff0c;索引&#xff08;index&#xff09;也叫做“键&#xff08;key&#xff09;”&#xff0c;它是存储引擎用于快速找到记录的一种数据结构。 2.索引的分类 在MySQL中&#xff0c;通常我们所指的索引类型&#xff0c;有以下几种&#xff1a;…

Mysql索引的类型(单列索引、组合索引 btree索引 聚簇索引等)

一、索引的类型 Mysql目前主要有以下几种索引类型&#xff1a;FULLTEXT&#xff0c;HASH&#xff0c;BTREE&#xff0c;RTREE。 FULLTEXT 即为全文索引&#xff0c;目前只有MyISAM引擎支持。其可以在CREATE TABLE &#xff0c;ALTER TABLE &#xff0c;CREATE INDEX 使用&…

mysql索引类型有哪些?

在Mysql数据库当中&#xff0c;我们经常会谈到Sql语句&#xff0c;当然也会谈到索引优化&#xff0c;那么在数据库当中有哪些索引类型呢&#xff0c;博主在这里进行分享&#xff0c;希望对大家能有所帮助。 目录 1、B-Tree索引&#xff1a; 2、Hash索引&#xff1a; 3、Full…

什么是索引?Mysql目前主要的几种索引类型

一、索引 MySQL索引的建立对于MySQL的高效运行是很重要的&#xff0c;索引可以大大提高MySQL的检索速度。 打个比方&#xff0c;如果合理的设计且使用索引的MySQL是一辆兰博基尼的话&#xff0c;那么没有设计和使用索引的MySQL就是一个人力三轮车。 索引分单列索引和组合索引。…

Mysql索引类型与索引方法

写在前面&#xff1a; 乍一看这两个概念可能有点混&#xff0c;先上一张发图。 索引类型就是我们平常说的唯一索引&#xff0c;主键索引&#xff0c;组合索引等索引类型。 我们都知道索引是一种数据结构&#xff0c;到底我们建的索引应该以什么样的结构存储呢&#xff1f;存储…

MYSQL 索引类型

一、索引类型 在数据库表中&#xff0c;对字段建立索引可以大大提高查询速度。假如我们创建了一个 mytable表 代码如下: CREATE TABLE mytable( ID INT NOT NULL, username VARCHAR(16) NOT NULL ); 我们随机向里面插入了10000条记录&#xff0c;其中有一条&#xff1a;555…

常见索引类型

日常开发工作中&#xff0c;涉及到的数据存储&#xff0c;要做查询优化或想深入了解存储引擎&#xff0c;需要对索引知识有个起码的了解&#xff0c;下面介绍下最常见的四种索引结构。 位图索引哈希索引BTREE索引倒排索引 1、位图索引&#xff08;BitMap&#xff09; 位图索引…