天天看點

(一)kafka修改topic分區的位置

(一)kafka修改topic分區的位置

環境:kafka_2.10-0.8.2.1 + JDK1.7.0_80

1. 檢視分區topic的分區分布

$ le-kafka-topics.sh --describe --topic http_zhixin_line1

結果如下:

[hadoop@sdf-nimbus-perf project]$ le-kafka-topics.sh --describe --topic http_zhixin_line1
Topic:http_zhixin_line1	PartitionCount:3	ReplicationFactor:1	Configs:
	Topic: http_zhixin_line1	Partition: 0	Leader: 4	Replicas: 4	Isr: 4
	Topic: http_zhixin_line1	Partition: 1	Leader: 5	Replicas: 5	Isr: 5
	Topic: http_zhixin_line1	Partition: 2	Leader: 6	Replicas: 6	Isr: 6
           

2. 準備分區配置設定的JSON配置檔案

可以使用kafka的kafka-reassign-partitions.sh工具來配置設定topic的分區位置,操作之前得準備一個Json檔案,裡面詳細地記錄着每個分區的副本所在機器等資訊,具體如下:

{
    "version": 1,
    "partitions": [
        {
            "topic": "http_zhixin_line1",
            "partition": 0,
            "replicas": [
                7
            ]
        },
        {
            "topic": "http_zhixin_line1",
            "partition": 1,
            "replicas": [
                8
            ]
        },
        {
            "topic": "http_zhixin_line1",
            "partition": 3,
            "replicas": [
                9
            ]
        }
    ]
}
           

3. 執行topic的分區位置修改操作:

kafka-reassign-partitions.sh --zookeeper $ZK_CONNECT --reassignment-json-file movePartitions.json --execute

執行日志如下:

[hadoop@sdf-nimbus-perf topic_reassgin]$ kafka-reassign-partitions.sh --zookeeper $ZK_CONNECT --reassignment-json-file movePartitions.json --execute
Current partition replica assignment

{"version":1,"partitions":[{"topic":"http_zhixin_line1","partition":2,"replicas":[6]},{"topic":"http_zhixin_line1","partition":1,"replicas":[5]},{"topic":"http_zhixin_line1","partition":0,"replicas":[4]}]}

Save this to use as the --reassignment-json-file option during rollback
Successfully started reassignment of partitions {"version":1,"partitions":[{"topic":"http_zhixin_line1","partition":0,"replicas":[7]},{"topic":"http_zhixin_line1","partition":1,"replicas":[8]},{"topic":"http_zhixin_line1","partition":2,"replicas":[9]}]}
           

4. 檢查執行的結果

kafka-reassign-partitions.sh --zookeeper $ZK_CONNECT --reassignment-json-file movePartitions.json --verify

[hadoop@sdf-nimbus-perf topic_reassgin]$ kafka-reassign-partitions.sh --zookeeper $ZK_CONNECT --reassignment-json-file movePartitions.json --verify
Status of partition reassignment:
Reassignment of partition [http_zhixin_line1,0] completed successfully
Reassignment of partition [http_zhixin_line1,1] completed successfully
Reassignment of partition [http_zhixin_line1,2] completed successfully
           

5. 檢查kafka的對應的topic的日志目錄

原目錄下的資料已經遷移到新的的分區所對應的伺服器下了。

配置設定狀态的變化:配置設定的狀态變化:“is still in progress” --》 “completed successfully”

如果配置設定腳本有錯,或者遇到異常,配置設定狀态會變成“failed” (具體的fail原因:如果是json配置檔案的原因,指令行就會列印出error日志;kafka内部錯誤可以檢視kafka的server.log 日志檔案等)。

重新配置設定過程中資料日志檔案的變化:

先将原來的分區的資料,copy到對應重新配置設定後的分區節點下,拷貝成功後,kakfa會将原來的分區目錄删除掉。 copy 前後的資料量大小是一緻的。

作者:

丹江湖畔養蜂子的趙大爹

出處:http://www.cnblogs.com/honeybee/

關于作者:丹江湖畔養蜂子的趙大爹

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連結