简体   繁体   English

如何将主题分区分成多个kafka服务器?

[英]How to separate topic partitions into multiple kafka servers?

I want to separate topic partitions into multiple kafka servers like on this picture .我想像这张图片一样将主题分区分成多个 kafka 服务器。

Example : I have only one topic "Test", I have two kafka servers (k1, k2), I have 4 partitions of topic "Test".示例:我只有一个主题“Test”,我有两个 kafka 服务器(k1,k2),我有 4 个主题“Test”分区。 I want to server k1 have partitions 0 and 1, and server k2 have partitions 2, 3.我希望服务器 k1 有分区 0 和 1,服务器 k2 有分区 2、3。

Kafka servers are nothing but multiple brokers. Kafka 服务器只不过是多个代理。 Please follow below steps,请按照以下步骤,

  1. Replicate the config/server.properties file into the number of servers you need.config/server.properties文件复制到您需要的服务器数量中。 In your case its two.在你的情况下,它是两个。 Copy the file to two different file and change the broker id and port将文件复制到两个不同的文件并更改代理 ID 和端口

    i.一世。 server_K1.properties (you can provide the file name as you wish), change the file properties as below. server_K1.properties (您可以根据需要提供文件名),更改文件属性如下。
    broker.id=1
    port=9092
    log.dir=/tmp/kafka-logs-1

    ii. ii. server_K2.properties
    broker.id=2
    port=9093
    log.dir=/tmp/kafka-logs-2

Start the kafka server with above two configurations使用以上两种配置启动kafka服务器

bin/kafka-server-start.sh config/server_K1.properties
bin/kafka-server-start.sh config/server_K2.properties

By providing the replication factors the Topics will be replicated across the brokers.通过提供复制因子,主题将在代理之间复制。 And based on the partitions you create, and the amount of data you receive, the partitions are shared across the brokers.并且根据您创建的分区以及您收到的数据量,这些分区在代理之间共享。

You can create 4 partitions while creating the Topic and this partitions will be shared across the brokers.您可以在创建主题时创建 4 个分区,并且此分区将在代理之间共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM