<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>大数据技术</title><link>http://mllib.cn/</link><description>山高人为峰</description><item><title>单机上部署kafka3.5，并配置sasl认证</title><link>http://mllib.cn/?id=14</link><description>&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;概述&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;今天我要跟大家分享一下如何在单机上部署kafka3.5，并配置sasl认证（plaintext模式）。kafka是一个分布式的消息队列，可以用来处理大量的数据流。sasl是一种安全认证机制，可以保证kafka的通信安全。下面我会分几个步骤来介绍这个过程。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;第一步，安装kafka&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;下载并解压kafka3.5的安装包。你可以从官网或者其他镜像站点下载kafka的压缩文件，然后解压到你想要的目录。例如，我把它解压到了/home/kafka目录。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;第二步，修改kafka的配置文件&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;你需要修改两个文件，一个是server.properties，另一个是kafka_server_jaas.conf。server.properties是kafka的主要配置文件，里面有很多参数可以调整。kafka_server_jaas.conf是sasl认证的配置文件，里面定义了认证的方式和用户信息。这两个文件都在kafka的config目录下。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;在server.properties中，你需要修改以下几个参数：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;broker.id：这是kafka的唯一标识，每个broker都需要有一个不同的id。因为我们只有一个broker，所以可以设置为0。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;listeners：这是kafka的监听地址和端口，可以有多个。我们需要添加一个sasl_plaintext类型的监听器，表示使用sasl和明文传输。例如，我们可以设置为listeners=PLAINTEXT://:9092,SASL_PLAINTEXT://:9093。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;advertised.listeners：这是kafka对外公布的监听地址和端口，客户端会根据这个来连接kafka。我们需要和listeners保持一致，例如advertised.listeners=PLAINTEXT://:9092,SASL_PLAINTEXT://:9093。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;zookeeper.connect：这是kafka连接zookeeper的地址和端口，zookeeper是一个分布式协调服务，用来管理kafka的元数据。因为我们只有一个zookeeper，所以可以设置为localhost:2181。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;sasl.enabled.mechanisms：这是kafka启用的sasl认证方式，可以有多个。我们使用最简单的PLAIN方式，所以设置为sasl.enabled.mechanisms=PLAIN。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;sasl.mechanism.inter.broker.protocol：这是kafka之间通信使用的sasl认证方式，必须是sasl.enabled.mechanisms中的一个。我们也设置为PLAIN。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;authorizer.class.name：这是kafka使用的授权类，用来控制客户端对主题和消费组的访问权限。我们使用默认的SimpleAclAuthorizer，所以设置为authorizer.class.name=kafka.security.authorizer.AclAuthorizer。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;super.users：这是kafka的超级用户列表，他们可以访问所有的主题和消费组，不受授权限制。我们可以设置为自己的用户名，例如super.users=User:admin。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;在kafka_server_jaas.conf中，你需要添加以下内容：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;KafkaServer&amp;nbsp;{
org.apache.kafka.common.security.plain.PlainLoginModule&amp;nbsp;required
username=“admin”
password=“admin”
user_admin=“admin”
user_alice=“alice”;
};&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;这里我们定义了一个KafkaServer段，表示kafka服务器端使用的认证模块。我们使用PlainLoginModule，并指定了用户名和密码。我们还定义了两个用户，admin和alice，并分别给他们设置了密码。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;第三步，启动zookeeper和kafka&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;你需要先启动zookeeper，然后启动kafka。你可以使用kafka自带的脚本来启动它们。例如，在/home/kafka目录下执行以下命令：&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;bin/zookeeper-server-start.sh&amp;nbsp;config/zookeeper.properties&amp;nbsp;&amp;amp;
bin/kafka-server-start.sh&amp;nbsp;config/server.properties&amp;nbsp;&amp;amp;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;如果没有报错，那么恭喜你，你已经成功部署了kafka3.5，并配置了sasl认证。&lt;/p&gt;&lt;h2 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 20px; color: rgb(79, 79, 79); line-height: 30px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a name=&quot;t4&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a id=&quot;kafka_43&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;第四步，测试kafka的功能和安全性&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;你可以使用kafka自带的命令行工具来创建主题，生产和消费消息，以及查看授权信息。例如，在/home/kafka目录下执行以下命令：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;#&amp;nbsp;创建一个名为test的主题，有一个分区和一个副本
bin/kafka-topics.sh&amp;nbsp;--create&amp;nbsp;--topic&amp;nbsp;test&amp;nbsp;--partitions&amp;nbsp;1&amp;nbsp;--replication-factor&amp;nbsp;1&amp;nbsp;--bootstrap-server&amp;nbsp;localhost:9092

#&amp;nbsp;查看主题的信息
bin/kafka-topics.sh&amp;nbsp;--describe&amp;nbsp;--topic&amp;nbsp;test&amp;nbsp;--bootstrap-server&amp;nbsp;localhost:9092

#&amp;nbsp;生产一些消息到test主题，使用sasl_plaintext协议和admin用户
bin/kafka-console-producer.sh&amp;nbsp;--topic&amp;nbsp;test&amp;nbsp;--broker-list&amp;nbsp;localhost:9093&amp;nbsp;--producer.config&amp;nbsp;config/producer.properties

#&amp;nbsp;消费test主题的消息，使用sasl_plaintext协议和alice用户
bin/kafka-console-consumer.sh&amp;nbsp;--topic&amp;nbsp;test&amp;nbsp;--bootstrap-server&amp;nbsp;localhost:9093&amp;nbsp;--consumer.config&amp;nbsp;config/consumer.properties

#&amp;nbsp;查看test主题的授权信息
bin/kafka-acls.sh&amp;nbsp;--describe&amp;nbsp;--topic&amp;nbsp;test&amp;nbsp;--bootstrap-server&amp;nbsp;localhost:9092&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;在config目录下，你需要创建两个文件，producer.properties和consumer.properties，分别用来配置生产者和消费者的认证信息。例如，producer.properties的内容如下：&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;sasl.mechanism=PLAIN
security.protocol=SASL_PLAINTEXT
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule&amp;nbsp;required&amp;nbsp;\
username=&amp;quot;admin&amp;quot;&amp;nbsp;\
password=&amp;quot;admin&amp;quot;;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;consumer.properties的内容如下：&lt;/span&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;sasl.mechanism=PLAIN
security.protocol=SASL_PLAINTEXT
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule&amp;nbsp;required&amp;nbsp;\
username=&amp;quot;alice&amp;quot;&amp;nbsp;\
password=&amp;quot;alice&amp;quot;;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;通过这些命令，你可以验证kafka的基本功能和sasl认证的效果。你可以尝试使用不同的用户和密码，或者不使用sasl_plaintext协议，看看会发生什么。&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以上就是我今天要分享的内容，希望对你有帮助。如果你有任何问题或建议，欢迎留言。谢谢！&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 29 Mar 2024 19:33:24 +0800</pubDate></item><item><title>实战指南-构建安全可靠的Kafka集群并配置SASL/PLAIN认证</title><link>http://mllib.cn/?id=13</link><description>&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: #535861; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;引言 近年来，随着大数据和分布式系统的快速发展，数据传输和处理的需求也越来越大。在这个背景下，Apache Kafka作为一款高性能、高可靠性的分布式流媒体平台，吸引了众多企业和开发者的关注。与此同时，随着安全和数据保护意识的提升，数据传输的安全性也变得尤为重要。正因如此，深入了解Kafka集群的安装和认证机制显得尤为重要。本文将为大家介绍如何搭建一个具有SASL认证机制的Kafka集群环境，并分享一些实验经验和注意事项。&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;span style=&quot;background-color: #FFFFFF; color: #191B1F; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium;&quot;&gt;本文主要以3虚拟机测试环境安装了JDK 11, Zookeeper 3.8.3和Kafka 2.7.2集群，同时演示怎么来通过配置简单SASL认证后，怎么通过客户端来SASL密码方式登录Kafka服务器集群。在实践操作之前对Kafka、Kafka认证方式及SASL认证进行了简单的介绍。然而，仅仅通过用户名和密码进行连接认证是远远不够的，在实际应用中还是根据具体需求而选择不同的Kafka认证方式。&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 id=&quot;h_666793036_0&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1 Kafka认证&lt;/h2&gt;&lt;h3 id=&quot;h_666793036_1&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;关于Kafka&lt;/h3&gt;&lt;p data-pid=&quot;i4kCo_sv&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Apache Kafka是一种分布式流处理平台，它具有高吞吐量、扩展性和可靠性的特点。作为一个强大的分布式消息传递系统，Kafka被广泛应用于各种场景，如实时数据流处理、日志收集、事件驱动架构等。它通过高吞吐量、可靠性和可扩展性，为企业提供了处理大规模实时数据流的解决方案，满足了现代数据处理的需求。&lt;/p&gt;&lt;p data-pid=&quot;Awvyn2TN&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;随着数据传输和存储的增加，保护数据安全和隐私成为组织和个人的首要任务。Kafka提供了多种安全功能来确保数据的机密性、完整性和可用性。&lt;/p&gt;&lt;h3 id=&quot;h_666793036_2&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;关于Kafka认证&lt;/h3&gt;&lt;p data-pid=&quot;NUSYTIQO&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Kafka提供了多种认证方式来保护集群的安全性，包括以下几种常见的认证方式：&lt;/p&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;SSL/TLS认证：Kafka支持使用SSL/TLS协议对网络通信进行加密和认证。通过使用SSL/TLS证书对客户端和服务器进行身份验证，可以确保通信的机密性和完整性。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SASL/PLAIN认证：SASL/PLAIN是一种基于用户名密码的认证机制，可用于Kafka和其他应用程序之间的认证。它要求客户端提供用户名和密码来进行身份验证，并使用安全的方式进行传输。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SASL/GSSAPI(Kerberos)认证：SASL/GSSAPI认证是一种基于Kerberos的单点登录认证机制。它使用Kerberos票据来进行身份验证，通过集成现有的企业身份验证系统，实现了强大的安全性和无缝的用户体验。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;自定义认证插件：Kafka还提供了自定义认证插件的扩展机制，允许用户根据特定需求实现自己的认证机制。通过自定义认证插件，可以与现有的身份验证系统或者第三方认证服务进行集成。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p data-pid=&quot;wp3us_oG&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Kafka的认证方式的&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;实现原理&lt;/span&gt;主要涉及以下几个步骤：&lt;/p&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;配置设置：通过Kafka的配置文件，设置认证方式和相关参数，如SSL证书的路径、用户名密码的配置等。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;证书生成和配置：对于SSL/TLS认证，需要生成证书和私钥，并将其配置到Kafka的服务器端和客户端。证书用于对通信进行加密和认证。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;用户认证信息配置：对于SASL/PLAIN和SASL/GSSAPI认证，需要在Kafka的配置文件中配置用户的认证信息，如用户名和密码，或者Kerberos票据。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;服务器端验证：服务器端接收到客户端的连接请求后，根据配置的认证方式进行验证。对于SSL/TLS认证，服务器会验证客户端的证书；对于SASL/PLAIN和SASL/GSSAPI认证，服务器会验证客户端提供的用户名和密码或Kerberos票据。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;客户端验证：客户端与服务器建立连接后，根据配置的认证方式提供相应的证书、用户名密码或Kerberos票据，进行身份验证。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p data-pid=&quot;pu5cfy2_&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;通过以上步骤，Kafka能够实现不同的认证方式来保护集群的安全性。根据具体的需求和环境，选择合适的认证方式并正确配置，可以确保Kafka集群的安全访问和数据传输。&lt;/p&gt;&lt;h3 id=&quot;h_666793036_3&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;关于，&lt;/h3&gt;&lt;p data-pid=&quot;YeijC2BZ&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;GNU SASL是简单身份验证和安全层框架以及一些常见SASL机制的实现。SASL被网络服务器(例如IMAP、SMTP、XMPP)用来请求来自客户端的身份验证，并在客户端中用来对服务器进行身份验证。&lt;/p&gt;&lt;p data-pid=&quot;3_76DG6O&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SASL是一个挑战-响应框架。在这里，服务器向客户机发出请求，客户机根据该请求发送响应。质询和响应是任意长度的字节数组，因此可以携带任何特定于机制的数据。工作简单原理图如下：&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://pic4.zhimg.com/80/v2-9932c3f34bcc75104417a97bc69a7447_720w.webp&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color: #FFFFFF;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 id=&quot;h_666793036_4&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;关于Kafka SASL认证&lt;/h3&gt;&lt;p data-pid=&quot;WX1sUgLj&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Kafka使用Java认证和授权服务(JAAS)进行SASL配置。&lt;/p&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;Kafka代理的JAAS配置： KafkaServer部分是每个KafkaServer/Broker使用的JAAS文件中的节名。为代理提供SASL配置选项，包括代理为进行代理间通信而建立的任何SASL客户机连接。如果多个侦听器配置为使用SASL，则可以使用侦听器名称的小写前缀加上句号，例如&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;sasl_ssl.KafkaServer&lt;/code&gt;。 Client部分用于验证与zookeeper的SASL连接。它还允许代理在zookeeper节点上设置SASL ACL，从而锁定这些节点，以便只有代理可以修改它。有必要在所有代理中使用相同的主体名称。如果你想使用一个节名而不是Client，设置系统属性&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;zookeeper.sasl.clientconfig&lt;/code&gt;为合适的名称(例如，&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;-Dzookeeper.sasl.clientconfig=ZkClient&lt;/code&gt;)。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kafka客户端的JAAS配置： 客户端可以使用客户端配置属性&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;sasl.jaas.config&lt;/code&gt;或使用类似于代理的静态JAAS配置文件来配置JAAS。&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p data-pid=&quot;FRmjsRuU&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文中后续以一个简单的例子较直观来解析kafka服务器端和客户端的配置连接。&lt;/p&gt;&lt;h2 id=&quot;h_666793036_5&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2 安装Kafka集群&lt;/h2&gt;&lt;p data-pid=&quot;uE3UYX0g&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;接下来例子以3个虚拟机Linux环境下，Kafka版本选择的是2.7的版本，在安装Kafka软件分别在3台机器上安装JDK和Zookeeper并配置zk正确运行下再安装Kafka。该环境下三台机器和IP地址分别如下：&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;VM65201&amp;nbsp;192.3.65.201
VM65202&amp;nbsp;192.3.65.202
VM65203&amp;nbsp;192.3.65.203&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&quot;h_666793036_6&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;准备工作&lt;/h3&gt;&lt;p data-pid=&quot;fCiuskMD&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;下载所需的软件包：&lt;/p&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;JDK 11：&amp;nbsp;&lt;a href=&quot;https://link.zhihu.com/?target=https%3A//www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html&quot; class=&quot; external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;https://www.&lt;/span&gt;&lt;span class=&quot;visible&quot;&gt;oracle.com/java/technol&lt;/span&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;ogies/javase/jdk11-archive-downloads.html&lt;/span&gt;&lt;span class=&quot;ellipsis&quot;&gt;&lt;/span&gt;&lt;/a&gt;&amp;nbsp;。选项“Linux x64 Compressed Archive”处进行 download&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic3.zhimg.com/80/v2-e6e261b98d92014e2349858528e2955a_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;1581&quot; data-rawheight=&quot;669&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;1581&quot; data-original=&quot;https://pic3.zhimg.com/v2-e6e261b98d92014e2349858528e2955a_r.jpg&quot; data-actualsrc=&quot;https://pic3.zhimg.com/v2-e6e261b98d92014e2349858528e2955a_b.jpg&quot; data-original-token=&quot;v2-eeeaf04d14430b8d9de344f94185e334&quot; height=&quot;669&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p data-pid=&quot;kqdArY5b&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;jdk-11.0.20_linux-x64_bin.tar.gz&lt;/code&gt;&lt;/p&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;em&gt;Zookeeper 3.8.3：&lt;a href=&quot;https://link.zhihu.com/?target=https%3A//zookeeper.apache.org/releases.html&quot; class=&quot; external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-style: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;https://&lt;/span&gt;&lt;span class=&quot;visible&quot;&gt;zookeeper.apache.org/re&lt;/span&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-style: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;leases.html&lt;/span&gt;&lt;span class=&quot;ellipsis&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic2.zhimg.com/80/v2-ba1a350f68df91601cf017c25ac2aee9_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;956&quot; data-rawheight=&quot;201&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;956&quot; data-original=&quot;https://pic2.zhimg.com/v2-ba1a350f68df91601cf017c25ac2aee9_r.jpg&quot; data-actualsrc=&quot;https://pic2.zhimg.com/v2-ba1a350f68df91601cf017c25ac2aee9_b.jpg&quot; data-original-token=&quot;v2-c70ccd0b349d188c5d31265b7d40ef26&quot; height=&quot;201&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p data-pid=&quot;Zcm1GHAp&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;em&gt;&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;apache-zookeeper-3.8.3-bin.tar.gz&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;Kafka 2.7：官网下载&amp;nbsp;&lt;a href=&quot;https://link.zhihu.com/?target=https%3A//kafka.apache.org/downloads&quot; class=&quot; external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;https://&lt;/span&gt;&lt;span class=&quot;visible&quot;&gt;kafka.apache.org/downlo&lt;/span&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;ads&lt;/span&gt;&lt;span class=&quot;ellipsis&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic3.zhimg.com/80/v2-3a934d668c3865f4f31987af4486fbda_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;1455&quot; data-rawheight=&quot;504&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;1455&quot; data-original=&quot;https://pic3.zhimg.com/v2-3a934d668c3865f4f31987af4486fbda_r.jpg&quot; data-actualsrc=&quot;https://pic3.zhimg.com/v2-3a934d668c3865f4f31987af4486fbda_b.jpg&quot; data-original-token=&quot;v2-03c2ba3bdd7f941aa15adb0b97e56e3f&quot; height=&quot;504&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p data-pid=&quot;CIv5iCO9&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;kafka_2.13-2.7.2.tgz&lt;/code&gt;&lt;/p&gt;&lt;p data-pid=&quot;WGKFtgD-&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;安装Java&lt;/span&gt;（三台机器均需要执行）&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;--root下运行cd&amp;nbsp;/usr/local
ls&amp;nbsp;-lh&amp;nbsp;jdk-11.0.20_linux-x64_bin.tar.gz
tar&amp;nbsp;-xf&amp;nbsp;jdk-11.0.20_linux-x64_bin.tar.gz&amp;nbsp;
cat&amp;nbsp;&amp;gt;&amp;gt;&amp;nbsp;/etc/profile&amp;nbsp;&amp;lt;&amp;lt;EOFexport&amp;nbsp;JAVA_HOME=/usr/local/jdk-11.0.20export&amp;nbsp;PATH=\$JAVA_HOME/bin:\$PATHexport&amp;nbsp;CLASSPATH=.:\$JAVA_HOME/lib:\$CLASSPATHEOF--确认java安装状况#&amp;nbsp;source&amp;nbsp;/etc/profile#&amp;nbsp;java&amp;nbsp;-versionjava&amp;nbsp;version&amp;nbsp;&amp;quot;11.0.20&amp;quot;&amp;nbsp;2023-07-18&amp;nbsp;LTS
Java(TM)&amp;nbsp;SE&amp;nbsp;Runtime&amp;nbsp;Environment&amp;nbsp;18.9&amp;nbsp;(build&amp;nbsp;11.0.20+9-LTS-256)Java&amp;nbsp;HotSpot(TM)&amp;nbsp;64-Bit&amp;nbsp;Server&amp;nbsp;VM&amp;nbsp;18.9&amp;nbsp;(build&amp;nbsp;11.0.20+9-LTS-256,&amp;nbsp;mixed&amp;nbsp;mode)&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&quot;h_666793036_7&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;安装和配置Zookeeper集群&lt;/h3&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;在三台机器上相同操作分别安装zookeeper软件，上传安装包到&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;/usr/local&lt;/code&gt;，此处将软件安装到&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;/usr/local&lt;/code&gt;下。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;--root用户执行cd&amp;nbsp;/usr/local/
ls&amp;nbsp;-lh&amp;nbsp;apache-zookeeper-3.8.3-bin.tar.gz
tar&amp;nbsp;-xf&amp;nbsp;apache-zookeeper-3.8.3-bin.tar.gz&amp;nbsp;
ls&amp;nbsp;-l&amp;nbsp;apache-zookeeper-3.8.3-bin/
--准备日志和数据目录
mkdir&amp;nbsp;-p&amp;nbsp;apache-zookeeper-3.8.3-bin/data&amp;nbsp;apache-zookeeper-3.8.3-bin/logs&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;三台机器上相同操作分别配置&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;zoo.cfg&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;cat&amp;nbsp;&amp;gt;&amp;nbsp;apache-zookeeper-3.8.3-bin/conf/zoo.cfg&amp;nbsp;&amp;lt;&amp;lt;EOF
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/usr/local/apache-zookeeper-3.8.3-bin/logs
dataDir=/usr/local/apache-zookeeper-3.8.3-bin/data
clientPort=2181
server.1=192.3.65.201:2888:3888
server.2=192.3.65.202:2888:3888
server.3=192.3.65.203:2888:3888
EOF&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;三台机器分别配置不同的myid&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;VM65201:/usr/local&amp;nbsp;#&amp;nbsp;echo&amp;nbsp;&amp;quot;1&amp;quot;&amp;nbsp;&amp;gt;&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/data/myid
VM65202:/usr/local&amp;nbsp;#&amp;nbsp;echo&amp;nbsp;&amp;quot;2&amp;quot;&amp;nbsp;&amp;gt;&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/data/myid
VM65203:/usr/local&amp;nbsp;#&amp;nbsp;echo&amp;nbsp;&amp;quot;3&amp;quot;&amp;nbsp;&amp;gt;&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/data/myid&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;启动zookeeer集群&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;#&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/bin/zkServer.sh&amp;nbsp;startZooKeeper&amp;nbsp;JMX&amp;nbsp;enabled&amp;nbsp;by&amp;nbsp;default
Using&amp;nbsp;config:&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/bin/../conf/zoo.cfg
Starting&amp;nbsp;zookeeper&amp;nbsp;...&amp;nbsp;STARTED

--三台机器上分别查看状态
VM65201:/usr/local&amp;nbsp;#&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/bin/zkServer.sh&amp;nbsp;statusZooKeeper&amp;nbsp;JMX&amp;nbsp;enabled&amp;nbsp;by&amp;nbsp;default
Using&amp;nbsp;config:&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/bin/../conf/zoo.cfg
Client&amp;nbsp;port&amp;nbsp;found:&amp;nbsp;2181.&amp;nbsp;Client&amp;nbsp;address:&amp;nbsp;localhost.&amp;nbsp;Client&amp;nbsp;SSL:&amp;nbsp;false.
Mode:&amp;nbsp;follower
VM65202:/usr/local&amp;nbsp;#&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/bin/zkServer.sh&amp;nbsp;statusZooKeeper&amp;nbsp;JMX&amp;nbsp;enabled&amp;nbsp;by&amp;nbsp;default
Using&amp;nbsp;config:&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/bin/../conf/zoo.cfg
Client&amp;nbsp;port&amp;nbsp;found:&amp;nbsp;2181.&amp;nbsp;Client&amp;nbsp;address:&amp;nbsp;localhost.&amp;nbsp;Client&amp;nbsp;SSL:&amp;nbsp;false.
Mode:&amp;nbsp;follower
VM65203:/usr/local&amp;nbsp;#&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/bin/zkServer.sh&amp;nbsp;statusZooKeeper&amp;nbsp;JMX&amp;nbsp;enabled&amp;nbsp;by&amp;nbsp;default
Using&amp;nbsp;config:&amp;nbsp;/usr/local/apache-zookeeper-3.8.3-bin/bin/../conf/zoo.cfg
Client&amp;nbsp;port&amp;nbsp;found:&amp;nbsp;2181.&amp;nbsp;Client&amp;nbsp;address:&amp;nbsp;localhost.&amp;nbsp;Client&amp;nbsp;SSL:&amp;nbsp;false.
Mode:&amp;nbsp;leader&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&quot;h_666793036_8&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;安装和配置Kafka集群&lt;/h3&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;在三台机器上相同操作分别安装Kafka软件，上传安装包到&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;/usr/local&lt;/code&gt;，此处将软件安装到&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;/usr/local&lt;/code&gt;下。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;--root用户下执行cd&amp;nbsp;/usr/local
ls&amp;nbsp;-lh&amp;nbsp;kafka_2.13-2.7.2.tgz
tar&amp;nbsp;-zxf&amp;nbsp;kafka_2.13-2.7.2.tgz&amp;nbsp;
mkdir&amp;nbsp;-p&amp;nbsp;kafka_2.13-2.7.2/logs&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;三台机器上准备不同的配置文件。如果不配置&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;listeners&lt;/span&gt;参数，只能本地&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;localhost:9092&lt;/code&gt;端口访问。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;#&amp;nbsp;cp&amp;nbsp;kafka_2.13-2.7.2/config/server.properties&amp;nbsp;kafka_2.13-2.7.2/config/server.properties.org

--节点1
cat&amp;nbsp;&amp;gt;&amp;nbsp;kafka_2.13-2.7.2/config/server.properties&amp;nbsp;&amp;lt;&amp;lt;EOF
broker.id=1
listeners=PLAINTEXT://192.3.65.201:9092
log.dirs=/usr/local/kafka_2.13-2.7.2/logs
zookeeper.connect=192.3.65.201:2181,192.3.65.202:2181,192.3.65.203:2181
EOF

--节点2
cat&amp;nbsp;&amp;gt;&amp;nbsp;kafka_2.13-2.7.2/config/server.properties&amp;nbsp;&amp;lt;&amp;lt;EOF
broker.id=2
listeners=PLAINTEXT://192.3.65.202:9092
log.dirs=/usr/local/kafka_2.13-2.7.2/logs
zookeeper.connect=192.3.65.201:2181,192.3.65.202:2181,192.3.65.203:2181
EOF

--节点3
cat&amp;nbsp;&amp;gt;&amp;nbsp;kafka_2.13-2.7.2/config/server.properties&amp;nbsp;&amp;lt;&amp;lt;EOF
broker.id=3
listeners=PLAINTEXT://192.3.65.203:9092
log.dirs=/usr/local/kafka_2.13-2.7.2/logs
zookeeper.connect=192.3.65.201:2181,192.3.65.202:2181,192.3.65.203:2181
EOF&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;启动Kafka集群&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;#&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-server-start.sh&amp;nbsp;-daemon&amp;nbsp;kafka_2.13-2.7.2/config/server.properties

--如果失败&amp;nbsp;可以去除daemon通过前台启动或者查看logs/下日志
#&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-server-start.sh&amp;nbsp;kafka_2.13-2.7.2/config/server.properties
...&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;h_666793036_9&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3 SASL/PLAIN认证&lt;/h2&gt;&lt;h3 id=&quot;h_666793036_10&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;默认连接操作&lt;/h3&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;通过Kafka软件下自带的工具连接 - 创建topic&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;#&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-topics.sh&amp;nbsp;--list&amp;nbsp;--bootstrap-server&amp;nbsp;192.3.65.201:9092,192.3.65.202:9092,192.3.65.203:9092
#&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-topics.sh&amp;nbsp;--create&amp;nbsp;&amp;nbsp;--bootstrap-server&amp;nbsp;192.3.65.201:9092,192.3.65.202:9092,192.3.65.203:9092&amp;nbsp;--replication-factor&amp;nbsp;3&amp;nbsp;--partitions&amp;nbsp;1&amp;nbsp;--topic&amp;nbsp;test1
Created&amp;nbsp;topic&amp;nbsp;test1.
#&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-topics.sh&amp;nbsp;--list&amp;nbsp;--bootstrap-server&amp;nbsp;192.3.65.201:9092,192.3.65.202:9092,192.3.65.203:9092
test1&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&quot;h_666793036_11&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;配置SASL/PLAIN认证&lt;/h3&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;zookeeper上准备授权用户 admin，密码&lt;code style=&quot;background-color: rgb(248, 248, 250); border-radius: 3px; font-family: Menlo, Monaco, Consolas, &amp;quot;Andale Mono&amp;quot;, &amp;quot;lucida console&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 0.9em; margin: 0px 2px; padding: 3px 4px;&quot;&gt;admin2023&lt;/code&gt;。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;--其中一台机器上登录zk
VM65201:/usr/local&amp;nbsp;#&amp;nbsp;apache-zookeeper-3.8.3-bin/bin/zkCli.sh&amp;nbsp;
...
[zk:&amp;nbsp;localhost:2181(CONNECTED)&amp;nbsp;0]&amp;nbsp;create&amp;nbsp;/digest&amp;nbsp;user
Created&amp;nbsp;/digest
[zk:&amp;nbsp;localhost:2181(CONNECTED)&amp;nbsp;1]&amp;nbsp;addauth&amp;nbsp;digest&amp;nbsp;admin:admin2023
[zk:&amp;nbsp;localhost:2181(CONNECTED)&amp;nbsp;2]&amp;nbsp;setAcl&amp;nbsp;/digest&amp;nbsp;auth:admin:admin2023:crwda
[zk:&amp;nbsp;localhost:2181(CONNECTED)&amp;nbsp;3]&amp;nbsp;quit&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;三台机器上分别修改配置&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;--root用户#&amp;nbsp;cp&amp;nbsp;kafka_2.13-2.7.2/config/server.properties&amp;nbsp;kafka_2.13-2.7.2/config/server-sasl.properties#&amp;nbsp;vi&amp;nbsp;kafka_2.13-2.7.2/config/server-sasl.properties&amp;nbsp;--修改listener中PLIANTEXT为SASL_PLAINTEXT#listeners=PLAINTEXT://192.3.65.201:9092listeners=SASL_PLAINTEXT://:9092

--增加如下内容指定认证方式
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=PLAIN
sasl.enabled.mechanisms=PLAIN

--指定超级管理员用户
super.users=User:admin&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;准备服务器端jaas文件，并指定用户名和密码。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;--三台服务器均需执行
cat&amp;nbsp;&amp;gt;&amp;gt;&amp;nbsp;&amp;nbsp;kafka_2.13-2.7.2/config/kafka-server-jaas.conf&amp;nbsp;&amp;lt;&amp;lt;EOF
KafkaServer&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;org.apache.kafka.common.security.plain.PlainLoginModule&amp;nbsp;required
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;username=&amp;quot;admin&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password=&amp;quot;admin2023&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;user_admin=&amp;quot;admin2023&amp;quot;;
};
EOF&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;重新启动kafka服务器，三台服务器均需执行。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;--停止服务器#&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-server-stop.sh&amp;nbsp;--修改启动脚本#&amp;nbsp;cp&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-server-start.sh&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-server-start-sasl.sh&amp;nbsp;#&amp;nbsp;vi&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-server-start-sasl.sh&amp;nbsp;exec&amp;nbsp;$base_dir/kafka-run-class.sh&amp;nbsp;$EXTRA_ARGS&amp;nbsp;kafka.Kafka&amp;nbsp;&amp;quot;$@&amp;quot;--&amp;gt;改为exec&amp;nbsp;$base_dir/kafka-run-class.sh&amp;nbsp;$EXTRA_ARGS&amp;nbsp;-Djava.security.auth.login.config=/usr/local/kafka_2.13-2.7.2/config/kafka-server-jaas.conf&amp;nbsp;kafka.Kafka&amp;nbsp;&amp;quot;$@&amp;quot;--启动带SASL的服务器#&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-server-start-sasl.sh&amp;nbsp;kafka_2.13-2.7.2/config/server-sasl.properties&amp;nbsp;...
--后台启动#&amp;nbsp;kafka_2.13-2.7.2/bin/kafka-server-start-sasl.sh&amp;nbsp;-daemon&amp;nbsp;kafka_2.13-2.7.2/config/server-sasl.properties&amp;nbsp;#&amp;nbsp;jps23638&amp;nbsp;QuorumPeerMain27133&amp;nbsp;Kafka27151&amp;nbsp;Jps&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;另外一台有Kafka客户端的机器上配置Kafka客户端认证文件并登录集群&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;--由于登录Kafka认证会严重服务器主机名，所以需先配置/etc/hosts
#&amp;nbsp;cat&amp;nbsp;&amp;gt;&amp;gt;/etc/hosts&amp;nbsp;&amp;lt;&amp;lt;EOF
192.3.65.201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VM65201
192.3.65.202&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VM65202
192.3.65.203&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VM65203
EOF

--不配置/etc/hosts会出现如下报错
[2023-11-08&amp;nbsp;09:37:58,961]&amp;nbsp;WARN&amp;nbsp;[Controller&amp;nbsp;id=1,&amp;nbsp;targetBrokerId=2]&amp;nbsp;Error&amp;nbsp;connecting&amp;nbsp;to&amp;nbsp;node&amp;nbsp;VM65202:9092&amp;nbsp;(id:&amp;nbsp;2&amp;nbsp;rack:&amp;nbsp;null)&amp;nbsp;(org.apache.kafka.clients.NetworkClient)
java.net.UnknownHostException:&amp;nbsp;VM65202:&amp;nbsp;Name&amp;nbsp;or&amp;nbsp;service&amp;nbsp;not&amp;nbsp;known

--配置客户端配置
#&amp;nbsp;cat&amp;nbsp;&amp;gt;&amp;nbsp;/tmp/jaas.conf&amp;nbsp;&amp;lt;&amp;lt;EOF
KafkaClient&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;org.apache.kafka.common.security.plain.PlainLoginModule&amp;nbsp;required
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;username=&amp;quot;admin&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password=&amp;quot;admin2023&amp;quot;;
};
EOF
#&amp;nbsp;cat&amp;nbsp;&amp;gt;&amp;nbsp;/tmp/security-client.properties&amp;nbsp;&amp;lt;&amp;lt;EOF
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
EOF

#&amp;nbsp;bin/kafka-topics.sh&amp;nbsp;--list&amp;nbsp;--bootstrap-server&amp;nbsp;192.3.65.201:9092,192.3.65.202:9092,192.3.65.203:9092&amp;nbsp;--command-config&amp;nbsp;/tmp/security-client.properties&amp;nbsp;
test1
#&amp;nbsp;bin/kafka-topics.sh&amp;nbsp;--describe&amp;nbsp;--bootstrap-server&amp;nbsp;192.3.65.201:9092,192.3.65.202:9092,192.3.65.203:9092&amp;nbsp;--command-config&amp;nbsp;/tmp/security-client.properties&amp;nbsp;--topic&amp;nbsp;test1
Topic:&amp;nbsp;test1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PartitionCount:&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ReplicationFactor:&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Configs:&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Topic:&amp;nbsp;test1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Partition:&amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Leader:&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Replicas:&amp;nbsp;3,2,1&amp;nbsp;Isr:&amp;nbsp;3,1,2

--向topic生成数据
#&amp;nbsp;bin/kafka-console-producer.sh&amp;nbsp;&amp;nbsp;--bootstrap-server&amp;nbsp;192.3.65.201:9092,192.3.65.202:9092,192.3.65.203:9092&amp;nbsp;--topic&amp;nbsp;test1&amp;nbsp;--producer-property&amp;nbsp;security.protocol=SASL_PLAINTEXT&amp;nbsp;--producer-property&amp;nbsp;sasl.mechanism=PLAIN&amp;nbsp;
&amp;gt;abc
&amp;gt;xyz
&amp;gt;this&amp;nbsp;is&amp;nbsp;test

#&amp;nbsp;bin/kafka-console-consumer.sh&amp;nbsp;&amp;nbsp;--bootstrap-server&amp;nbsp;192.3.65.201:9092,192.3.65.202:9092,192.3.65.203:9092&amp;nbsp;--topic&amp;nbsp;test1&amp;nbsp;--consumer-property&amp;nbsp;security.protocol=SASL_PLAINTEXT&amp;nbsp;--consumer-property&amp;nbsp;sasl.mechanism=PLAIN&amp;nbsp;--from-beginning&amp;nbsp;
abc
xyz
this&amp;nbsp;is&amp;nbsp;test
&amp;gt;^C&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&quot;h_666793036_12&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;通过SASL/PLAIN认证连接&lt;/h3&gt;&lt;p data-pid=&quot;0Sw6xgIP&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;解释SASL/PLAIN认证的概念和工作原理 提供Kafka配置文件的修改示例，启用和配置SASL/PLAIN认证&lt;/p&gt;&lt;h2 id=&quot;h_666793036_13&quot; data-into-catalog-status=&quot;&quot; style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;总结&lt;/h2&gt;&lt;p data-pid=&quot;Jx2caZDW&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;通过本文的实验和操作指导，我们成功搭建了一个具有SASL认证机制的Apache Kafka集群环境。我们首先安装了Java、Zookeeper和Kafka，然后配置了SASL认证，并进行了客户端和服务器的连接认证。在此过程中，我们深入理解了Kafka集群的安装和认证机制，并且获取了一些实践经验和注意事项。&lt;/p&gt;&lt;blockquote data-pid=&quot;5OCW_TdZ&quot; style=&quot;border-left: 3px solid rgb(196, 199, 206); color: rgb(83, 88, 97); margin: 1.4em 0px; padding-left: 1em; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;参考文档&lt;/blockquote&gt;&lt;ul style=&quot;margin-top: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;GUN SASL库：&lt;a href=&quot;https://link.zhihu.com/?target=https%3A//www.gnu.org/software/gsasl/&quot; class=&quot; external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;https://www.&lt;/span&gt;&lt;span class=&quot;visible&quot;&gt;gnu.org/software/gsasl/&lt;/span&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;An Introduction to Java SASL:&amp;nbsp;&lt;a href=&quot;https://link.zhihu.com/?target=https%3A//www.baeldung.com/java-sasl&quot; class=&quot; external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;https://www.&lt;/span&gt;&lt;span class=&quot;visible&quot;&gt;baeldung.com/java-sasl&lt;/span&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Apache Kafka官网：&lt;a href=&quot;https://link.zhihu.com/?target=http%3A//kafka.apache.org/&quot; class=&quot; external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;http://&lt;/span&gt;&lt;span class=&quot;visible&quot;&gt;kafka.apache.org/&lt;/span&gt;&lt;span class=&quot;invisible&quot; style=&quot;background-color: transparent; color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 0px; line-height: 0; font-family: a; text-shadow: none;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;ul style=&quot;list-style-type: square;&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://link.zhihu.com/?target=https%3A//kafka.apache.org/intro&quot; class=&quot; wrap external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;Apache Kafka 介绍&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://link.zhihu.com/?target=https%3A//kafka.apache.org/quickstart&quot; class=&quot; wrap external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;Apache Kafka 快速入门&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://link.zhihu.com/?target=https%3A//kafka.apache.org/documentation/&quot; class=&quot; wrap external&quot; target=&quot;_blank&quot; rel=&quot;nofollow noreferrer&quot; data-za-detail-view-id=&quot;1043&quot; style=&quot;text-decoration-line: none; border-bottom: 1px solid rgb(129, 133, 143); cursor: pointer;&quot;&gt;Apache Kafka 官方文档&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;background-color: #FFFFFF;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 29 Mar 2024 19:29:17 +0800</pubDate></item><item><title>Kafka的监听地址配置</title><link>http://mllib.cn/?id=12</link><description>&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;本文使用版本：Kafka 3.6.0&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;有时我们会碰到网络是通畅的，但却连不上Kafka，特别是在多网卡环境或者云环境上很容易出现。这个其实和Kafka的监听配置有关系。本文介绍监听相关的配置。目前监听相关的参数主要有下面几个：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;listeners
advertised.listeners
listener.security.protocol.map
inter.broker.listener.name
security.inter.broker.protocol
advertised.host.name&amp;nbsp;（历史遗留，已废弃，勿使用）
advertised.port&amp;nbsp;（历史遗留，已废弃，勿使用）
host.name&amp;nbsp;（历史遗留，已废弃，勿使用）&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: 0em;&quot;&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;其中最重要的就是 listeners 和 advertised.listeners ：集群启动时监听listeners配置的地址，并将 advertised.listeners 配置的地址写到Zookeeper里面，作为集群元数据的一部分。我们可以将客户端（生产者/消费者）连接Kafka集群进行操作的过程分成2步：&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: 0em;&quot;&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;通过 listeners 配置的连接信息（ip/host）连接到某个Broker（broker会定期获取并缓存zk中的元数据信息），获取元数据中 advertised.listeners 配置的地址信息。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: 0em;&quot;&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;通过第1步获取的 advertised.listeners 连接信息和Kafka集群通信（读/写）。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: 0em;&quot;&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;所以在存在内外网隔离的虚拟化环境中（比如Docker、公有云），外部客户端经常会出现可以连接到Kafka（第1步），但发送/消费数据时报连接超时（第2步），就是因为 listeners 配置的是外网地址，而 advertised.listeners 配置的却是内网地址。那这几个参数该如何配置呢？&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: 0em;&quot;&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: 2em;&quot;&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;先看连接信息的配置格式： {listener名字}://{HOST/IP}:{PORT} 。HOST/IP、PORT很清楚，主要是这个“ listener名字 ”字段。要理解这个得了解 listener.security.protocol.map 这个配置项：它的用途是配置listener名字和协议的映射（所以它是一个key-value的map），key是“listener名字”，value是“协议名称”，其默认值是“listener名字”和“协议名称”一样。有点绕，举个例子，比如：PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL，冒号前面是key，即协议名字；后面是value，即协议名称。listener名字我们可以随便起，而协议名称则是固定可枚举的一个范围。所以如果我们自定义了listener名字，那就需要显式的设置其对应的协议名。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;inter.broker.listener.name 和 security.inter.broker.protocol 都是用于配置Broker之间通信的，前者配置名称（即 listener.security.protocol.map 中的key），后者配置协议（即 listener.security.protocol.map 中的value），默认值是 PLAINTEXT 。这两个配置项同时只能配置一个。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;为什么一个连接要搞这么复杂呢？主要是为了各种不同的场景需求。下面举一个复杂一点的应用场景进行说明。比如我们在一个公有云上面部署了一个Kafka集群，该环境有一个外网地址 external_hostname 和一个内网地址 internal_hostname ；且在内部中是无法获取外网地址的（公有云大多都是这样的）。然后想实现内部客户端访问集群时走内部地址，且不需要加密；而外部客户端访问时则走外部地址，且需要加密。要实现这个需求，可以对集群进行如下配置：&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;listener.security.protocol.map=INTERNAL:,PLAINTEXT,EXTERNAL:SSL
listeners=INTERNAL://0.0.0.0:19092,EXTERNAL://0.0.0.0:9092
advertised.listeners=INTERNAL://{internal_hostname}:19092,EXTERNAL://{external_hostname}:9092
inter.broker.listener.name=INTERNAL&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;其实更进一步，我们还可以通过可选的control.plane.listener.name参数单独定制集群Controller节点与其他Broker节点的连接，那配置信息就变为：&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:SSL,CONTROL:SSL
listeners=INTERNAL://0.0.0.0:19092,EXTERNAL://0.0.0.0:9092
advertised.listeners=INTERNAL://{internal_hostname}:19092,EXTERNAL://{external_hostname}:9092,CONTROL://{control_ip}:9094
inter.broker.listener.name=INTERNAL
control.plane.listener.name=CONTROL&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;最后给出这些配置项的默认值和一些注意事项：&lt;/span&gt;&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: decimal;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;listeners 如果不显式的配置，那会监听所有网卡，相当于配置了0.0.0.0。该配置项里面listeners名字和端口都必须是唯一的，不能重复。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;advertised.listeners 如果不配置，默认使用 listeners 配置的值。如果 listeners 也没有显式配置，则使用 java.net.InetAddress.getCanonicalHostName() 获取的IP地址。 如果 listeners 配置的是0.0.0.0，则必须显式的配置 advertised.listeners ，因为这个配置项必须是一个具体的地址，不允许是0.0.0.0（因为客户端无法根据这个地址连接到Broker） 。另外，advertised.listeners 中的端口允许重复。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;对于 listeners 和 advertised.listeners ，有多个地址的时候，每一个地址都必须按照 {listener名字}://{HOST/IP}:{PORT} 格式进行配置，多个地址用英文逗号分隔。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果集群所有节点的hostname在客户端和服务端各节点之间可以正确解析，优先使用hostname，而不是IP。因为代码里面使用了 java.net.InetAddress.getCanonicalHostName() ，有时使用IP会出现访问不通的情况。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;总结： listeners 地址是用于首次连接的； advertised.listeners 的地址是会写到zk里面，客户端通过listeners地址建立连接获取该地址信息，然后通过该地址和集群交互。所以对于客户端，这2个地址必须都是可以访问的才可以。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 29 Mar 2024 14:24:29 +0800</pubDate></item><item><title>KAFAK 配置内外网分流，实现同时支持内网，外网访问kafka</title><link>http://mllib.cn/?id=11</link><description>&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这里的内网和外网并不必须是是我们通常说的公司内部网络和公网，只要是两块网卡都可以，不管是这两块网卡是公网、内网、甚至是k8s的虚拟网络两个网段的主要目的是实现分流，一个负责节点间通信，一个负责对外收发消息&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;总结一句话：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot; highlighted=&quot;true&quot; cnb-code-toolbar-active=&quot;true&quot; has-selection=&quot;true&quot; style=&quot;margin: 10px auto; padding: 0px; transition-duration: 0.2s; transition-property: background, font-size, border-color, border-radius, border-width, padding, margin, color; overflow: auto; position: relative; text-wrap: wrap; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;margin: 0px 3px; padding: 0px 5px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; line-height: 1.8; display: inline-block; overflow-x: auto; vertical-align: middle; border-radius: 3px; background-color: rgb(251, 229, 225); color: rgb(192, 52, 29);&quot;&gt;listeners&amp;nbsp;指明&amp;nbsp;kafka&amp;nbsp;当前节点监听本机的哪个网卡&lt;br/&gt;advertised.listeners&amp;nbsp;指明客户端通过哪个&amp;nbsp;ip&amp;nbsp;可以访问到当前节点&lt;/code&gt;&lt;br/&gt;&lt;/pre&gt;&lt;h2 id=&quot;1-kafka的两个配置listeners和advertisedlisteners&quot; style=&quot;margin: 20px 0px; padding: 0px; font-size: 21px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. kafka的两个配置listeners和advertised.listeners&lt;/h2&gt;&lt;h3 id=&quot;11-listeners&quot; style=&quot;margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.1 listeners:&lt;/h3&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;kafka监听的网卡的ip，假设你机器上有两张网卡，内网192.168.0.213和外网101.89.163.1&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;如下配置&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;&lt;code style=&quot;margin: 0px 3px; padding: 0px 5px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; line-height: 1.8; display: inline-block; overflow-x: auto; vertical-align: middle; border-radius: 3px; background-color: rgb(251, 229, 225); color: rgb(192, 52, 29);&quot;&gt;listeners=PLAINTEXT://192.168.0.213:9092&lt;/code&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;那么kafka只监听内网网卡，即只接收内网网卡的数据，如果如下配置：&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;&lt;code style=&quot;margin: 0px 3px; padding: 0px 5px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; line-height: 1.8; display: inline-block; overflow-x: auto; vertical-align: middle; border-radius: 3px; background-color: rgb(251, 229, 225); color: rgb(192, 52, 29);&quot;&gt;listeners=PLAINTEXT://101.89.163.1:9092&lt;/code&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;那么kafka只监听外网网卡，即只接收外网网卡的数据。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;当然ip可以配置成0.0.0.0，监听所有网卡。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;总结：&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;listeners 解决的是 kafka 监听来自于哪个网卡的请求。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;1.2 advertised.listeners&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;一般配置成这样：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;listeners=PLAINTEXT://192.168.0.213:9092
advertised.listeners=PLAINTEXT://101.89.163.1:9092&lt;/pre&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;配置过 zookeeper 的都知道， zookeeper 的配置文件中写明了所有 zookeeper 节点的 ip 地址，以便启动后节点之间的互相通信。我们观察 kafka 的配置文件 server.properties，会发现里面并没有记录其他 kafka 节点的地址，即各个节点都不知道其他节点的 ip 地址。那么 kafka 集群的各个节点之间是怎么通信的呢？&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;kafka 节点启动后，会向 zookeeper 注册自己，同时告诉 zookeeper 自身的通信地址，这个地址就是配置文件中的 advertised.listeners，如果没有配置 advertised.listeners，就会使用listeners。同时从 zookeeper 中获取兄弟节点的这个地址，以便与兄弟节点通信。即 kafka 节点是从 zookeeper 获取的其他节点的通信地址。&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;我们使用客户端以一个 ip 地址首次连接 kafka 节点后，节点返回给客户端的 kafka 集群地址就是从 zookeeper 中获得的这些地址，也就是各个节点配置的 advertised.listeners，包括当前连接的节点。所以可能客户端后续访问当前节点的 ip 地址有可能和首次连接的 ip 地址并不一样。&lt;/p&gt;&lt;h2 id=&quot;2-三种情景搭配使用这两个配置&quot; style=&quot;margin: 20px 0px; padding: 0px; font-size: 21px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 三种情景，搭配使用这两个配置&lt;/h2&gt;&lt;h3 id=&quot;21-只需要内网访问kafka&quot; style=&quot;margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.1. 只需要内网访问kafka&lt;/h3&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个很简单，只配置 listeners 并且使用内网 ip&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #C0341D; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; text-wrap: wrap; background-color: #FBE5E1;&quot;&gt;listeners=PLAINTEXT://192.168.0.213:9092&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;客户端访问 kafka 节点，以及与其他节点通信都用这个 ip 地址。&lt;/p&gt;&lt;h2 id=&quot;22-需要外网访问&quot; style=&quot;margin: 20px 0px; padding: 0px; font-size: 21px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.2 需要外网访问&lt;button class=&quot;cnblogs-toc-button&quot; title=&quot;显示目录导航&quot; aria-expanded=&quot;false&quot; style=&quot;margin: 0px 0px 0px 0.5rem; padding: 0px; font-size: inherit; opacity: 0.5; outline: none; appearance: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-width: 0px; border-style: initial; border-color: initial; cursor: pointer; user-select: none; vertical-align: middle; display: inline;&quot;&gt;&lt;/button&gt;&lt;/h2&gt;&lt;h3 id=&quot;221-机器有外网网卡&quot; style=&quot;margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.2.1 机器有外网网卡&lt;/h3&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;最简单的一个方法，只配置 listeners 并且使用外网 ip&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;margin: 0px 3px; padding: 0px 5px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; line-height: 1.8; display: inline-block; overflow-x: auto; vertical-align: middle; border-radius: 3px; background-color: rgb(251, 229, 225); color: rgb(192, 52, 29);&quot;&gt;listeners=PLAINTEXT://101.89.163.1:9092&lt;/code&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;所有请求都走外网网卡，虽然有问题（所有流量走外网），但是能够正常使用。&lt;/p&gt;&lt;h2 id=&quot;222-机器没有外网网卡&quot; style=&quot;margin: 20px 0px; padding: 0px; font-size: 21px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.2.2 机器没有外网网卡&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;如果机器是通过转发或者映射搞出来的外网ip（例如你访问腾讯新闻某个页面使用的 ip，这个 ip 和实际的网卡并不在为你提供首页内容的那台机器上），此时kafka无法监听这个外网ip，启动就会报错。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;需要配置一下 advertised.listeners，例如：&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #C0341D; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; text-wrap: wrap; background-color: #FBE5E1;&quot;&gt;&lt;span class=&quot;hljs-attr&quot; style=&quot;margin: 0px; padding: 0px; color: #FF0000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;listeners&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;=PLAINTEXT://&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;192.168&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;0.213&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;9092&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #C0341D; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; text-wrap: wrap; background-color: #FBE5E1;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot; style=&quot;margin: 0px; padding: 0px; color: #FF0000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;advertised.listeners&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;=PLAINTEXT://&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;101.89&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;163.1&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;9092&lt;/span&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #C0341D; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; text-wrap: wrap; background-color: #FBE5E1;&quot;&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;此时 kafka 客户端访问 kafka 集群的一个完整流程是：&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;客户端访问 101.89.163.1:9092，该请求被发送到 kafka 节点宿主机的内网地址 192.168.0.213:9092 上（也可以是其他 kafka 节点，效果是一样的），第一次请求成功，此次请求申请获得 kafka 集群的所有节点的地址。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;kafka 从 zookeeper 拿到自己和其他兄弟节点注册在 zookeeper 的 advertised.listeners，作为 kafka 集群各个节点的的服务 ip 返回给客户端。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;客户端拿这些返回的服务 ip 访问kafka集群，该请求从 实际拥有该 ip 的机器被转发到被具体 kafka 节点所在的内网ip，访问到了 kafka 节点，&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;当然有外网网卡时你也可以配置&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span class=&quot;hljs-attr&quot; style=&quot;margin: 0px; padding: 0px; color: #FF0000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;listeners&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;=PLAINTEXT://&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;101.89&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;163.1&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap; background-color: #F5F5F5;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; white-space: pre-wrap;&quot;&gt;9092&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;highlighter-hljs&quot; highlighted=&quot;true&quot; style=&quot;margin: 10px auto; padding: 0px; transition-duration: 0.2s; transition-property: background, font-size, border-color, border-radius, border-width, padding, margin, color; overflow: auto; text-wrap: wrap; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255);&quot;&gt;&lt;span class=&quot;hljs-attr&quot; style=&quot;margin: 0px; padding: 0px; color: #FF0000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px;&quot;&gt;advertised.listeners&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; background-color: #F5F5F5;&quot;&gt;=PLAINTEXT://&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px;&quot;&gt;101.89&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; background-color: #F5F5F5;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px;&quot;&gt;163.1&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px; background-color: #F5F5F5;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;margin: 0px; padding: 0px; color: #880000; font-family: &amp;quot;Courier New&amp;quot;, sans-serif; font-size: 12px;&quot;&gt;9092&lt;/span&gt;&lt;br/&gt;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;但是这毫无意义。&lt;/span&gt;&lt;/p&gt;&lt;h3 id=&quot;223-为什么客户端需要在第一次请求中获取-kafka-各个节点的服务-ip&quot; style=&quot;margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.2.3 为什么客户端需要在第一次请求中获取 kafka 各个节点的服务 ip&lt;/h3&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;因为你可以在启动客户端时只配置一个 kafka 节点的地址而不是列出所有节点（这样是不推荐的），但是客户端必须具有访问集群中的每一个节点的能力（收消息、发消息都可能面向所有节点）。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;对于 2.2 的情况，如果去掉&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;margin: 0px 3px; padding: 0px 5px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; line-height: 1.8; display: inline-block; overflow-x: auto; vertical-align: middle; border-radius: 3px; background-color: rgb(251, 229, 225); color: rgb(192, 52, 29);&quot;&gt;advertised.listeners=PLAINTEXT://101.89.163.1:9092&lt;/code&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;你会发现虽然你在启动 kafka 客户端时配置的访问地址是101.89.163.1:9092，但是 kafka 客户端启动时报错：&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;margin: 0px 3px; padding: 0px 5px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace, sans-serif; font-size: 12px; line-height: 1.8; display: inline-block; overflow-x: auto; vertical-align: middle; border-radius: 3px; background-color: rgb(251, 229, 225); color: rgb(192, 52, 29);&quot;&gt;Connection to node -1[192.168.0.213:9092] could not be established. Broker may not be available.&lt;/code&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;为什么明明配置的是101.89.163.1:9092启动时连接的是192.168.0.213？这就是因为不配置advertised.listeners 则使用listeners 代替并注册到zookeeper 中，客户端拿到的 kafka 节点 ip 就是listeners配置的内网 ip 192.168.0.213。&lt;/p&gt;&lt;h2 id=&quot;3-内外网分流&quot; style=&quot;margin: 20px 0px; padding: 0px; font-size: 21px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 内外网分流&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2中两种情况都有一个问题，所有请求包括 kafka 节点之间的通信都走的外网，这既不方便（外网访问的各种权限控制很麻烦），也不经济，更不安全。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;这时候就要配置内外网。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;配置1（针对没有实际的外网网卡，即2.2的情况）：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
listeners=INTERNAL://192.168.0.213:9092,EXTERNAL://192.168.0.213:19092
advertised.listeners=INTERNAL://192.168.0.213:9092,EXTERNAL://101.89.163.9:19092
inter.broker.listener.name=INTERNAL&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;配置2（针对有实际的外网网卡，即2.1的情况）：&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-go&quot;&gt;listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
listeners=INTERNAL://192.168.0.213:9092,EXTERNAL://101.89.163.9:19092
advertised.listeners=INTERNAL://192.168.0.213:9092,EXTERNAL://101.89.163.9:19092
inter.broker.listener.name=INTERNAL&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这两配置的区别是只有 listeners 的 EXTERNAL 使用的 ip 不一样，一个使用内网 ip ，一个使用外网 ip 。&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;对内网 INTERNAL 的配置就不说了，主要用于节点间通信，无论 listeners 还是 advertised.listeners 都配置成内网 ip，自然所有请求都走内网；主要是外网 EXTERNAL 配置：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;1）如果机器的外网&amp;nbsp;ip&amp;nbsp;是映射来的，listeners&amp;nbsp;的&amp;nbsp;EXTERNAL&amp;nbsp;使用内网ip，客户端拿到的是&amp;nbsp;advertised.listeners&amp;nbsp;配置的外网&amp;nbsp;ip，对于该外网&amp;nbsp;ip&amp;nbsp;的请求会被转发到对应的内网&amp;nbsp;ip，即访问到了对应的&amp;nbsp;kafka&amp;nbsp;节点，请求完成闭环。不要问怎么转发的，既然机器被映射了外网&amp;nbsp;ip，自然能够转发，有问题问网管
2）如果你的kafka宿主机有外网网卡，listeners&amp;nbsp;的EXTERNAL&amp;nbsp;使用用外网ip，客户端拿到的是&amp;nbsp;advertised.listeners&amp;nbsp;配置的外网&amp;nbsp;ip，直接就访问到了对应的&amp;nbsp;kafka&amp;nbsp;节点。&lt;/pre&gt;</description><pubDate>Wed, 27 Mar 2024 16:55:20 +0800</pubDate></item><item><title>clickhouse修改数据存储目录</title><link>http://mllib.cn/?id=10</link><description>&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;clickhouse默认数据目录是： /var/lib/clickhouse。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;修改方案：先停止数据库，然后转移该目录到指定位置，最后软连接回原地址并启动；即无需修改config.xml实现对数据目录的修改。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;1、停止数据库&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;service clickhouse-server stop&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;mkdir&amp;nbsp; /cc/soft/clickhouse&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;2、迁移数据目录&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;修改权限，否则没权限就启动不了&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;数据量太大，较慢，耐心等待。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;mv /var/lib/clickhouse/* /cc/soft/clickhouse/&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;chown -R clickhouse:clickhouse /cc/soft/clickhouse&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;3、建立软连接&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;ln -s /cc/soft/clickhouse&amp;nbsp; /var/lib/&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;#检查创建的软连接&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;ls -l /var/lib/&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;4、启动数据库-完成数据目录变更&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;第二种方式是在修改congfig配置文件&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;参考：&lt;a href=&quot;https://blog.csdn.net/Azj12345/article/details/128169866&quot;&gt;修改clickhouse的默认存储路径_clickhouse日志路径-CSDN博客&lt;/a&gt;&lt;/p&gt;</description><pubDate>Fri, 02 Feb 2024 19:20:53 +0800</pubDate></item><item><title>clickhouse创建角色和用户</title><link>http://mllib.cn/?id=9</link><description>&lt;p&gt;&lt;span style=&quot;color: #191B1F; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;clickhouse版本：22.2.2.1&lt;/span&gt;&lt;/p&gt;&lt;h2 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;更改default账户权限&lt;/h2&gt;&lt;p data-pid=&quot;-urtEYQG&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;ClickHouse提供了一个default账号，这个账号有所有的权限，但是不能使用SQL驱动方式的访问权限和账户管理。我们需要在配置文件中修改default账户，使其能够通过SQL驱动方式添加角色和用户。&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;默认default用户是没有办法创建用户的，这时候需要我们修改&lt;/span&gt;&lt;a href=&quot;https://so.csdn.net/so/search?q=%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6&amp;spm=1001.2101.3001.7020&quot; target=&quot;_blank&quot; class=&quot;hl hl-1&quot; data-report-click=&quot;{&amp;quot;spm&amp;quot;:&amp;quot;1001.2101.3001.7020&amp;quot;,&amp;quot;dest&amp;quot;:&amp;quot;https://so.csdn.net/so/search?q=%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6&amp;amp;spm=1001.2101.3001.7020&amp;quot;,&amp;quot;extra&amp;quot;:&amp;quot;{\&amp;quot;searchword\&amp;quot;:\&amp;quot;配置文件\&amp;quot;}&amp;quot;}&quot; data-tit=&quot;配置文件&quot; data-pretit=&quot;配置文件&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px 3px 0px 0px; padding: 0px 14px 0px 3px; text-decoration-line: none; cursor: pointer; background: url(&amp;quot;../img/iconHighlight.svg&amp;quot;) right top / 12px 14px no-repeat rgb(255, 255, 255); color: rgb(252, 85, 49); overflow-wrap: break-word; border-radius: 3px; box-shadow: none; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap;&quot;&gt;配置文件&lt;/a&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;users.xml，便能创建用户了,详见&lt;/span&gt;&lt;a href=&quot;https://clickhouse.com/docs/en/operations/access-rights#settings-profiles-management&quot; rel=&quot;nofollow&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; text-decoration-line: none; cursor: pointer; background-color: rgb(255, 255, 255); color: rgb(78, 161, 219); overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap;&quot;&gt;官网&lt;/a&gt;&lt;/p&gt;&lt;ol style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; counter-reset: ol 0; display: table; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;修改 /etc/clickhouse-server/users.xml 文件，在&amp;lt;users&amp;gt;:&amp;lt;default&amp;gt;标签中，将&amp;lt;access_management&amp;gt;&amp;lt;/access_management&amp;gt;中的值从0改成1。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;&amp;lt;networks&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;ip&amp;gt;::/0&amp;lt;/ip&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/networks&amp;gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;Settings&amp;nbsp;profile&amp;nbsp;for&amp;nbsp;user.&amp;nbsp;--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;profile&amp;gt;default&amp;lt;/profile&amp;gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;Quota&amp;nbsp;for&amp;nbsp;user.&amp;nbsp;--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;quota&amp;gt;default&amp;lt;/quota&amp;gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;User&amp;nbsp;can&amp;nbsp;create&amp;nbsp;other&amp;nbsp;users&amp;nbsp;and&amp;nbsp;grant&amp;nbsp;rights&amp;nbsp;to&amp;nbsp;them.&amp;nbsp;--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;access_management&amp;gt;1&amp;lt;/access_management&amp;gt;&amp;nbsp;#&amp;nbsp;该部分控制权限，把原本注释去掉就能建用户了
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;下面这几行也要加，不然授权all的时候会提示权限不足
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;named_collection_control&amp;gt;1&amp;lt;/named_collection_control&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;show_named_collections&amp;gt;1&amp;lt;/show_named_collections&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;show_named_collections_secrets&amp;gt;1&amp;lt;/show_named_collections_secrets&amp;gt;
&amp;lt;/default&amp;gt;
#&amp;nbsp;修改后需要重启clickhouse服务&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;O3yXbjYa&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 重启clickhouse-server&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;service&amp;nbsp;clickhouse-server&amp;nbsp;restart&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建管理员&lt;/h2&gt;&lt;p data-pid=&quot;3SUeKAmO&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建管理员账户，并为其分配所有权限。&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;CREATE&amp;nbsp;USER&amp;nbsp;IF&amp;nbsp;NOT&amp;nbsp;EXISTS&amp;nbsp;admin&amp;nbsp;IDENTIFIED&amp;nbsp;WITH&amp;nbsp;sha256_password&amp;nbsp;BY&amp;nbsp;&amp;#39;password&amp;#39;GRANT&amp;nbsp;ALL&amp;nbsp;ON&amp;nbsp;*.*&amp;nbsp;TO&amp;nbsp;admin&amp;nbsp;WITH&amp;nbsp;GRANT&amp;nbsp;OPTION&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;登录管理员账户&lt;/h2&gt;&lt;p data-pid=&quot;NTg-EvGn&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;假设有一个数据库名为test。接下来，登录管理员账户，然后为test添加读写账户。&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;clickhouse-client&amp;nbsp;-u&amp;nbsp;admin&amp;nbsp;--password&amp;nbsp;password&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建普通角色&lt;/h2&gt;&lt;h3 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建只读角色&lt;/h3&gt;&lt;p data-pid=&quot;P3DAotHA&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;该角色只能读取test的数据。&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;CREATE&amp;nbsp;ROLE&amp;nbsp;ro
GRANT&amp;nbsp;SELECT&amp;nbsp;ON&amp;nbsp;test.*&amp;nbsp;TO&amp;nbsp;ro&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.1em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(1.90909em) 0px calc(1.27273em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建读写角色&lt;/h3&gt;&lt;p data-pid=&quot;cyAp5upo&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;该角色可以读写test的数据。&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;CREATE&amp;nbsp;ROLE&amp;nbsp;rw
GRANT&amp;nbsp;SELECT,&amp;nbsp;INSERT,&amp;nbsp;ALTER&amp;nbsp;UPDATE,&amp;nbsp;ALTER&amp;nbsp;DELETE&amp;nbsp;ON&amp;nbsp;test.*&amp;nbsp;TO&amp;nbsp;rw&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建普通账户&lt;/h2&gt;&lt;p data-pid=&quot;-6Pt73iB&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;我们分别创建账户reader和writer，然后把只读角色ro分配给reader，把读写角色分配给writer。这样，reader拥有只读权限，writer拥有读写权限。&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;CREATE&amp;nbsp;USER&amp;nbsp;IF&amp;nbsp;NOT&amp;nbsp;EXISTS&amp;nbsp;reader&amp;nbsp;IDENTIFIED&amp;nbsp;WITH&amp;nbsp;sha256_password&amp;nbsp;BY&amp;nbsp;&amp;#39;password&amp;#39;
GRANT&amp;nbsp;ro&amp;nbsp;TO&amp;nbsp;reader

CREATE&amp;nbsp;USER&amp;nbsp;IF&amp;nbsp;NOT&amp;nbsp;EXISTS&amp;nbsp;writer&amp;nbsp;IDENTIFIED&amp;nbsp;WITH&amp;nbsp;sha256_password&amp;nbsp;BY&amp;nbsp;&amp;#39;password&amp;#39;
GRANT&amp;nbsp;rw&amp;nbsp;TO&amp;nbsp;writer&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;参考资料：&lt;a href=&quot;https://www.ewbang.com/community/article/details/997884891.html&quot;&gt;ClickHouse中创建用户、数据库并进行权限分配-易微帮 (ewbang.com)&lt;/a&gt;&lt;/p&gt;</description><pubDate>Tue, 30 Jan 2024 10:16:39 +0800</pubDate></item><item><title>ClickHouse核心引擎MergeTree解读</title><link>http://mllib.cn/?id=8</link><description>&lt;p data-first-child=&quot;&quot; data-pid=&quot;yJPV5mmx&quot; style=&quot;margin-top: 0px; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;ClickHouse&lt;/span&gt;&amp;nbsp;是俄罗斯最大的搜索引擎Yandex在2016年开源的数据库管理系统（DBMS），主要用于联机分析处理（OLAP）。其采用了面向列的存储方式，性能远超传统面向行的DBMS，近几年受到广泛关注。&lt;/p&gt;&lt;p data-pid=&quot;liWWAmkv&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文将介绍&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;ClickHouse MergeTree系列表引擎&lt;/span&gt;的相关知识，并通过示例分析MergeTree存储引擎的数据存储结构。&lt;/p&gt;&lt;h2 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style;&quot;&gt;1 MergeTree表引擎简介&lt;/span&gt;&lt;/h2&gt;&lt;p data-pid=&quot;CQ5HAuVp&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MergeTree（合并树）系列表引擎是ClickHouse提供的最具特色的存储引擎。MergeTree引擎支持数据按主键、数据分区、数据副本以及数据采样等特性。官方提供了包括MergeTree、ReplacingMergeTree、SummingMergeTree、AggregatingMergeTree、CollapsingMergeTree、VersionedCollapsingMergeTree、GraphiteMergeTree等7种不同类型的MergeTree引擎的实现，以及与其相对应的支持数据副本的MergeTree引擎（Replicated*）。&lt;/p&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic2.zhimg.com/80/v2-db132f45192b5415ed031369e7908cf5_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;1490&quot; data-rawheight=&quot;418&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;1490&quot; data-original=&quot;https://pic2.zhimg.com/v2-db132f45192b5415ed031369e7908cf5_r.jpg&quot; data-actualsrc=&quot;https://pic2.zhimg.com/v2-db132f45192b5415ed031369e7908cf5_b.jpg&quot; data-original-token=&quot;v2-db132f45192b5415ed031369e7908cf5&quot; height=&quot;418&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;jQZyn01Z&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;首先来介绍一下&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;MergeTree核心引擎：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;ReplacingMergeTree：&lt;/span&gt;在后台数据合并期间，对具有相同排序键的数据进行去重操作。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;SummingMergeTree：&lt;/span&gt;当合并数据时，会把具有相同主键的记录合并为一条记录。根据聚合字段设置，该字段的值为聚合后的汇总值，非聚合字段使用第一条记录的值，聚合字段类型必须为数值类型。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;AggregatingMergeTree：&lt;/span&gt;在同一数据分区下，可以将具有相同主键的数据进行聚合。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;CollapsingMergeTree：&lt;/span&gt;在同一数据分区下，对具有相同主键的数据进行折叠合并。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;VersionedCollapsingMergeTree：&lt;/span&gt;基于CollapsingMergeTree引擎，增添了数据版本信息字段配置选项。在数据依据ORDER BY设置对数据进行排序的基础上，如果数据的版本信息列不在排序字段中，那么版本信息会被隐式的作为ORDER BY的最后一列从而影响数据排序。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;GraphiteMergeTree：&lt;/span&gt;用来存储时序数据库Graphites的数据。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p data-pid=&quot;zVUU2YWf&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;MergeTree是该系列引擎中最核心的引擎，其他引擎均以MergeTree为基础，并在数据合并过程中实现了不同的特性，从而构成了MergeTree表引擎家族。下面我们通过MergeTree来具体了解MergeTree表系列引擎。&lt;/p&gt;&lt;h2 style=&quot;font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-variant-position: inherit; font-stretch: inherit; font-size: 1.2em; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; margin: calc(2.33333em) 0px calc(1.16667em); clear: left; font-synthesis: style; color: rgb(25, 27, 31); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style;&quot;&gt;2 MergeTree引擎&lt;/span&gt;&lt;/h2&gt;&lt;p data-pid=&quot;jmbCOX31&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;2.1 表创建&lt;/span&gt;&lt;/p&gt;&lt;p data-pid=&quot;wnbL-lSq&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建MergeTree的DDL如下所示：&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;CREATE&amp;nbsp;TABLE&amp;nbsp;[IF&amp;nbsp;NOT&amp;nbsp;EXISTS]&amp;nbsp;[db.]table_name&amp;nbsp;[ON&amp;nbsp;CLUSTER&amp;nbsp;cluster]&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name1&amp;nbsp;[type1]&amp;nbsp;[DEFAULT|MATERIALIZED|ALIAS&amp;nbsp;expr1]&amp;nbsp;[TTL&amp;nbsp;expr1],&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name2&amp;nbsp;[type2]&amp;nbsp;[DEFAULT|MATERIALIZED|ALIAS&amp;nbsp;expr2]&amp;nbsp;[TTL&amp;nbsp;expr2],&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&amp;nbsp;)&amp;nbsp;ENGINE&amp;nbsp;=&amp;nbsp;MergeTree()
&amp;nbsp;&amp;nbsp;ORDER&amp;nbsp;BY&amp;nbsp;expr&amp;nbsp;
&amp;nbsp;&amp;nbsp;[PARTITION&amp;nbsp;BY&amp;nbsp;expr]&amp;nbsp;
&amp;nbsp;&amp;nbsp;[PRIMARY&amp;nbsp;KEY&amp;nbsp;expr]&amp;nbsp;
&amp;nbsp;&amp;nbsp;[SAMPLE&amp;nbsp;BY&amp;nbsp;expr]&amp;nbsp;
&amp;nbsp;&amp;nbsp;[TTL&amp;nbsp;expr&amp;nbsp;[DELETE|TO&amp;nbsp;DISK&amp;nbsp;&amp;#39;xxx&amp;#39;|TO&amp;nbsp;VOLUME&amp;nbsp;&amp;#39;xxx&amp;#39;],&amp;nbsp;...]&amp;nbsp;
&amp;nbsp;&amp;nbsp;[SETTINGS&amp;nbsp;name=value,&amp;nbsp;...&lt;/pre&gt;&lt;/div&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;Ej81EBVj&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这里说明一下MergeTree引擎的主要参数：&lt;/p&gt;&lt;p data-pid=&quot;V3yUf3R-&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;[必填选项]&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;ENGINE&lt;/span&gt;：引擎名字，MergeTree引擎无参数。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;ORDER BY&lt;/span&gt;：排序键，可以由一列或多列组成，决定了数据以何种方式进行排序，例如ORDER BY（CounterID, EventDate）。如果没有显示指定PRIMARY KEY，那么将使用ORDER BY作为PRIMARY KEY。通常只指定ORDER BY即可。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p data-pid=&quot;7B61VJuv&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;[选填选项]&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;PARTITION BY&lt;/span&gt;：分区键，指明表中的数据以何种规则进行分区。分区是在一个表中通过指定的规则划分而成的逻辑数据集。分区可以按任意标准进行，如按月、按日或按事件类型。为了减少需要操作的数据，每个分区都是分开存储的。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;PRIMARY KEY&lt;/span&gt;：主键，设置后会按照主键生成一级索引（primary.idx），数据会依据索引的设置进行排序，从而加速查询性能。默认情况下，PRIMARY KEY与ORDER BY设置相同，所以通常情况下直接使用ORDER BY设置来替代主键设置。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;SAMPLE BY&lt;/span&gt;：数据采样设置，如果显示配置了该选项，那么主键配置中也应该包括此配置。例如 ORDER BY CounterID / EventDate / intHash32（UserID）、SAMPLE BY intHash32（UserID）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;TTL&lt;/span&gt;：数据存活时间，可以为某一字段列或者一整张表设置TTL，设置中必须包含Date或DateTime字段类型。如果设置在列上，那么会删除字段中过期的数据。如果设置的是表级的TTL，那么会删除表中过期的数据。如果设置了两种类型，那么按先到期的为准。例如，TTL createtime + INTERVAL 1 DAY，即一天后过期。使用场景包括定期删除数据，或者定期将数据进行归档。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;index_granularity&lt;/span&gt;：索引间隔粒度。MergeTree索引为稀疏索引，每index_granularity个数据产生一条索引。index_granularity默认设置为8092。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;enable_mixed_granularity_parts&lt;/span&gt;：是否启动index_granularity_bytes来控制索引粒度大小。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;index_granularity_bytes&lt;/span&gt;：索引粒度，以字节为单位，默认10Mb。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;merge_max_block_size&lt;/span&gt;：数据块合并最大记录个数，默认8192。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;merge_with_ttl_timeout&lt;/span&gt;：合并频率最小时间间隔，默认1天。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p data-pid=&quot;H13iyPij&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;2.2 数据存储结构&lt;/span&gt;&lt;/p&gt;&lt;p data-pid=&quot;C6wHN-82&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;首先创建一个test表，DDL如下:&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;CREATE&amp;nbsp;TABLE&amp;nbsp;test.test&amp;nbsp;
(&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UInt64,&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UInt8,&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;create_time&amp;nbsp;DateTime&amp;nbsp;
)&amp;nbsp;ENGINE&amp;nbsp;=&amp;nbsp;MergeTree()&amp;nbsp;
&amp;nbsp;&amp;nbsp;PARTITION&amp;nbsp;BY&amp;nbsp;toYYYYMMDD(create_time)&amp;nbsp;
&amp;nbsp;&amp;nbsp;ORDER&amp;nbsp;BY&amp;nbsp;(id)&amp;nbsp;
&amp;nbsp;&amp;nbsp;SETTINGS&amp;nbsp;index_granularity&amp;nbsp;=&amp;nbsp;4;&lt;/pre&gt;&lt;/div&gt;&lt;p data-pid=&quot;jtLOf7-O&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;test表包括id、type、create等三个字段，其中以create_time日期字段作为分区键，并将日期格式转化为YYYYMMDD。按照id字段进行排序。由于没有显式设置主键，所以引擎默认使用ORDER BY设置的id列作为索引字段，并生成索引文件。index_granularity设置为4，意味着每4条数据产生一条索引数据。&lt;/p&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;tMjS1JcZ&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;插入一条测试数据：&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(1,&amp;nbsp;1,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&lt;/pre&gt;&lt;/div&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;5k3AQZUg&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用如下命令查看test表分区相关信息：&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;&amp;nbsp;SELECT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;database,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;table,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;partition,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;partition_id,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;active,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;path&amp;nbsp;
&amp;nbsp;FROM&amp;nbsp;system.parts&amp;nbsp;
&amp;nbsp;WHERE&amp;nbsp;table&amp;nbsp;=&amp;nbsp;&amp;#39;test&amp;#39;&lt;/pre&gt;&lt;/div&gt;&lt;p data-pid=&quot;wQjCDiVg&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;返回结果如下图所示：&lt;/p&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic3.zhimg.com/80/v2-fc1cac973c60943ec866b79564b49f16_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;2134&quot; data-rawheight=&quot;536&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;2134&quot; data-original=&quot;https://pic3.zhimg.com/v2-fc1cac973c60943ec866b79564b49f16_r.jpg&quot; data-actualsrc=&quot;https://pic3.zhimg.com/v2-fc1cac973c60943ec866b79564b49f16_b.jpg&quot; data-original-token=&quot;v2-fc1cac973c60943ec866b79564b49f16&quot; height=&quot;536&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p data-pid=&quot;6WMdkNOi&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;从上图中可以看到test表中返回了一条partitionid为20210301的数据分区的记录，从name字段中我们可以得知，此分区的目录名为20210301_8_8_0。 20210301_8_8_0这个目录名字到底有什么含义呢？下面来介绍一下分区规则以及分区目录的命名规则。&lt;/p&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;dplAZ-5N&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;2.2.1 数据分区ID生成规则&lt;/span&gt;&lt;/p&gt;&lt;p data-pid=&quot;XmRbcr7J&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;数据分区规则由分区ID决定，分区ID由PARTITION BY分区键决定。根据分区键字段类型，ID生成规则可分为：&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;未定义分区键：&lt;/span&gt;没有定义PARTITION BY，默认生成一个目录名为all的数据分区，所有数据均存放在all目录下。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;整型分区键：&lt;/span&gt;分区键为整型，那么直接用该整型值的字符串形式做为分区ID。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;日期类分区键：&lt;/span&gt;分区键为日期类型，或者可以转化成日期类型。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;其他类型分区键：&lt;/span&gt;String、Float类型等，通过128位的Hash算法取其Hash值作为分区ID。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p data-pid=&quot;_C2DAdEF&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;上面我们插入一条日期为2021-03-01 00:00:00的数据，对该字段格式化后生成的数据分区id就是20210301。&lt;/p&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;9DWZwylQ&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;2.2.2 数据分区目录命名规则&lt;/span&gt;&lt;/p&gt;&lt;p data-pid=&quot;W3ah9wuE&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;目录命名规则如下：&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;PartitionId_MinBlockNum_MaxBlockNum_Level&lt;/pre&gt;&lt;/div&gt;&lt;ul style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; padding: 0px; width: 690px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;PartitionID：&lt;/span&gt;分区id，例如20210301。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;MinBlockNum：&lt;/span&gt;最小分区块编号，自增类型，从1开始向上递增。每产生一个新的目录分区就向上递增一个数字。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;MaxBlockNum：&lt;/span&gt;最大分区块编号，新创建的分区MinBlockNum等于MaxBlockNum的编号。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;Level：&lt;/span&gt;合并的层级，被合并的次数。合并次数越多，层级值越大。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic3.zhimg.com/80/v2-046ef0a4874fd46255ed79f20522a47e_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;776&quot; data-rawheight=&quot;614&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;776&quot; data-original=&quot;https://pic3.zhimg.com/v2-046ef0a4874fd46255ed79f20522a47e_r.jpg&quot; data-actualsrc=&quot;https://pic3.zhimg.com/v2-046ef0a4874fd46255ed79f20522a47e_b.jpg&quot; data-original-token=&quot;v2-046ef0a4874fd46255ed79f20522a47e&quot; height=&quot;614&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p data-pid=&quot;6H49wKTx&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;从上图可知，此分区的分区id为20210301，当前分区的MinBlockNum和MinBlockNum均为8，而level为0，表示此分区没有合并过。&lt;/p&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;tNdu8Lz1&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;2.3 数据分区文件组织结构&lt;/span&gt;&lt;/p&gt;&lt;p data-pid=&quot;r3kN5XUK&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在了解了分区目录名字的生成规则后，下面来看看数据分区目录下的文件组织结构。以2021030188_0分区为例：&lt;/p&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic1.zhimg.com/80/v2-bccb6c9e3bbae2f9f679a82fd8fb0e98_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;432&quot; data-rawheight=&quot;520&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;432&quot; data-original=&quot;https://pic1.zhimg.com/v2-bccb6c9e3bbae2f9f679a82fd8fb0e98_r.jpg&quot; data-actualsrc=&quot;https://pic1.zhimg.com/v2-bccb6c9e3bbae2f9f679a82fd8fb0e98_b.jpg&quot; data-original-token=&quot;v2-bccb6c9e3bbae2f9f679a82fd8fb0e98&quot; height=&quot;520&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p data-pid=&quot;8-14czO0&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;从图中可以看到，目录中的文件主要包括bin文件、mrk文件、primary.idx文件以及其他相关文件。&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;bin文件：&lt;/span&gt;数据文件，存储的是某一列的数据。数据表中的每一列都对应一个与其字段名相同的bin文件，例如id.bin存储的是表test中id列的数据。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;mrk文件：&lt;/span&gt;标记文件，每一列都对应一个与其字段名相同的标记文件，标记文件在idx索引文件和bin数据文件之间起到了桥梁作用。以mrk2结尾的文件，表示该表启用了自适应索引间隔。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;primary.idx文件：&lt;/span&gt;主键索引文件，用于加快查询效率。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;count.txt：&lt;/span&gt;数据分区中数据总记录数。上述20210301_8_8_0的数据分区中，该文件中的记录总数为1。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;columns.txt：&lt;/span&gt;表中所有列数的信息，包括字段名和字段类型。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;partion.dat：&lt;/span&gt;用于保存分区表达式的值。上述20210301_8_8_0的数据分区中该文件中的值为20210301。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;minmax_create_time.idx：&lt;/span&gt;分区键的最大最小值。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;checksums.txt：&lt;/span&gt;校验文件，用于校验各个文件的正确性。存放各个文件的size以及hash值。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;TtksNPMV&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;2.3.1 数据文件&lt;/span&gt;&lt;/p&gt;&lt;p data-pid=&quot;e19YO7wY&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;MergeTree中，每列都对应一个bin文件单独存放该列数据。例如，id.bin存放的是id列的数据。所有数据都经过数据压缩、排序，最后以数据块的形式写入bin文件中。bin中数据以压缩数据块为单位写入文件中。每个数据块由头信息和压缩数据组成。头部信息包括校验和、数据压缩算法、数据压缩前大小和压缩后大小组成。压缩数据由granule组成，granule大小与index_granularity相关。&lt;/p&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;WnJYL6yw&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;2.3.2 索引文件&lt;/span&gt;&lt;/p&gt;&lt;p data-pid=&quot;yr-SbJxa&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;MergeTree索引为稀疏索引，它并不索引单条数据，而是索引一定范围的数据。也就是从已排序的全量数据中，间隔性的选取一些数据记录主键字段的值来生成primary.idx索引文件，从而加快表查询效率。间隔设置参数为index_granularity。&lt;/p&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic1.zhimg.com/80/v2-ceb6281679b817bea7958a531eb9d054_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;580&quot; data-rawheight=&quot;210&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;580&quot; data-original=&quot;https://pic1.zhimg.com/v2-ceb6281679b817bea7958a531eb9d054_r.jpg&quot; data-actualsrc=&quot;https://pic1.zhimg.com/v2-ceb6281679b817bea7958a531eb9d054_b.jpg&quot; data-original-token=&quot;v2-ceb6281679b817bea7958a531eb9d054&quot; height=&quot;210&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p data-pid=&quot;gN0ql6Fy&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;我们向表test中插入9条数据，&lt;/p&gt;&lt;div class=&quot;highlight&quot; style=&quot;margin: 1em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre style=&quot;margin-top: 0px; margin-bottom: 0px; overflow-wrap: initial; background-color: rgb(248, 248, 250); border-radius: 4px; font-size: 0.9em; overflow: auto; padding: calc(0.888889em); word-break: initial;&quot;&gt;insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(1,&amp;nbsp;1,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(1,&amp;nbsp;2,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(1,&amp;nbsp;3,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(2,&amp;nbsp;1,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(2,&amp;nbsp;1,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(3,&amp;nbsp;1,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(3,&amp;nbsp;1,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(4,&amp;nbsp;1,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;test.test(id,&amp;nbsp;type,&amp;nbsp;create_time)&amp;nbsp;VALUES&amp;nbsp;(5,&amp;nbsp;1,&amp;nbsp;toDateTime(&amp;#39;2021-03-01&amp;nbsp;00:00:00&amp;#39;));&lt;/pre&gt;&lt;/div&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;KBjb5a_Y&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;因为index_granularity设置为4，所以每4条数据就会生成一条索引记录，即使用插入的第1、5、9条数据id字段的值生成索引文件记录。&lt;/p&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic1.zhimg.com/80/v2-d451e77bce4761b3206d93149e461c68_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;472&quot; data-rawheight=&quot;398&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;472&quot; data-original=&quot;https://pic1.zhimg.com/v2-d451e77bce4761b3206d93149e461c68_r.jpg&quot; data-actualsrc=&quot;https://pic1.zhimg.com/v2-d451e77bce4761b3206d93149e461c68_b.jpg&quot; data-original-token=&quot;v2-d451e77bce4761b3206d93149e461c68&quot; height=&quot;398&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p data-pid=&quot;vyb5Sr3j&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;2.3.3 标记文件&lt;/span&gt;&lt;/p&gt;&lt;p data-pid=&quot;nnnszz41&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;mrk标记文件在primary.idx索引文件和bin数据文件之间起到了桥梁作用。primary.idx文件中的每条索引在mrk文件中都有对应的一条记录。一条记录的组成包括：&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;offset-compressed bin file：&lt;/span&gt;表示指向的压缩数据块在bin文件中的偏移量。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;offset-decompressed data block：&lt;/span&gt;表示指向的数据在解压数据块中的偏移量。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-synthesis: style; font-weight: 600;&quot;&gt;row counts：&lt;/span&gt;代表数据记录行数，小于等于index_granularity所设置的值。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic3.zhimg.com/80/v2-7a0e46bf1e985e30716978e9c7eaa24a_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;1216&quot; data-rawheight=&quot;138&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;1216&quot; data-original=&quot;https://pic3.zhimg.com/v2-7a0e46bf1e985e30716978e9c7eaa24a_r.jpg&quot; data-actualsrc=&quot;https://pic3.zhimg.com/v2-7a0e46bf1e985e30716978e9c7eaa24a_b.jpg&quot; data-original-token=&quot;v2-7a0e46bf1e985e30716978e9c7eaa24a&quot; height=&quot;138&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p class=&quot;ztext-empty-paragraph&quot; style=&quot;margin-top: -0.8em; margin-bottom: -0.8em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p data-pid=&quot;Mf-vS-MB&quot; style=&quot;margin-top: 1.4em; margin-bottom: 1.4em; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;索引，标记和数据文件下图所示：&lt;/p&gt;&lt;p&gt;&lt;figure data-size=&quot;normal&quot; style=&quot;margin: 1.4em 0px; color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Source Han Sans SC&amp;quot;, &amp;quot;Noto Sans CJK SC&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: medium; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://pic1.zhimg.com/80/v2-3b83d66563d9f1d415927957deaca650_720w.webp&quot; data-caption=&quot;&quot; data-size=&quot;normal&quot; data-rawwidth=&quot;1374&quot; data-rawheight=&quot;532&quot; class=&quot;origin_image zh-lightbox-thumb lazy&quot; width=&quot;1374&quot; data-original=&quot;https://pic1.zhimg.com/v2-3b83d66563d9f1d415927957deaca650_r.jpg&quot; data-actualsrc=&quot;https://pic1.zhimg.com/v2-3b83d66563d9f1d415927957deaca650_b.jpg&quot; data-original-token=&quot;v2-3b83d66563d9f1d415927957deaca650&quot; height=&quot;532&quot; data-lazy-status=&quot;ok&quot; style=&quot;display: block; margin: 0px auto; max-width: 100%; height: auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running animation-1yvu044; width: 690px;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 11 Jan 2024 21:58:51 +0800</pubDate></item><item><title>clickhouse通过jdbc实现批量数据导入代码示例</title><link>http://mllib.cn/?id=7</link><description>&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;通过mybatis也可以实现批量写入clickhouse，但是效率太低，每秒大概只能写入300条数据，对于动辄上千万的数据或者更多数据，效率就太低了。而采用jdbc驱动的方式进行批量写入，每秒大约写入数据量达到10000条，效率得到大幅度的提升，只是这种方式，需要编写的代码会更多，需要处理的细节也更多。&lt;/p&gt;&lt;h4 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 18px; color: rgb(79, 79, 79); line-height: 26px; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 添加依赖&lt;/h4&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;&amp;lt;!--clickhouse--&amp;gt;
&amp;lt;dependency&amp;gt;
&amp;lt;groupId&amp;gt;com.clickhouse&amp;lt;/groupId&amp;gt;
&amp;lt;artifactId&amp;gt;clickhouse-jdbc&amp;lt;/artifactId&amp;gt;
&amp;lt;version&amp;gt;0.3.2-patch8&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;&lt;/pre&gt;&lt;h4 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 18px; color: rgb(79, 79, 79); line-height: 26px; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 获取连接&lt;/h4&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;public&amp;nbsp;Connection&amp;nbsp;getClickHouseConnection(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
	String&amp;nbsp;url&amp;nbsp;=&amp;nbsp;&amp;quot;jdbc:clickhouse://192.168.17.81:8123/default&amp;quot;;
&amp;nbsp;
	Properties&amp;nbsp;props&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Properties();
	props.setProperty(&amp;quot;user&amp;quot;,&amp;nbsp;username);
	props.setProperty(&amp;quot;password&amp;quot;,&amp;nbsp;&amp;quot;123456&amp;quot;);	
&amp;nbsp;
	try&amp;nbsp;{
		
		ClickHouseDataSource&amp;nbsp;dataSource&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ClickHouseDataSource(url,&amp;nbsp;props);
		Connection&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;dataSource.getConnection();
		return&amp;nbsp;conn;
	}catch&amp;nbsp;(Exception&amp;nbsp;e)
	{
		e.printStackTrace();
	}
&amp;nbsp;
	return&amp;nbsp;null;	
}
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
//&amp;nbsp;关闭连接
public&amp;nbsp;void&amp;nbsp;closeClickHouseConnection(Connection&amp;nbsp;connection)
{
	if&amp;nbsp;(connection&amp;nbsp;!=&amp;nbsp;null)&amp;nbsp;{
		try&amp;nbsp;{
			connection.close();
		}&amp;nbsp;catch&amp;nbsp;(SQLException&amp;nbsp;e)&amp;nbsp;{
			//ignore
		}
	}
}&lt;/pre&gt;&lt;h4 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 18px; color: rgb(79, 79, 79); line-height: 26px; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 准备预编译sql&lt;/h4&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;private&amp;nbsp;String&amp;nbsp;buildBatchSql()
{
	String&amp;nbsp;baseSql&amp;nbsp;=&amp;nbsp;&amp;quot;INSERT&amp;nbsp;INTO&amp;nbsp;plat_data_center_bill(bill_id,&amp;nbsp;bank_merchno,&amp;nbsp;bank_sub_merchno,&amp;nbsp;...)&amp;nbsp;&amp;quot;;
	baseSql&amp;nbsp;=&amp;nbsp;baseSql&amp;nbsp;+&amp;nbsp;&amp;quot;VALUES(&amp;quot;;
&amp;nbsp;
	baseSql&amp;nbsp;=&amp;nbsp;baseSql&amp;nbsp;+&amp;nbsp;&amp;quot;?,?,?,?,?,?,?,?,?,?&amp;quot;;
	baseSql&amp;nbsp;=&amp;nbsp;baseSql&amp;nbsp;+&amp;nbsp;&amp;quot;,?,?,?,?,?,?,?,?,?,?&amp;quot;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;
	baseSql&amp;nbsp;=&amp;nbsp;baseSql&amp;nbsp;+&amp;nbsp;&amp;quot;)&amp;quot;;
&amp;nbsp;
	return&amp;nbsp;baseSql;
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #4F4F4F; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; font-size: 16px; text-wrap: wrap; background-color: #EEF0F4;&quot;&gt;注意这里的字段对应的值采用问号替换，一个字段就是一个问号。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 18px; color: rgb(79, 79, 79); line-height: 26px; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. 批量写入数据&lt;/h4&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;private&amp;nbsp;void&amp;nbsp;batchInsertClickHouse(Connection&amp;nbsp;connection,&amp;nbsp;List&amp;lt;PlatDataCenterBill&amp;gt;&amp;nbsp;dataList)
{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
	String&amp;nbsp;batchSql&amp;nbsp;=&amp;nbsp;buildBatchSql();
&amp;nbsp;
	PreparedStatement&amp;nbsp;prepareStatement&amp;nbsp;=&amp;nbsp;null;
	try&amp;nbsp;{
		&amp;nbsp;connection.setAutoCommit(true);
		//&amp;nbsp;执行conn.setAutoCommit(false);会报Transactions&amp;nbsp;are&amp;nbsp;not&amp;nbsp;supported异常
		//&amp;nbsp;所以不能执行conn.commit();
		//&amp;nbsp;只能执行pst.executeBatch();由clickhouse进行后台提交。测试时插入数据条数是正确的
		prepareStatement&amp;nbsp;=&amp;nbsp;connection.prepareStatement(batchSql);
		for&amp;nbsp;(PlatDataCenterBill&amp;nbsp;bill&amp;nbsp;:&amp;nbsp;dataList)&amp;nbsp;{
			prepareStatement.setLong(1,&amp;nbsp;bill.getBillId());
&amp;nbsp;
			setPrepareString(prepareStatement,&amp;nbsp;2,&amp;nbsp;bill.getBankMerchno());
&amp;nbsp;
			setPrepareString(prepareStatement,2,&amp;nbsp;bill.getBankMerchno());
			setPrepareString(prepareStatement,3,&amp;nbsp;bill.getBankSubMerchno());
			setPrepareString(prepareStatement,4,&amp;nbsp;bill.getBankMerchname());
			prepareStatement.setObject(5,&amp;nbsp;bill.getBankDeptid());
&amp;nbsp;
			setPrepareString(prepareStatement,6,&amp;nbsp;bill.getBankDeptances());
			setPrepareString(prepareStatement,7,&amp;nbsp;bill.getBankDeptname());
			setPrepareString(prepareStatement,8,&amp;nbsp;bill.getAppId());
			setPrepareString(prepareStatement,9,&amp;nbsp;bill.getExternalMerchno());
			setPrepareString(prepareStatement,10,&amp;nbsp;bill.getExternalMerchname());
&amp;nbsp;
			...		
&amp;nbsp;
			prepareStatement.addBatch();
		}
		prepareStatement.executeBatch();
		prepareStatement.clearBatch();
		
	}&amp;nbsp;catch&amp;nbsp;(Exception&amp;nbsp;e)&amp;nbsp;{
		e.printStackTrace();
		throw&amp;nbsp;new&amp;nbsp;ServiceException(&amp;quot;批量写入异常&amp;quot;);
	}&amp;nbsp;finally&amp;nbsp;{
		if&amp;nbsp;(prepareStatement&amp;nbsp;!=&amp;nbsp;null)&amp;nbsp;{
			try&amp;nbsp;{
				prepareStatement.close();
			}&amp;nbsp;catch&amp;nbsp;(SQLException&amp;nbsp;e)&amp;nbsp;{
				//ignore
			}
		}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;
	}
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #4F4F4F; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; font-size: 16px; text-wrap: wrap; background-color: #EEF0F4;&quot;&gt;这里需要注意的是需要对每个字段的值进行设置，即使字段值为空值，也需要设置，另外还需要注意，日期时间类型，需要使用Timestamp进行设置。&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;prepareStatement.setObject(48,&amp;nbsp;new&amp;nbsp;Timestamp(sqlCreateTime.getTime()));&lt;/pre&gt;&lt;h4 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 18px; color: rgb(79, 79, 79); line-height: 26px; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;5. 为了判断空值，使用统一的方法&lt;/h4&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;public&amp;nbsp;void&amp;nbsp;setPrepareString(PreparedStatement&amp;nbsp;pst,&amp;nbsp;int&amp;nbsp;idx,&amp;nbsp;String&amp;nbsp;value)&amp;nbsp;throws&amp;nbsp;SQLException&amp;nbsp;{
&amp;nbsp;
	if(value&amp;nbsp;!=&amp;nbsp;null)&amp;nbsp;{
		pst.setString(idx,&amp;nbsp;value);
	}
	else&amp;nbsp;&amp;nbsp;{
		pst.setString(idx,&amp;nbsp;&amp;quot;&amp;quot;);
	}
}&lt;/pre&gt;&lt;h4 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 18px; color: rgb(79, 79, 79); line-height: 26px; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;6. 相关的依赖&lt;/h4&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;import&amp;nbsp;com.clickhouse.jdbc.ClickHouseDataSource;
&amp;nbsp;
import&amp;nbsp;org.slf4j.Logger;
import&amp;nbsp;org.slf4j.LoggerFactory;
import&amp;nbsp;org.springframework.beans.factory.annotation.Autowired;
import&amp;nbsp;org.springframework.beans.factory.annotation.Qualifier;
import&amp;nbsp;org.springframework.beans.factory.annotation.Value;
import&amp;nbsp;org.springframework.stereotype.Component;
&amp;nbsp;
import&amp;nbsp;javax.sql.DataSource;
import&amp;nbsp;java.math.BigDecimal;
import&amp;nbsp;java.sql.Connection;
import&amp;nbsp;java.sql.PreparedStatement;
import&amp;nbsp;java.sql.SQLException;
import&amp;nbsp;java.sql.Timestamp;
import&amp;nbsp;java.sql.Types;
import&amp;nbsp;java.util.ArrayList;
import&amp;nbsp;java.util.Date;
import&amp;nbsp;java.util.HashMap;
import&amp;nbsp;java.util.List;
import&amp;nbsp;java.util.Map;
import&amp;nbsp;java.util.Properties;&lt;/pre&gt;&lt;h4 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 18px; color: rgb(79, 79, 79); line-height: 26px; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;7. 循环批量写数据&lt;/h4&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;Connection&amp;nbsp;connection&amp;nbsp;=&amp;nbsp;getClickHouseConnection();
&amp;nbsp;
&amp;nbsp;
List&amp;lt;PlatDataCenterBill&amp;gt;&amp;nbsp;platBills&amp;nbsp;=&amp;nbsp;pdcBillService.selectPlatDataCenterBillList(pdcbill);
&amp;nbsp;
int&amp;nbsp;iCount&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;
ArrayList&amp;lt;PlatDataCenterBill&amp;gt;&amp;nbsp;billList&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ArrayList&amp;lt;PlatDataCenterBill&amp;gt;();
&amp;nbsp;
for(PlatDataCenterBill&amp;nbsp;bill&amp;nbsp;:&amp;nbsp;platBills)
{
	billList.add(bill);
	iCount&amp;nbsp;=&amp;nbsp;iCount&amp;nbsp;+&amp;nbsp;1;
&amp;nbsp;
	if(iCount&amp;nbsp;%&amp;nbsp;10000&amp;nbsp;==&amp;nbsp;0)
	{		
		System.out.println(billList.size());
		batchInsertClickHouse(connection,&amp;nbsp;billList);
&amp;nbsp;
		billList.clear();
	}
}
&amp;nbsp;
//&amp;nbsp;剩余部分数据批量写入
if(billList.size()&amp;nbsp;&amp;gt;&amp;nbsp;0)
{	
	batchInsertClickHouse(connection,&amp;nbsp;billList);
	billList.clear();
}
&amp;nbsp;
&amp;nbsp;
//&amp;nbsp;这里关闭连接才是正确的
closeClickHouseConnection(connection);&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; font-size: 16px; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;以上就是批量导入数据的大致处理过程。&lt;/span&gt;&lt;/p&gt;</description><pubDate>Tue, 09 Jan 2024 14:41:53 +0800</pubDate></item><item><title>Clickhouse MergeTree引擎配置说明</title><link>http://mllib.cn/?id=6</link><description>&lt;p&gt;&lt;span style=&quot;background-color: #FFFFFF; color: #4F4F4F; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 20px; font-variant-ligatures: no-common-ligatures;&quot;&gt;总结&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: decimal;&quot;&gt;&lt;li&gt;&lt;p&gt;分区目录可以不断被合并，最终可能被合并成一个目录&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;分区目录数据量最大可达150G&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;插入的数据只有落地到磁盘之后，客户端才能查询到数据&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;数据写入类似于kafka：支持同步，异步写入。支持最近数据插入去重校验&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;数据块合并之后，旧的数据块默认情况下会在480s之后 被删除&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;注意：&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: decimal;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;不活动的数据块：数据被合并后旧的数据块&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;活动的数据块：合并新生成 或 刚写入的 数据块&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;数据块就是：表数据目录下生成的存储数据的目录&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 20px; color: rgb(79, 79, 79); line-height: 30px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;配置说明&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 18px; color: rgb(79, 79, 79); line-height: 28px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a name=&quot;t2&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a id=&quot;max_parts_in_total_23&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;max_parts_in_total&lt;/h3&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;如果表的所有分区中的活动数据块总数超过&amp;nbsp;&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;max_parts_in_total&lt;/code&gt;，则插入操作将被中断并抛出“Too many parts (N)”异常。&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;可能的取值：&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;任何正整数。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;默认值为 100000。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;表中大量的数据块会降低 ClickHouse 查询的性能并增加 ClickHouse 的启动时间。&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;parts_to_throw_insert&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果单个分区中活动数据块数量超过parts_to_throw_insert值，则插入操作会因为Too many parts（N）而中断。与插入操作相比，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;合并操作的处理速度显著较慢。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值：300。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;为了实现SELECT查询的最大性能，需要尽量减少分区数据块的数量，请参见Merge Tree。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;您可以将值设置为更大，这将降低Too many parts错误的概率，但同时SELECT性能可能会下降。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;parts_to_delay_insert&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果单个分区中的活动数据块数量超过 parts_to_delay_insert，则插入操作会人为地减慢。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 150。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;ClickHouse 人为地延长了 INSERT 的执行时间（添加“sleep”），提升后天数据合并效率。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_delay_to_insert&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果单个分区中的活动数据块数量超过 parts_to_throw_insert，则此参数用于计算插入延迟的秒数值。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 1。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;INSERT 的延迟（以毫秒为单位）通过以下公式计算：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_k = parts_to_throw_insert - parts_to_delay_insert&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;k = 1 + parts_count_in_partition - parts_to_delay_insert&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;delay_milliseconds = pow(max_delay_to_insert * 1000, k / max_k)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;例如，如果一个分区有 299 个活动数据块，parts_to_throw_insert 为 300，parts_to_delay_insert 为 150，max_delay_to_insert 为 1，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;则插入将延迟 pow(1 * 1000, (1 + 299 - 150) / (300 - 150)) = 1000 毫秒。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;从版本 23.1 开始，公式已更改为：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;allowed_parts_over_threshold = parts_to_throw_insert - parts_to_delay_insert&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;parts_over_threshold = parts_count_in_partition - parts_to_delay_insert + 1&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;delay_milliseconds = max(min_delay_to_insert_ms, (max_delay_to_insert * 1000) * parts_over_threshold / allowed_parts_over_threshold)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;例如，如果一个分区有 224 个活动数据块，parts_to_throw_insert 为 300，parts_to_delay_insert 为 150，max_delay_to_insert 为 1，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;min_delay_to_insert_ms 为 10，则插入将延迟 max(10, 1 * 1000 * (224 - 150 + 1) / (300 - 150)) = 500 毫秒&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;inactive_parts_to_throw_insert&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果单个分区中的非活动数据块数量超过 inactive_parts_to_throw_insert，则插入操作将被中断并抛出“Too many inactive parts (N).&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Parts cleaning are processing significantly slower than inserts”异常。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 0（不限制）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;inactive_parts_to_delay_insert&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果表中单个分区中的非活动数据块数量至少达到 inactive_parts_to_delay_insert，则插入操作会人为地减慢。当服务器无法快速清理数据块时，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;这很有用。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 0（不限制）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;simultaneous_parts_removal_limit&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果存在大量过时的数据块，则清理线程将尝试在一次迭代中删除多达 simultaneous_parts_removal_limit 个数据块。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;将 simultaneous_parts_removal_limit 设置为 0 表示没有限制。&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_deduplication_window&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;写入副本表时 存储数据块哈希值以防止重复数据插入。由于网络抖动，客户端可能会发起两次数据插入，每次数据插入节点可能不一样，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;所以 ClickHouse 将数据块的哈希值写入 ClickHouse Keeper，用于副本节点之间共享数据块的哈希值&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0（禁用去重）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 100。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Insert 命令会创建一个或多个数据块（part）。写入副本表时会进行插入去重校验，ClickHouse 将所创建 数据块 的哈希值写入 ClickHouse Keeper。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;仅存储最近的 replicated_deduplication_window 个数据块的哈希值。旧的哈希值将从 ClickHouse Keeper 中删除。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果replicated_deduplication_window 设置过大，会减慢插入，因为需要比较更多的条目。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;哈希值是从插入数据的字段名称、类型和数据（字节流）通过hash计算而来的。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;non_replicated_deduplication_window&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;在非副本表的 MergeTree 表中，存储用于检查重复 插入数据块的哈希值 的个数&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0（禁用去重）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;使用与副本表类似的去重机制（参见 replicated_deduplication_window 设置）&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_deduplication_window_seconds&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;数据块的哈希值 从 ClickHouse Keeper 中删除的时间（以秒为单位）。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 604800（1 周）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;与 replicated_deduplication_window 类似，replicated_deduplication_window_seconds 指定存储插入去重的数据块的哈希值保留时长。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;超过 replicated_deduplication_window_seconds 的哈希值将从 ClickHouse Keeper 中删除，即使数量小于 replicated_deduplication_window。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果只有一条记录，则会永久存储。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_deduplication_window_for_async_inserts&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;类似配置：replicated_deduplication_window，该配置应用于异步数据插入并且 默认值为 10000。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_deduplication_window_seconds_for_async_inserts&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;类似配置：replicated_deduplication_window_seconds&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;use_async_block_ids_cache&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果为 true，则缓存异步插入数据块的哈希值，提升插入性能。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;true，false&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 false。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;一个包含多个异步插入将生成多个数据块的哈希值。这些哈希值存储在Keeper 上，如果开启这个缓存，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Clickhouse将监视 Keeper 中的存储该分区哈希值的路径。如果在 Keeper 中监视到更新，则尽快更新缓存，以便我们能够在内存中过滤重复的插入。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;async_block_ids_cache_min_update_interval_ms&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;更新数据块哈希值 的最小间隔（以毫秒为单位）。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 100。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;通常，只要监视 Keeper 路径中有更新，内存中的数据块哈希值就会立即更新。但是，缓存更新可能过于频繁并成为重负担。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;这个最小间隔可以防止缓存更新得太快。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_replicated_logs_to_keep&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;How many records may be in the ClickHouse Keeper log if there is inactive replica.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;An inactive replica becomes lost when when this number exceed.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Possible values:&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Any positive integer.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Default value: 1000&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;min_replicated_logs_to_keep&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;同上，这是最小值，默认值为：10&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;prefer_fetch_merged_part_time_threshold&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;在副本同步过程中，如果zk上同步日志创建时长大于prefer_fetch_merged_part_time_threshold，并且需要同步的数据大小总和大于&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp;prefer_fetch_merged_part_size_threshold，则优先从副本中拉取合并后的数据块，而不是拉取原始数据并在本地执行合并。这是为了加速数据合并。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 3600。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;prefer_fetch_merged_part_size_threshold&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;在副本同步过程中，如果zk上同步日志创建时长大于prefer_fetch_merged_part_time_threshold，并且需要同步的数据大小总和大于&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp;prefer_fetch_merged_part_size_threshold，则优先从副本中拉取合并后的数据块，而不是拉取原始数据并在本地执行合并。这是为了加速数据合并。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 10,737,418,240（10G）&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;execute_merges_on_single_replica_time_threshold&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;当此设置的值大于零时，则仅一个副本立即开始合并，其他副本等待execute_merges_on_single_replica_time_threshold秒后下载合并好的数据。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果所选副本在execute_merges_on_single_replica_time_threshold秒后未完成合并，则会回退到标准行为。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0（秒）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;remote_fs_execute_merges_on_single_replica_time_threshold&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;当此设置的值大于零时，如果合并数据块在共享存储上（比如s3上），并且启用了 allow_remote_fs_zero_copy_replication，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;则仅一个副本立即开始合并。其他的副本等待，超过该值还没有完成合并，则会回退到标准行为。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;allow_remote_fs_zero_copy_replication &lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;还处于实验阶段&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;ClickHouse 版本 22.8 及更高版本默认禁用。不建议在生产环境中使用此功能。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 10800。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;try_fetch_recompressed_part_timeout&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Recompression 是代表更换压缩方式 对数据进行压缩？？&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Recompression works slow in most cases, so we don’t start merge with recompression until this timeout and trying to&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;fetch recompressed part from replica which assigned this merge with recompression.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Possible values:&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Any positive integer.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Default value: 7200&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;always_fetch_merged_part&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;副本同步时，只拉取合并好的分区&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;true，false&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 false。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_suspicious_broken_parts&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;分区中最大的被损坏的数据块数量，如果超过此值，则停止自动删除。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 100。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_suspicious_broken_parts_bytes&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;分区中最大被损坏的数据块的数据总和大小，如果超过此值，则停止自动删除。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 1,073,741,824。（1G）&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_files_to_modify_in_alter_columns&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果要修改（删除、添加）的文件数量大于此设置，则取消ALTER操作。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为75。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_files_to_remove_in_alter_columns&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果在列删除时，需要删除的文件数量大于此设置，则取消ALTER操作。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为50。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_max_ratio_of_wrong_parts&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果被损坏的数据块占总数据块的数量的比例小于此值，则允许启动，反之就无法启动&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;浮点数，0.0 - 1.0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0.5。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_max_parallel_fetches_for_host&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;副本数据同步线程次大小&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为15。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_can_become_leader&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;标记节点是否参与主副本的竞争&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;true，false&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 true。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;zookeeper_session_expiration_check_period&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;ZooKeeper 会话过期检查周期，以秒为单位。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为60。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;detach_old_local_parts_when_cloning_replica&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;在修复丢失的副本时，不要删除旧的本地数据块。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;true，false&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 true。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_fetches_http_connection_timeout&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;拉取数据数据块请求的连接超时（以秒为单位）。如果未明确设置，则继承自默认配置文件的 http_connection_timeout。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 使用 http_connection_timeout 的值。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_fetches_http_send_timeout&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;拉取数据块的请求发送超时时间（以秒为单位。如果未明确设置，则继承自默认配置文件的 http_send_timeout。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 使用 http_send_timeout 的值。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;replicated_fetches_http_receive_timeout&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;拉取数据块的请求接收超时时间（以秒为单位）。如果未明确设置，则继承自默认配置文件的 http_receive_timeout。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 使用 http_receive_timeout 的值。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_replicated_fetches_network_bandwidth&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;限制副本同步过程中 数据拉取最大速度，以每秒字节数为单位。这个设置可以应用于特定的表，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_replicated_fetches_network_bandwidth_for_server用于控制Clickhouse server限制副本同步过程中 数据拉取最大速度，但是对于这个设置，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;表级别的值应该小于服务器级别的值。否则，服务器只考虑 max_replicated_fetches_network_bandwidth_for_server&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;这个设置不能完全精确地跟踪。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 无限制。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;用法&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可以用于在向新增或替换节点，复制数据时限制速度。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_replicated_sends_network_bandwidth&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;限制副本同步过程中 数据发送出去最大速度，以每秒字节数为单位。这个设置可以应用于特定的表，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_replicated_sends_network_bandwidth_for_server 用于控制Clickhouse server限制副本同步过程中 数据发送出去最大速度，但是对于这个设置，&lt;/span&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;表级别的值应该小于服务器级别的值。否则，服务器只考虑 max_replicated_sends_network_bandwidth_for_server&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;这个设置不能完全精确地跟踪。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 无限制。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;用法&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可以用于在向新增或替换节点，复制数据时限制速度。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;old_parts_lifetime&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;合并后产生的非活动数据块保留时长（以秒为单位）。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为：480。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;多个数据块合并为一个新数据块后，ClickHouse 将原始数据块标记为非活动状态，如果它们不被现有的查询引用，即数据块的引用计数为零，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;在 old_parts_lifetime 秒后会删除它们。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;对于新的数据块，不会调用 fsync，因此新的数据块在一段时间内仅存在于服务器的内存（操作系统缓存）中。如果服务器异常重启，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;新的数据块可能会丢失或损坏。为了保护数据，非活动数据块不会立即被删除。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;在启动期间，ClickHouse 会检查数据块的完整性。如果合并的数据块已损坏，则将原来非活动数据块放到活动列表中，并在以后再次合并它们。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;然后，将已损坏的数据块重命名（添加 broken_ 前缀）并移动到 detached 文件夹中。如果合并的数据块未损坏，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;则将原始非活动数据块重命名（添加 ignored_ 前缀）并移动到 detached 文件夹中。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认的 dirty_expire_centisecs 值（Linux 内核设置）为 30 秒（需要被写入磁盘数据存储在 内存 中的最长时间），&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;但在磁盘系统的负载高的情况下，数据可以写入得更晚。通过实验，选择了 old_parts_lifetime 的值为 480 秒，这样可以保证新数据块被写入磁盘&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_bytes_to_merge_at_max_space_in_pool&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果有足够的资源可用的情况下，合并为一个数据块的最大总数据块大小（以字节为单位），max_bytes_to_merge_at_max_space_in_pool&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;大致对应于自动后台合并后最大可能数据块大小。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为161061273600（150 GB）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;合并调度程序会定期分析分区中的数据块大小和数量，如果池中有足够的空闲资源，则启动后台合并。合并将持续进行，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;直到源数据块的总大小大于 max_bytes_to_merge_at_max_space_in_pool。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;由 OPTIMIZE FINAL 发起的合并会忽略 max_bytes_to_merge_at_max_space_in_pool，只考虑可用资源（空闲磁盘空间）进行合并，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;直到分区中只剩下一个数据块为止。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_bytes_to_merge_at_min_space_in_pool&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可用资源最少的情况， 合并为一个数据块的最小总数据块大小（以字节为单位）&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为1048576（1 MB）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_bytes_to_merge_at_min_space_in_pool 定义了即使缺少可用磁盘空间，也可以合并的数据块的最大总大小。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;这是为了减少小数据块的数量和“Too many parts”错误的几率。由于合并过程中会翻倍占用磁盘空间。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;因此，当可用磁盘空间很少时，可能会出现这样的情况：虽然有空闲空间，但该空间已经被正在进行的大型合并所占用，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;因此其他合并无法启动，并且随着大量的数据插入，小数据块的数量会不断增多。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;merge_max_block_size&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;合并过程中 每次从原始数据中读取的行数。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为8192。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;数据合并时，将从原始数据中以 merge_max_block_size 行作为一个段进行读取，然后将数据合并写入到新的数据块。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;读取的数据会被放置在 内存 中，因此 merge_max_block_size 影响合并所需的 内存 大小。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;因此，对于具有多列的表（如果平均行大小为100kb，则合并10个数据块时，（100kb * 10 * 8192）= ~8GB RAM），合并可能会消耗大量内存。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;通过减小 merge_max_block_size，可以减少合并所需的内存，但会减低合并操作性能。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;number_of_free_entries_in_pool_to_lower_max_size_of_merge&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;当池中（或复制队列中）的可用空闲条目少于number_of_free_entries_in_pool_to_lower_max_size_of_merge时，开始减少每次合并的数据量 ，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;减少合并线程占用太多时间&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为8。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;number_of_free_entries_in_pool_to_execute_mutation&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;当线程池中空闲数少于number_of_free_entries_in_pool_to_execute_mutation时，不再执行数据变更操作。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;这是为了留出空闲线程进行常规合并操作，避免出现“Too many parts”的错误。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为20。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;使用：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;number_of_free_entries_in_pool_to_execute_mutation&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp;设置的值应该小于 background_pool_size * background_merges_mutations_concurrency_ratio 的值。否则，ClickHouse 会抛出异常。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;min_age_to_force_merge_seconds&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Merge parts if every part in the range is older than the value of min_age_to_force_merge_seconds.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Possible values:&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Positive integer.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Default value: 0 — Disabled.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;min_age_to_force_merge_on_partition_only&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;参数 min_age_to_force_merge_seconds是否仅应用于整个分区，而不是应用子目录上（project 目录）。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;true，false&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 false。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_part_loading_threads&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;加载分区元数据的线程数，默认与机器cup数量相等，在启动期间，ClickHouse 会读取所有表数据块的元数据文件，以构建内存中数据块的列表。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果数据块比较多，这个过程可能需要很长时间，可以通过适当增加max_part_loading_threads来缩短这个启动时间。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为 auto（即 CPU 核心数）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_partitions_to_read&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;限制一次查询中可以访问的最大分区数。可以通过查询级别的设置来覆盖表创建时指定的设置值。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为-1（无限制）&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;allow_floating_point_partition_key&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;允许浮点数类型字段作为分区字段&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能值:&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 不允许使用浮点分区键。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;1 - 允许使用浮点分区键。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值: 0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;check_sample_column_is_correct&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Enables the check at table creation, that the data type of a column for sampling or sampling expression is correct.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;The data type must be one of unsigned integer types: UInt8, UInt16, UInt32, UInt64.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Possible values:&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;true — The check is enabled.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;false — The check is disabled at table creation.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Default value: true.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;By default, the ClickHouse server checks at table creation the data type of a column for sampling or sampling expression.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;If you already have tables with incorrect sampling expression and do not want the server to raise an exception during startup,&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;set check_sample_column_is_correct to false.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;min_bytes_to_rebalance_partition_over_jbod&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;每次写入某个磁盘阵列时，数据的最小值&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能取值为：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 禁用平衡。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;使用：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;min_bytes_to_rebalance_partition_over_jbod设置的值应该大于max_bytes_to_merge_at_max_space_in_pool/1024的值。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;否则，ClickHouse会抛出异常。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;detach_not_byte_identical_parts&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;副本之间数据同步完成后，发现数据与副本数据不一样，是把副本数据卸载掉，还是直接删掉这些数据&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 删除数据块。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;1 - 卸载数据块。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;merge_tree_clear_old_temporary_directories_interval_seconds&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;设置多长时间（单位：秒）清理无用临时目录&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为60秒。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;merge_tree_clear_old_parts_interval_seconds&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;设置多长时间（单位：秒）清理无用数据&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;任何正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为1秒。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;max_concurrent_queries&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;最大查询并发量，收到其他级别max_concurrent_queries的限制，比如整个集群查询最大并发量是100，表的最大查询并发量不能超过100&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;正整数。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 - 没有限制。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为0（没有限制）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;min_marks_to_honor_max_concurrent_queries&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;The minimal number of marks read by the query for applying the max_concurrent_queries setting.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Note that queries will still be limited by other max_concurrent_queries settings.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Possible values:&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Positive integer.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;0 — Disabled (max_concurrent_queries limit applied to no queries).&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;Default value: 0 (limit never applied).&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;ratio_of_defaults_for_sparse_serialization&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;列中默认值数量 与 所有值数量 之比 的最小值。设置该值主要是为了使用 稀疏序列化存储，提升查询效率。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果列是稀疏的（比如大部分行都是0），ClickHouse可以使用稀疏格式对其进行编码，在查询过程中 数据不需要进行完全解压缩 提升查询效率。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;要启用此 稀疏序列化 压缩特性，请将ratio_of_defaults_for_sparse_serialization设置为小于1.0的值。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果该值大于或等于1.0（默认值），则使用常规的方法序列化 列数据。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可能的取值：&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;介于0和1之间的小数，表示启用稀疏序列化特性。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;如果不想使用稀疏序列化，则设置为1.0或更大。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;默认值为1.0（表示禁用稀疏序列化特性）。&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;案例&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;以下表中的s列有95%的行为空字符串。在&lt;/span&gt;&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; text-wrap: wrap;&quot;&gt;my_regular_table&lt;/code&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;中，我们不使用稀疏序列化，在&lt;/span&gt;&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; text-wrap: wrap;&quot;&gt;my_sparse_table&lt;/code&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;中，我们将&lt;/span&gt;&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; text-wrap: wrap;&quot;&gt;ratio_of_defaults_for_sparse_serialization&lt;/code&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;设置为0.95&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;CREATE&amp;nbsp;TABLE&amp;nbsp;my_regular_table
(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;`id`&amp;nbsp;UInt64,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;`s`&amp;nbsp;String
)
ENGINE&amp;nbsp;=&amp;nbsp;MergeTree
ORDER&amp;nbsp;BY&amp;nbsp;id;

INSERT&amp;nbsp;INTO&amp;nbsp;my_regular_table
SELECT
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;number&amp;nbsp;AS&amp;nbsp;id,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;number&amp;nbsp;%&amp;nbsp;20&amp;nbsp;=&amp;nbsp;0&amp;nbsp;?&amp;nbsp;toString(number):&amp;nbsp;&amp;#39;&amp;#39;&amp;nbsp;AS&amp;nbsp;s
FROM
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numbers(10000000);


CREATE&amp;nbsp;TABLE&amp;nbsp;my_sparse_table
(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;`id`&amp;nbsp;UInt64,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;`s`&amp;nbsp;String
)
ENGINE&amp;nbsp;=&amp;nbsp;MergeTree
ORDER&amp;nbsp;BY&amp;nbsp;id
SETTINGS&amp;nbsp;ratio_of_defaults_for_sparse_serialization&amp;nbsp;=&amp;nbsp;0.95;

INSERT&amp;nbsp;INTO&amp;nbsp;my_sparse_table
SELECT
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;number,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;number&amp;nbsp;%&amp;nbsp;20&amp;nbsp;=&amp;nbsp;0&amp;nbsp;?&amp;nbsp;toString(number):&amp;nbsp;&amp;#39;&amp;#39;
FROM
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numbers(10000000);&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;您可以通过查看&lt;/span&gt;&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; text-wrap: wrap;&quot;&gt;system.parts_columns&lt;/code&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;表的&lt;/span&gt;&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; text-wrap: wrap;&quot;&gt;serialization_kind&lt;/code&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;列来验证列是否使用稀疏编码：&lt;/span&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;SELECT&amp;nbsp;column,&amp;nbsp;serialization_kind&amp;nbsp;FROM&amp;nbsp;system.parts_columns
WHERE&amp;nbsp;table&amp;nbsp;LIKE&amp;nbsp;&amp;#39;my_sparse_table&amp;#39;;
┌─column─┬─serialization_kind─┐
│&amp;nbsp;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│&amp;nbsp;Default&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│
│&amp;nbsp;s&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│&amp;nbsp;Default&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│
│&amp;nbsp;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│&amp;nbsp;Default&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│
│&amp;nbsp;s&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│&amp;nbsp;Sparse&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│
│&amp;nbsp;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│&amp;nbsp;Default&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│
│&amp;nbsp;s&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│&amp;nbsp;Sparse&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;│
└────────┴────────────────────┘&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;clean_deleted_rows&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;启用/禁用使用ReplacingMergeTree引擎的表上执行OPTIMIZE … FINAL时自动删除标记为is_deleted的行。当禁用时，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;必须在OPTIMIZE … FINAL中添加CLEANUP关键字才能获得相同的行为。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;可选的值&lt;/span&gt;&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: disc;&quot;&gt;&lt;li&gt;&lt;p&gt;Always 或者 Never&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;默认：Never&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong&gt;参考资料&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;https://clickhouse.com/docs/en/operations/settings/settings&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Wed, 27 Dec 2023 22:13:02 +0800</pubDate></item><item><title>Springboot集成ClickHouse</title><link>http://mllib.cn/?id=5</link><description>&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;1、clickhouse应⽤场景&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(244, 244, 244) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;1&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.绝大多数请求都是用于读访问的&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(255, 255, 255) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;2&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.数据需要以大批次（大于&lt;/code&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;1000&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;行）进行更新，而不是单行更新；或者根本没有更新操作&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(244, 244, 244) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;3&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.数据只是添加到数据库，没有必要修改&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number4 index3 alt1&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(255, 255, 255) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;4&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.读取数据时，会从数据库中提取出大量的行，但只用到一小部分列&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number5 index4 alt2&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(244, 244, 244) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;5&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.表很“宽”，即表中包含大量的列&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number6 index5 alt1&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(255, 255, 255) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;6&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.查询频率相对较低（通常每台服务器每秒查询数百次或更少）&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number7 index6 alt2&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(244, 244, 244) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;7&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.对于简单查询，允许大约&lt;/code&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;50&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;毫秒的延迟&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(255, 255, 255) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;8&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.列的值是比较小的数值和短字符串（例如，每个URL只有&lt;/code&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;60&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;个字节）&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number9 index8 alt2&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(244, 244, 244) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;9&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.在处理单个查询时需要高吞吐量（每台服务器每秒高达数十亿行）&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number10 index9 alt1&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(255, 255, 255) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;10&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.不需要事务&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number11 index10 alt2&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(244, 244, 244) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;11&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.数据一致性要求较低&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number12 index11 alt1&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(255, 255, 255) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;12&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.每次查询中只会查询一个大表。除了一个大表，其余都是小表&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number13 index12 alt2&quot; style=&quot;font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); margin: 0px !important; padding: 0px 1em !important; border-radius: 0px !important; background: none rgb(244, 244, 244) !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important;&quot;&gt;&lt;code class=&quot;java value&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 153, 0) !important;&quot;&gt;13&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;margin: 0px !important; padding: 0px !important; font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace !important; border-radius: 0px !important; background: none !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; color: rgb(0, 0, 0) !important;&quot;&gt;.查询结果显著小于数据源。即数据有过滤或聚合。返回结果不超过单个服务器内存大小&lt;/code&gt;&lt;/div&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;分析类查询，通常只需要读取表的一小部分列。在列式数据库中可以只读取需要的数据。数据总是打包成批量读取的，所以压缩是非常容易的。同时数据按列分别存储这也更容易压缩。这进一步降低了I/O的体积。由于I/O的降低，这将帮助更多的数据被系统缓存。&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2、整合Springboot：&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;核心依赖（mybatis plus做持久层，druid做数据源）：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;&amp;lt;dependencies&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--clickhouse--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;ru.yandex.clickhouse&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;clickhouse-jdbc&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;0.3.1-patch&amp;lt;/version&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;https://mvnrepository.com/artifact/com.alibaba/druid&amp;nbsp;--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.alibaba&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;druid&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;1.2.6&amp;lt;/version&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter&amp;nbsp;--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.baomidou&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;mybatis-plus-boot-starter&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;3.4.3.1&amp;lt;/version&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;配置yml文件：&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;spring:
&amp;nbsp;&amp;nbsp;datasource:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type:&amp;nbsp;com.alibaba.druid.pool.DruidDataSource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;click:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;driverClassName:&amp;nbsp;ru.yandex.clickhouse.ClickHouseDriver
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url:&amp;nbsp;jdbc:clickhouse://127.0.0.1:8123/dbname
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;username:&amp;nbsp;username
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password:&amp;nbsp;123456
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;initialSize:&amp;nbsp;10
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;maxActive:&amp;nbsp;100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;minIdle:&amp;nbsp;10
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;maxWait:&amp;nbsp;6000
&amp;nbsp;
mybatis-plus:
&amp;nbsp;&amp;nbsp;mapper-locations:&amp;nbsp;classpath*:mapper/*.xml
&amp;nbsp;&amp;nbsp;configuration:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;log-impl:&amp;nbsp;org.apache.ibatis.logging.stdout.StdOutImpl
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;map-underscore-to-camel-case:&amp;nbsp;true
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cache-enabled:&amp;nbsp;true
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lazy-loading-enabled:&amp;nbsp;true
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;multiple-result-sets-enabled:&amp;nbsp;true
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;use-generated-keys:&amp;nbsp;true
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;default-statement-timeout:&amp;nbsp;60
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;default-fetch-size:&amp;nbsp;100
&amp;nbsp;&amp;nbsp;type-aliases-package:&amp;nbsp;com.example.tonghp.entity&lt;/pre&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;ClickHouse与Druid连接池配置类：&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;参数配置：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;package&amp;nbsp;com.example.tonghp.config;
&amp;nbsp;
import&amp;nbsp;lombok.Data;
import&amp;nbsp;org.springframework.boot.context.properties.ConfigurationProperties;
import&amp;nbsp;org.springframework.stereotype.Component;
&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@author:&amp;nbsp;tonghp
&amp;nbsp;*&amp;nbsp;@create:&amp;nbsp;2021/07/26&amp;nbsp;16:23
&amp;nbsp;*/
@Data
@Component
@ConfigurationProperties(prefix&amp;nbsp;=&amp;nbsp;&amp;quot;spring.datasource.click&amp;quot;)
public&amp;nbsp;class&amp;nbsp;JdbcParamConfig&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;driverClassName&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;url&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Integer&amp;nbsp;initialSize&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Integer&amp;nbsp;maxActive&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Integer&amp;nbsp;minIdle&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Integer&amp;nbsp;maxWait&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;username;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;password;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;省略&amp;nbsp;GET&amp;nbsp;和&amp;nbsp;SET
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;Druid连接池配置&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;package&amp;nbsp;com.example.tonghp.config;
&amp;nbsp;
import&amp;nbsp;com.alibaba.druid.pool.DruidDataSource;
import&amp;nbsp;org.springframework.context.annotation.Bean;
import&amp;nbsp;org.springframework.context.annotation.Configuration;
&amp;nbsp;
import&amp;nbsp;javax.annotation.Resource;
import&amp;nbsp;javax.sql.DataSource;
import&amp;nbsp;javax.swing.*;
&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@author:&amp;nbsp;tonghp
&amp;nbsp;*&amp;nbsp;@create:&amp;nbsp;2021/07/26&amp;nbsp;16:22
&amp;nbsp;*/
@Configuration
public&amp;nbsp;class&amp;nbsp;DruidConfig&amp;nbsp;{
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Resource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;JdbcParamConfig&amp;nbsp;jdbcParamConfig&amp;nbsp;;
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Bean
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;DataSource&amp;nbsp;dataSource()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DruidDataSource&amp;nbsp;datasource&amp;nbsp;=&amp;nbsp;new&amp;nbsp;DruidDataSource();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setUrl(jdbcParamConfig.getUrl());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setDriverClassName(jdbcParamConfig.getDriverClassName());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setInitialSize(jdbcParamConfig.getInitialSize());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setMinIdle(jdbcParamConfig.getMinIdle());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setMaxActive(jdbcParamConfig.getMaxActive());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setMaxWait(jdbcParamConfig.getMaxWait());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setUsername(jdbcParamConfig.getUsername());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setPassword(jdbcParamConfig.getPassword());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;datasource;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;接下来配置实体类，mapper，service，controlle以及mapper.xml。与mybatisplus操作mysql&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;package&amp;nbsp;com.example.tonghp.entity;
&amp;nbsp;
import&amp;nbsp;lombok.Data;
&amp;nbsp;
import&amp;nbsp;java.io.Serializable;
&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@author:&amp;nbsp;tonghp
&amp;nbsp;*&amp;nbsp;@create:&amp;nbsp;2021/07/26&amp;nbsp;16:31
&amp;nbsp;*/
@Data
public&amp;nbsp;class&amp;nbsp;UserInfo&amp;nbsp;implements&amp;nbsp;Serializable&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;final&amp;nbsp;long&amp;nbsp;serialVersionUID&amp;nbsp;=&amp;nbsp;1L;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;int&amp;nbsp;id;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;userName;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;passWord;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;phone;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;email;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;createDay;
}&lt;/pre&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;package&amp;nbsp;com.example.tonghp.mapper;
&amp;nbsp;
import&amp;nbsp;com.baomidou.mybatisplus.core.mapper.BaseMapper;
import&amp;nbsp;com.example.tonghp.entity.UserInfo;
import&amp;nbsp;org.apache.ibatis.annotations.Mapper;
import&amp;nbsp;org.apache.ibatis.annotations.Param;
import&amp;nbsp;org.springframework.stereotype.Repository;
&amp;nbsp;
import&amp;nbsp;java.util.List;
&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@author:&amp;nbsp;tonghp
&amp;nbsp;*&amp;nbsp;@create:&amp;nbsp;2021/07/26&amp;nbsp;16:32
&amp;nbsp;*/
@Repository
public&amp;nbsp;interface&amp;nbsp;UserInfoMapper&amp;nbsp;extends&amp;nbsp;BaseMapper&amp;lt;UserInfo&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;写入数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;saveData&amp;nbsp;(UserInfo&amp;nbsp;userInfo)&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;ID&amp;nbsp;查询
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UserInfo&amp;nbsp;selectById&amp;nbsp;(@Param(&amp;quot;id&amp;quot;)&amp;nbsp;Integer&amp;nbsp;id)&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;查询全部
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;UserInfo&amp;gt;&amp;nbsp;selectList&amp;nbsp;()&amp;nbsp;;
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;UserInfoMapper.xml&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;&amp;lt;?xml&amp;nbsp;version=&amp;quot;1.0&amp;quot;&amp;nbsp;encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE&amp;nbsp;mapper&amp;nbsp;PUBLIC&amp;nbsp;&amp;quot;-//mybatis.org//DTD&amp;nbsp;Mapper&amp;nbsp;3.0//EN&amp;quot;&amp;nbsp;&amp;quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&amp;quot;&amp;gt;
&amp;lt;mapper&amp;nbsp;namespace=&amp;quot;com.example.tonghp.mapper.UserInfoMapper&amp;quot;&amp;gt;
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resultMap&amp;nbsp;id=&amp;quot;BaseResultMap&amp;quot;&amp;nbsp;type=&amp;quot;com.example.tonghp.entity.UserInfo&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;id&amp;nbsp;column=&amp;quot;id&amp;quot;&amp;nbsp;jdbcType=&amp;quot;INTEGER&amp;quot;&amp;nbsp;property=&amp;quot;id&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;user_name&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;userName&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;pass_word&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;passWord&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;phone&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;phone&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;email&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;email&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;create_day&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;createDay&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resultMap&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;sql&amp;nbsp;id=&amp;quot;Base_Column_List&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id,user_name,pass_word,phone,email,create_day
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/sql&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;insert&amp;nbsp;id=&amp;quot;saveData&amp;quot;&amp;nbsp;parameterType=&amp;quot;com.example.tonghp.entity.UserInfo&amp;quot;&amp;nbsp;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;INSERT&amp;nbsp;INTO&amp;nbsp;cs_user_info
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(id,user_name,pass_word,phone,email,create_day)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VALUES
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(#{id,jdbcType=INTEGER},#{userName,jdbcType=VARCHAR},#{passWord,jdbcType=VARCHAR},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#{phone,jdbcType=VARCHAR},#{email,jdbcType=VARCHAR},#{createDay,jdbcType=VARCHAR})
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/insert&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;select&amp;nbsp;id=&amp;quot;selectById&amp;quot;&amp;nbsp;parameterType=&amp;quot;java.lang.Integer&amp;quot;&amp;nbsp;resultMap=&amp;quot;BaseResultMap&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;include&amp;nbsp;refid=&amp;quot;Base_Column_List&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;from&amp;nbsp;cs_user_info
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where&amp;nbsp;id&amp;nbsp;=&amp;nbsp;#{id,jdbcType=INTEGER}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/select&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;select&amp;nbsp;id=&amp;quot;selectList&amp;quot;&amp;nbsp;resultMap=&amp;quot;BaseResultMap&amp;quot;&amp;nbsp;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;include&amp;nbsp;refid=&amp;quot;Base_Column_List&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;from&amp;nbsp;cs_user_info
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/select&amp;gt;
&amp;nbsp;
&amp;lt;/mapper&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;Service&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;package&amp;nbsp;com.example.tonghp.service;
&amp;nbsp;
import&amp;nbsp;com.baomidou.mybatisplus.extension.service.IService;
import&amp;nbsp;com.example.tonghp.entity.UserInfo;
import&amp;nbsp;org.apache.ibatis.annotations.Param;
import&amp;nbsp;org.springframework.stereotype.Service;
&amp;nbsp;
import&amp;nbsp;java.util.List;
&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@author:&amp;nbsp;tonghp
&amp;nbsp;*&amp;nbsp;@create:&amp;nbsp;2021/07/26&amp;nbsp;16:46
&amp;nbsp;*/
public&amp;nbsp;interface&amp;nbsp;UserInfoService&amp;nbsp;extends&amp;nbsp;IService&amp;lt;UserInfo&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;写入数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;saveData&amp;nbsp;(UserInfo&amp;nbsp;userInfo)&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;ID&amp;nbsp;查询
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UserInfo&amp;nbsp;selectById&amp;nbsp;(@Param(&amp;quot;id&amp;quot;)&amp;nbsp;Integer&amp;nbsp;id)&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;查询全部
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;UserInfo&amp;gt;&amp;nbsp;selectList&amp;nbsp;()&amp;nbsp;;
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;ServiceImpl&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;package&amp;nbsp;com.example.tonghp.service.impl;
&amp;nbsp;
import&amp;nbsp;com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import&amp;nbsp;com.example.tonghp.entity.UserInfo;
import&amp;nbsp;com.example.tonghp.mapper.UserInfoMapper;
import&amp;nbsp;com.example.tonghp.service.UserInfoService;
import&amp;nbsp;org.springframework.beans.factory.annotation.Autowired;
import&amp;nbsp;org.springframework.stereotype.Service;
&amp;nbsp;
import&amp;nbsp;java.util.List;
&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@author:&amp;nbsp;tonghp
&amp;nbsp;*&amp;nbsp;@create:&amp;nbsp;2021/07/26&amp;nbsp;16:48
&amp;nbsp;*/
&amp;nbsp;
@Service
public&amp;nbsp;class&amp;nbsp;UserInfoServiceImpl&amp;nbsp;extends&amp;nbsp;ServiceImpl&amp;lt;UserInfoMapper,&amp;nbsp;UserInfo&amp;gt;&amp;nbsp;implements&amp;nbsp;UserInfoService&amp;nbsp;{
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Autowired
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UserInfoMapper&amp;nbsp;userInfoMapper;
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;saveData(UserInfo&amp;nbsp;userInfo)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfoMapper.saveData(userInfo);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;UserInfo&amp;nbsp;selectById(Integer&amp;nbsp;id)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userInfoMapper.selectById(id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;UserInfo&amp;gt;&amp;nbsp;selectList()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userInfoMapper.selectList();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;Controller&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;package&amp;nbsp;com.example.tonghp.controller;
&amp;nbsp;
import&amp;nbsp;com.example.tonghp.entity.UserInfo;
import&amp;nbsp;com.example.tonghp.service.UserInfoService;
import&amp;nbsp;org.springframework.beans.factory.annotation.Autowired;
import&amp;nbsp;org.springframework.web.bind.annotation.RequestMapping;
import&amp;nbsp;org.springframework.web.bind.annotation.RestController;
&amp;nbsp;
import&amp;nbsp;javax.annotation.Resource;
import&amp;nbsp;java.util.List;
&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@author:&amp;nbsp;tonghp
&amp;nbsp;*&amp;nbsp;@create:&amp;nbsp;2021/07/26&amp;nbsp;16:45
&amp;nbsp;*/
@RestController
@RequestMapping(&amp;quot;user&amp;quot;)
public&amp;nbsp;class&amp;nbsp;UserInfoController&amp;nbsp;{
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Autowired
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;UserInfoService&amp;nbsp;userInfoService&amp;nbsp;;
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@RequestMapping(&amp;quot;saveData&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;String&amp;nbsp;saveData&amp;nbsp;(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UserInfo&amp;nbsp;userInfo&amp;nbsp;=&amp;nbsp;new&amp;nbsp;UserInfo&amp;nbsp;()&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setId(4);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setUserName(&amp;quot;winter&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setPassWord(&amp;quot;567&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setPhone(&amp;quot;13977776789&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setEmail(&amp;quot;winter&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setCreateDay(&amp;quot;2020-02-20&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfoService.saveData(userInfo);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;sus&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@RequestMapping(&amp;quot;selectById&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;UserInfo&amp;nbsp;selectById&amp;nbsp;()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userInfoService.selectById(1)&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@RequestMapping(&amp;quot;selectList&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;UserInfo&amp;gt;&amp;nbsp;selectList&amp;nbsp;()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userInfoService.selectList()&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;main()&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;package&amp;nbsp;com.example.tonghp;
&amp;nbsp;
import&amp;nbsp;org.mybatis.spring.annotation.MapperScan;
import&amp;nbsp;org.springframework.boot.SpringApplication;
import&amp;nbsp;org.springframework.boot.autoconfigure.SpringBootApplication;
&amp;nbsp;
@SpringBootApplication
@MapperScan(&amp;quot;com.example.tonghp.mapper&amp;quot;)
public&amp;nbsp;class&amp;nbsp;TonghpApplication&amp;nbsp;{
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;main(String[]&amp;nbsp;args)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SpringApplication.run(TonghpApplication.class,&amp;nbsp;args);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;h2 style=&quot;margin: 20px 0px; padding: 0px; font-size: 21px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用jdbc方式操作clickhouse&lt;/h2&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;1、创建表及数据&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;create&amp;nbsp;table&amp;nbsp;t_order01(
&amp;nbsp;id&amp;nbsp;UInt32,
&amp;nbsp;sku_id&amp;nbsp;String,
&amp;nbsp;total_amount&amp;nbsp;Decimal(16,2),
&amp;nbsp;create_time&amp;nbsp;Datetime
)&amp;nbsp;engine&amp;nbsp;=MergeTree
&amp;nbsp;partition&amp;nbsp;by&amp;nbsp;toYYYYMMDD(create_time)
&amp;nbsp;primary&amp;nbsp;key&amp;nbsp;(id)
&amp;nbsp;order&amp;nbsp;by&amp;nbsp;(id,sku_id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;
insert&amp;nbsp;into&amp;nbsp;t_order01&amp;nbsp;values
(101,&amp;#39;sku_001&amp;#39;,1000.00,&amp;#39;2021-12-01&amp;nbsp;12:00:00&amp;#39;),
(102,&amp;#39;sku_002&amp;#39;,2000.00,&amp;#39;2021-12-01&amp;nbsp;11:00:00&amp;#39;),
(102,&amp;#39;sku_004&amp;#39;,2500.00,&amp;#39;2021-12-01&amp;nbsp;12:00:00&amp;#39;),
(102,&amp;#39;sku_002&amp;#39;,2000.00,&amp;#39;2021-12-01&amp;nbsp;13:00:00&amp;#39;),
(102,&amp;#39;sku_002&amp;#39;,12000.00,&amp;#39;2021-12-01&amp;nbsp;13:00:00&amp;#39;),
(102,&amp;#39;sku_002&amp;#39;,600.00,&amp;#39;2020-06-12&amp;nbsp;12:00:00&amp;#39;);&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;2、&lt;/span&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;引入clickhouse的jdbc依赖&lt;/strong&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;ru.yandex.clickhouse&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;clickhouse-jdbc&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;0.1.52&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;&lt;/pre&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3、&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;实例代码&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;实大部分的操作和我们使用jdbc操作mysql的步骤类似，下面直接贴出代码，可以结合注释进行参考使用&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;import&amp;nbsp;ru.yandex.clickhouse.ClickHouseConnection;
import&amp;nbsp;ru.yandex.clickhouse.ClickHouseDataSource;
import&amp;nbsp;ru.yandex.clickhouse.settings.ClickHouseProperties;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
import&amp;nbsp;java.sql.*;
import&amp;nbsp;java.util.ArrayList;
import&amp;nbsp;java.util.HashMap;
import&amp;nbsp;java.util.List;
import&amp;nbsp;java.util.Map;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
public&amp;nbsp;class&amp;nbsp;CreateTableTest&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;String&amp;nbsp;username&amp;nbsp;=&amp;nbsp;&amp;quot;default&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;String&amp;nbsp;password&amp;nbsp;=&amp;nbsp;&amp;quot;你的连接密码&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;String&amp;nbsp;address&amp;nbsp;=&amp;nbsp;&amp;quot;jdbc:clickhouse://clickhouse的连接IP地址:8123&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;String&amp;nbsp;db&amp;nbsp;=&amp;nbsp;&amp;quot;连接数据库名称（默认数据库：default）&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;int&amp;nbsp;socketTimeout&amp;nbsp;=&amp;nbsp;600000;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;main(String[]&amp;nbsp;args)&amp;nbsp;throws&amp;nbsp;Exception&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//getConn();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//queryTable();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//createTable(&amp;quot;&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//insertOne();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//dropTable();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;deleteById();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//updateById();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;查询数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;queryTable(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;Map&amp;lt;String,&amp;nbsp;Object&amp;gt;&amp;gt;&amp;nbsp;list&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ArrayList&amp;lt;&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;sql&amp;nbsp;=&amp;nbsp;&amp;quot;select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;user_info&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Connection&amp;nbsp;connection&amp;nbsp;=&amp;nbsp;getConn();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Statement&amp;nbsp;statement&amp;nbsp;=&amp;nbsp;connection.createStatement();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ResultSet&amp;nbsp;rs&amp;nbsp;&amp;nbsp;=&amp;nbsp;statement.executeQuery(sql);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ResultSetMetaData&amp;nbsp;rsmd&amp;nbsp;=&amp;nbsp;rs.getMetaData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while(rs.next()){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Map&amp;lt;String,&amp;nbsp;Object&amp;gt;&amp;nbsp;row&amp;nbsp;=&amp;nbsp;new&amp;nbsp;HashMap&amp;lt;&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(int&amp;nbsp;i&amp;nbsp;=&amp;nbsp;1;&amp;nbsp;i&amp;nbsp;&amp;lt;=&amp;nbsp;rsmd.getColumnCount();&amp;nbsp;i++){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;row.put(rsmd.getColumnName(i),&amp;nbsp;rs.getObject(rsmd.getColumnName(i)));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;list.add(row);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;catch&amp;nbsp;(SQLException&amp;nbsp;e)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.printStackTrace();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//在此可以根据实际需求将解析的数据封装到对象中
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;list.stream().forEach(item&amp;nbsp;-&amp;gt;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Map&amp;lt;String,&amp;nbsp;Object&amp;gt;&amp;nbsp;rowData&amp;nbsp;=&amp;nbsp;item;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(rowData);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//System.out.println(list);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;创建表
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;@throws&amp;nbsp;Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;createTable(String&amp;nbsp;tableSql)&amp;nbsp;throws&amp;nbsp;Exception{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/*tableSql&amp;nbsp;=&amp;nbsp;&amp;quot;create&amp;nbsp;table&amp;nbsp;t_order02(\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;nbsp;id&amp;nbsp;UInt32,\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;nbsp;sku_id&amp;nbsp;String,\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;nbsp;total_amount&amp;nbsp;Decimal(16,2),\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;nbsp;create_time&amp;nbsp;Datetime\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;)&amp;nbsp;engine&amp;nbsp;=MergeTree\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;nbsp;partition&amp;nbsp;by&amp;nbsp;toYYYYMMDD(create_time)\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;nbsp;primary&amp;nbsp;key&amp;nbsp;(id)\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;nbsp;order&amp;nbsp;by&amp;nbsp;(id,sku_id);&amp;quot;;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Connection&amp;nbsp;connection&amp;nbsp;=&amp;nbsp;getConn();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Statement&amp;nbsp;statement&amp;nbsp;=&amp;nbsp;connection.createStatement();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;boolean&amp;nbsp;execute&amp;nbsp;=&amp;nbsp;statement.execute(tableSql);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(execute){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(execute);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;创建表成功&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;删除表
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;@throws&amp;nbsp;Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;dropTable()&amp;nbsp;throws&amp;nbsp;Exception{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Connection&amp;nbsp;connection&amp;nbsp;=&amp;nbsp;getConn();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Statement&amp;nbsp;statement&amp;nbsp;=&amp;nbsp;connection.createStatement();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;statement.execute(&amp;quot;drop&amp;nbsp;table&amp;nbsp;t_order01;&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;删除表成功&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;插入数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;实际使用时候，插入的语句里面的参数从外部传入进去
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;@throws&amp;nbsp;Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;insertOne()&amp;nbsp;throws&amp;nbsp;Exception{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Connection&amp;nbsp;connection&amp;nbsp;=&amp;nbsp;getConn();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PreparedStatement&amp;nbsp;pstmt&amp;nbsp;=&amp;nbsp;connection.prepareStatement(&amp;quot;insert&amp;nbsp;into&amp;nbsp;t_order01&amp;nbsp;values(&amp;#39;103&amp;#39;,&amp;nbsp;&amp;#39;sku_004&amp;#39;,&amp;nbsp;&amp;#39;2500.00&amp;#39;,&amp;#39;2021-06-01&amp;nbsp;12:00:00&amp;#39;)&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pstmt.execute();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;insert&amp;nbsp;success&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;删除数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;实际使用时候，删除的语句里面的参数从外部传入进去
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;deleteById()&amp;nbsp;throws&amp;nbsp;Exception{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Connection&amp;nbsp;connection&amp;nbsp;=&amp;nbsp;getConn();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//sku_id&amp;nbsp;=&amp;#39;sku_001&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PreparedStatement&amp;nbsp;pstmt&amp;nbsp;=&amp;nbsp;connection.prepareStatement(&amp;quot;alter&amp;nbsp;table&amp;nbsp;t_order01&amp;nbsp;delete&amp;nbsp;where&amp;nbsp;sku_id&amp;nbsp;=&amp;nbsp;&amp;#39;sku_002&amp;#39;;&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pstmt.execute();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;delete&amp;nbsp;success&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;修改数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;实际使用时候，修改的语句里面的参数从外部传入进去
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;updateById()&amp;nbsp;throws&amp;nbsp;Exception{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Connection&amp;nbsp;connection&amp;nbsp;=&amp;nbsp;getConn();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PreparedStatement&amp;nbsp;pstmt&amp;nbsp;=&amp;nbsp;connection.prepareStatement(&amp;quot;alter&amp;nbsp;table&amp;nbsp;t_order01&amp;nbsp;update&amp;nbsp;total_amount=toDecimal32(2000.00,2)&amp;nbsp;where&amp;nbsp;id&amp;nbsp;=&amp;nbsp;&amp;#39;102&amp;#39;&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pstmt.execute();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;update&amp;nbsp;success&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;Connection&amp;nbsp;getConn()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseProperties&amp;nbsp;properties&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ClickHouseProperties();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties.setUser(username);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties.setPassword(password);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties.setDatabase(db);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties.setSocketTimeout(socketTimeout);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseDataSource&amp;nbsp;clickHouseDataSource&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ClickHouseDataSource(address,&amp;nbsp;properties);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseConnection&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;clickHouseDataSource.getConnection();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(conn);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;连接成功&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;conn;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;catch&amp;nbsp;(SQLException&amp;nbsp;e)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.printStackTrace();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;或操作util工具类&lt;/span&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/strong&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;import&amp;nbsp;lombok.extern.slf4j.Slf4j;
import&amp;nbsp;org.springframework.beans.factory.annotation.Value;
import&amp;nbsp;org.springframework.stereotype.Component;
import&amp;nbsp;net.sf.json.JSONObject;
import&amp;nbsp;ru.yandex.clickhouse.ClickHouseConnection;
import&amp;nbsp;ru.yandex.clickhouse.ClickHouseDataSource;
import&amp;nbsp;ru.yandex.clickhouse.settings.ClickHouseProperties;
&amp;nbsp;&amp;nbsp;
import&amp;nbsp;java.sql.*;
import&amp;nbsp;java.util.*;
&amp;nbsp;&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@Description:
&amp;nbsp;*&amp;nbsp;@Date&amp;nbsp;2018/11/12
&amp;nbsp;*/
@Slf4j
@Component
public&amp;nbsp;class&amp;nbsp;ClickHouseUtil&amp;nbsp;{
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;String&amp;nbsp;clickhouseAddress;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;String&amp;nbsp;clickhouseUsername;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;String&amp;nbsp;clickhousePassword;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;String&amp;nbsp;clickhouseDB;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;Integer&amp;nbsp;clickhouseSocketTimeout;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Value(&amp;quot;${clickhouse.address}&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;&amp;nbsp;void&amp;nbsp;setClickhouseAddress(String&amp;nbsp;address)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseUtil.clickhouseAddress&amp;nbsp;=&amp;nbsp;address;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Value(&amp;quot;${clickhouse.username}&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;&amp;nbsp;void&amp;nbsp;setClickhouseUsername(String&amp;nbsp;username)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseUtil.clickhouseUsername&amp;nbsp;=&amp;nbsp;username;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Value(&amp;quot;${clickhouse.password}&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;&amp;nbsp;void&amp;nbsp;setClickhousePassword(String&amp;nbsp;password)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseUtil.clickhousePassword&amp;nbsp;=&amp;nbsp;password;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Value(&amp;quot;${clickhouse.db}&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;&amp;nbsp;void&amp;nbsp;setClickhouseDB(String&amp;nbsp;db)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseUtil.clickhouseDB&amp;nbsp;=&amp;nbsp;db;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Value(&amp;quot;${clickhouse.socketTimeout}&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;&amp;nbsp;void&amp;nbsp;setClickhouseSocketTimeout(Integer&amp;nbsp;socketTimeout)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseUtil.clickhouseSocketTimeout&amp;nbsp;=&amp;nbsp;socketTimeout;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;Connection&amp;nbsp;getConn()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseConnection&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseProperties&amp;nbsp;properties&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ClickHouseProperties();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties.setUser(clickhouseUsername);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties.setPassword(clickhousePassword);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties.setDatabase(clickhouseDB);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties.setSocketTimeout(clickhouseSocketTimeout);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClickHouseDataSource&amp;nbsp;clickHouseDataSource&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ClickHouseDataSource(clickhouseAddress,properties);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;clickHouseDataSource.getConnection();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;conn;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;catch&amp;nbsp;(SQLException&amp;nbsp;e)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.printStackTrace();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;List&amp;lt;JSONObject&amp;gt;&amp;nbsp;exeSql(String&amp;nbsp;sql){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;log.info(&amp;quot;cliockhouse&amp;nbsp;执行sql：&amp;quot;&amp;nbsp;+&amp;nbsp;sql);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Connection&amp;nbsp;connection&amp;nbsp;=&amp;nbsp;getConn();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Statement&amp;nbsp;statement&amp;nbsp;=&amp;nbsp;connection.createStatement();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ResultSet&amp;nbsp;results&amp;nbsp;=&amp;nbsp;statement.executeQuery(sql);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ResultSetMetaData&amp;nbsp;rsmd&amp;nbsp;=&amp;nbsp;results.getMetaData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;JSONObject&amp;gt;&amp;nbsp;list&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ArrayList();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while(results.next()){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;JSONObject&amp;nbsp;row&amp;nbsp;=&amp;nbsp;new&amp;nbsp;JSONObject();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(int&amp;nbsp;i&amp;nbsp;=&amp;nbsp;1;i&amp;lt;=rsmd.getColumnCount();i++){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;row.put(rsmd.getColumnName(i),results.getString(rsmd.getColumnName(i)));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;list.add(row);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;list;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;catch&amp;nbsp;(SQLException&amp;nbsp;e)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.printStackTrace();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;
}&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;Test简单使用执行sql查询数据&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;import&amp;nbsp;com.renrenche.databus.common.ClickHouseUtil;
import&amp;nbsp;com.renrenche.databus.common.Result;
import&amp;nbsp;com.renrenche.databus.domain.logdata.fem.FemParam;
import&amp;nbsp;com.renrenche.databus.service.fem.FemMainService;
import&amp;nbsp;net.sf.json.JSONObject;
import&amp;nbsp;org.junit.Test;
import&amp;nbsp;org.junit.runner.RunWith;
import&amp;nbsp;org.springframework.beans.factory.annotation.Autowired;
import&amp;nbsp;org.springframework.boot.test.context.SpringBootTest;
import&amp;nbsp;org.springframework.test.context.junit4.SpringRunner;
&amp;nbsp;&amp;nbsp;
import&amp;nbsp;java.util.List;
&amp;nbsp;&amp;nbsp;
/**
&amp;nbsp;*&amp;nbsp;@Auther:&amp;nbsp;qixin
&amp;nbsp;*&amp;nbsp;@Date:&amp;nbsp;2018/12/11&amp;nbsp;15:05
&amp;nbsp;*&amp;nbsp;@Description:
&amp;nbsp;*/
@RunWith(SpringRunner.class)
@SpringBootTest
public&amp;nbsp;class&amp;nbsp;SemTest&amp;nbsp;{
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Test
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;getFrsDataTest(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;******************&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;sql=&amp;quot;select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;marketing.sem_campaign_real_time_report&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;JSONObject&amp;gt;&amp;nbsp;result=&amp;nbsp;ClickHouseUtil.exeSql(sql);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;******************&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;
}&lt;/pre&gt;&lt;h2 style=&quot;margin: 20px 0px; padding: 0px; font-size: 21px; line-height: 1.5; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;springboot的整合&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;1、准备一张表，以及表中插入一些实验数据&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;CREATE&amp;nbsp;TABLE&amp;nbsp;user_info&amp;nbsp;(
&amp;nbsp;&amp;nbsp;`id`&amp;nbsp;UInt64,
&amp;nbsp;&amp;nbsp;`user_name`&amp;nbsp;String,
&amp;nbsp;&amp;nbsp;`pass_word`&amp;nbsp;String,
&amp;nbsp;&amp;nbsp;`phone`&amp;nbsp;String,
&amp;nbsp;&amp;nbsp;`create_day`&amp;nbsp;Date&amp;nbsp;DEFAULT&amp;nbsp;CAST(now(),&amp;#39;Date&amp;#39;)
)ENGINE&amp;nbsp;=&amp;nbsp;MergeTree
primary&amp;nbsp;key&amp;nbsp;(id)
order&amp;nbsp;by&amp;nbsp;(id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
INSERT&amp;nbsp;INTO&amp;nbsp;user_info
&amp;nbsp;&amp;nbsp;(id,user_name,pass_word,phone)
VALUES
&amp;nbsp;&amp;nbsp;(1,&amp;#39;xiaowang&amp;#39;,&amp;#39;123456&amp;#39;,&amp;#39;13325511231&amp;#39;),
&amp;nbsp;&amp;nbsp;(2,&amp;#39;xiaoma&amp;#39;,&amp;#39;123456&amp;#39;,&amp;#39;13825511231&amp;#39;),
&amp;nbsp;&amp;nbsp;(3,&amp;#39;xiaozhao&amp;#39;,&amp;#39;123456&amp;#39;,&amp;#39;18925511231&amp;#39;);&lt;/pre&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;2、代码完整整合步骤&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;导入完整依赖&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;&amp;lt;dependencies&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;spring-boot-starter-web&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;spring-boot-starter-aop&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;spring-boot-starter-test&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.mybatis.spring.boot&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;mybatis-spring-boot-starter&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;1.3.2&amp;lt;/version&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;mysql&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;mysql-connector-java&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;5.1.38&amp;lt;/version&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.alibaba&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;druid-spring-boot-starter&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;1.1.13&amp;lt;/version&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;commons-lang&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;commons-lang&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;2.6&amp;lt;/version&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;clickHouse数据库&amp;nbsp;--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;ru.yandex.clickhouse&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;clickhouse-jdbc&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;0.1.53&amp;lt;/version&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;/dependencies&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2、基础配置文件&lt;/strong&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;server:
&amp;nbsp;&amp;nbsp;port:&amp;nbsp;7010
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;#&amp;nbsp;mybatis&amp;nbsp;配置
mybatis:
&amp;nbsp;&amp;nbsp;type-aliases-package:&amp;nbsp;com.congge.entity
&amp;nbsp;&amp;nbsp;mapper-locations:&amp;nbsp;classpath:/mapper/*.xml
&amp;nbsp;&amp;nbsp;&amp;nbsp;
spring:
&amp;nbsp;&amp;nbsp;datasource:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type:&amp;nbsp;com.alibaba.druid.pool.DruidDataSource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;click:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;driverClassName:&amp;nbsp;ru.yandex.clickhouse.ClickHouseDriver
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url:&amp;nbsp;jdbc:clickhouse://IP地址:8123/default
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;username:&amp;nbsp;default
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password:&amp;nbsp;123456
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;initialSize:&amp;nbsp;10
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;maxActive:&amp;nbsp;100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;minIdle:&amp;nbsp;10
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;maxWait:&amp;nbsp;6000&lt;/pre&gt;&lt;p&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3、使用一个配置类，关联第二步中的click配置属性&lt;/strong&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/strong&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;import&amp;nbsp;org.springframework.boot.context.properties.ConfigurationProperties;
import&amp;nbsp;org.springframework.stereotype.Component;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
@Component
@ConfigurationProperties(prefix&amp;nbsp;=&amp;nbsp;&amp;quot;spring.datasource.click&amp;quot;)
public&amp;nbsp;class&amp;nbsp;ConnectionParamConfig&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;driverClassName&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;url&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Integer&amp;nbsp;initialSize&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Integer&amp;nbsp;maxActive&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Integer&amp;nbsp;minIdle&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Integer&amp;nbsp;maxWait&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;username;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;String&amp;nbsp;password;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;String&amp;nbsp;getDriverClassName()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;driverClassName;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setDriverClassName(String&amp;nbsp;driverClassName)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.driverClassName&amp;nbsp;=&amp;nbsp;driverClassName;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;String&amp;nbsp;getUrl()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;url;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setUrl(String&amp;nbsp;url)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.url&amp;nbsp;=&amp;nbsp;url;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Integer&amp;nbsp;getInitialSize()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;initialSize;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setInitialSize(Integer&amp;nbsp;initialSize)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.initialSize&amp;nbsp;=&amp;nbsp;initialSize;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Integer&amp;nbsp;getMaxActive()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;maxActive;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setMaxActive(Integer&amp;nbsp;maxActive)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.maxActive&amp;nbsp;=&amp;nbsp;maxActive;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Integer&amp;nbsp;getMinIdle()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;minIdle;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setMinIdle(Integer&amp;nbsp;minIdle)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.minIdle&amp;nbsp;=&amp;nbsp;minIdle;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Integer&amp;nbsp;getMaxWait()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;maxWait;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setMaxWait(Integer&amp;nbsp;maxWait)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.maxWait&amp;nbsp;=&amp;nbsp;maxWait;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;String&amp;nbsp;getUsername()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;username;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setUsername(String&amp;nbsp;username)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.username&amp;nbsp;=&amp;nbsp;username;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;String&amp;nbsp;getPassword()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;password;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setPassword(String&amp;nbsp;password)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.password&amp;nbsp;=&amp;nbsp;password;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;p&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4、重写datasource的配置，使用自定义的clickhouse的属性配置&lt;/strong&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/strong&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;import&amp;nbsp;javax.annotation.Resource;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
import&amp;nbsp;com.alibaba.druid.pool.DruidDataSource;
import&amp;nbsp;org.springframework.context.annotation.Bean;
import&amp;nbsp;org.springframework.context.annotation.Configuration;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
import&amp;nbsp;javax.sql.DataSource;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
@Configuration
public&amp;nbsp;class&amp;nbsp;DruidConfig&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Resource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;ConnectionParamConfig&amp;nbsp;jdbcParamConfig;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;重写&amp;nbsp;DataSource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;@return
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Bean
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;DataSource&amp;nbsp;dataSource()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DruidDataSource&amp;nbsp;datasource&amp;nbsp;=&amp;nbsp;new&amp;nbsp;DruidDataSource();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setUrl(jdbcParamConfig.getUrl());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setDriverClassName(jdbcParamConfig.getDriverClassName());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setInitialSize(jdbcParamConfig.getInitialSize());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setMinIdle(jdbcParamConfig.getMinIdle());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setMaxActive(jdbcParamConfig.getMaxActive());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setMaxWait(jdbcParamConfig.getMaxWait());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setUsername(jdbcParamConfig.getUsername());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;datasource.setPassword(jdbcParamConfig.getPassword());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;datasource;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/pre&gt;&lt;p&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;5、提供一个接口和mybatis的查询xml文件&lt;/strong&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/strong&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;public&amp;nbsp;interface&amp;nbsp;UserInfoMapper&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;saveData&amp;nbsp;(UserInfo&amp;nbsp;userInfo)&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UserInfo&amp;nbsp;selectById&amp;nbsp;(@Param(&amp;quot;id&amp;quot;)&amp;nbsp;Integer&amp;nbsp;id)&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;UserInfo&amp;gt;&amp;nbsp;selectList&amp;nbsp;()&amp;nbsp;;
}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;?xml&amp;nbsp;version=&amp;quot;1.0&amp;quot;&amp;nbsp;encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE&amp;nbsp;mapper&amp;nbsp;PUBLIC&amp;nbsp;&amp;quot;-//mybatis.org//DTD&amp;nbsp;Mapper&amp;nbsp;3.0//EN&amp;quot;&amp;nbsp;&amp;quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&amp;quot;&amp;gt;
&amp;lt;mapper&amp;nbsp;namespace=&amp;quot;com.congge.mapper.UserInfoMapper&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resultMap&amp;nbsp;id=&amp;quot;BaseResultMap&amp;quot;&amp;nbsp;type=&amp;quot;com.congge.entity.UserInfo&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;id&amp;nbsp;column=&amp;quot;id&amp;quot;&amp;nbsp;jdbcType=&amp;quot;INTEGER&amp;quot;&amp;nbsp;property=&amp;quot;id&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;user_name&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;userName&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;pass_word&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;passWord&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;phone&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;phone&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;result&amp;nbsp;column=&amp;quot;create_day&amp;quot;&amp;nbsp;jdbcType=&amp;quot;VARCHAR&amp;quot;&amp;nbsp;property=&amp;quot;createDay&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resultMap&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;sql&amp;nbsp;id=&amp;quot;Base_Column_List&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id,user_name,pass_word,phone,create_day
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/sql&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;insert&amp;nbsp;id=&amp;quot;saveData&amp;quot;&amp;nbsp;parameterType=&amp;quot;com.congge.entity.UserInfo&amp;quot;&amp;nbsp;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;INSERT&amp;nbsp;INTO&amp;nbsp;user_info
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(id,user_name,pass_word,phone,create_day)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VALUES
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(#{id,jdbcType=INTEGER},#{userName,jdbcType=VARCHAR},#{passWord,jdbcType=VARCHAR},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#{phone,jdbcType=VARCHAR},#{createDay,jdbcType=VARCHAR})
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/insert&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;select&amp;nbsp;id=&amp;quot;selectById&amp;quot;&amp;nbsp;parameterType=&amp;quot;java.lang.Integer&amp;quot;&amp;nbsp;resultMap=&amp;quot;BaseResultMap&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;include&amp;nbsp;refid=&amp;quot;Base_Column_List&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;from&amp;nbsp;user_info
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where&amp;nbsp;id&amp;nbsp;=&amp;nbsp;#{id,jdbcType=INTEGER}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/select&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;select&amp;nbsp;id=&amp;quot;selectList&amp;quot;&amp;nbsp;resultMap=&amp;quot;BaseResultMap&amp;quot;&amp;nbsp;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;include&amp;nbsp;refid=&amp;quot;Base_Column_List&amp;quot;&amp;nbsp;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;from&amp;nbsp;user_info
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/select&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;/mapper&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/strong&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;6、接口和服务实现类&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;@RestController
public&amp;nbsp;class&amp;nbsp;UserInfoController&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Resource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;UserInfoService&amp;nbsp;userInfoService&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//localhost:7010/saveData
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@GetMapping(&amp;quot;/saveData&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;String&amp;nbsp;saveData&amp;nbsp;(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UserInfo&amp;nbsp;userInfo&amp;nbsp;=&amp;nbsp;new&amp;nbsp;UserInfo&amp;nbsp;()&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setId(4);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setUserName(&amp;quot;xiaolin&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setPassWord(&amp;quot;54321&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setPhone(&amp;quot;18500909876&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfo.setCreateDay(&amp;quot;2022-02-06&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfoService.saveData(userInfo);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;success&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//localhost:7010/getById?id=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@GetMapping(&amp;quot;/getById&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;UserInfo&amp;nbsp;getById&amp;nbsp;(int&amp;nbsp;id)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userInfoService.selectById(id)&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@GetMapping(&amp;quot;/getList&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;UserInfo&amp;gt;&amp;nbsp;getList&amp;nbsp;()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userInfoService.selectList()&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/pre&gt;&lt;p&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;7、服务实现类，UserInfoService&lt;/strong&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/strong&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;@Service
public&amp;nbsp;class&amp;nbsp;UserInfoService&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Resource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;UserInfoMapper&amp;nbsp;userInfoMapper&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;saveData(UserInfo&amp;nbsp;userInfo)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userInfoMapper.saveData(userInfo);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;UserInfo&amp;nbsp;selectById(Integer&amp;nbsp;id)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userInfoMapper.selectById(id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;UserInfo&amp;gt;&amp;nbsp;selectList()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userInfoMapper.selectList();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/pre&gt;&lt;p&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;8、启动类&lt;/strong&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/strong&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;@SpringBootApplication
@MapperScan(basePackages&amp;nbsp;=&amp;nbsp;{&amp;quot;com.congge.mapper&amp;quot;})
public&amp;nbsp;class&amp;nbsp;App&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;main(String[]&amp;nbsp;args)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SpringApplication.run(App.class,args);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/pre&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;9、功能接口测试&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;查询测试，调用接口：localhost:7010/getById?id=1&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://img.jbzj.com/file_images/article/202202/2022020908262910.png&quot; alt=&quot;在这里插入图片描述&quot;/&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/strong&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;然后再去clickhouse表中查询下数据&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;img src=&quot;https://img.jbzj.com/file_images/article/202202/2022020908262912.png&quot; alt=&quot;在这里插入图片描述&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap: wrap; background-color: #FFFFFF;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;</description><pubDate>Fri, 22 Dec 2023 09:46:24 +0800</pubDate></item></channel></rss>