kafka相關命令整理

來源:互聯網
上載者:User

標籤:kafka

1、增加kafka分區

./kafka-topics.sh --zookeeper 192.168.2.70 --alter  --topic us_forward  --partitions 24

2、查看kafka的topic

./kafka-topics.sh --zookeeper 192.168.2.70 --list

3、查看單個topic的分區,也可以不加topic

./kafka-topics.sh --zookeeper 192.168.2.70 --describe --topic us_general

Topic: us_generalPartition: 0Leader: 117Replicas: 117Isr: 117

Topic: us_generalPartition: 1Leader: 117Replicas: 117Isr: 117

4、查看kafka各個組的位移量

./kafka-run-class.sh  kafka.tools.ConsumerOffsetChecker --zookeeper 192.168.110.165:2181 -group test_groupid

5、啟動kafka

bin/kafka-server-start.sh config/server.properties &

6、建立topic

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 24 --topic topic_test

7、發送訊息

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic page_visits

8、消費訊息

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic page_visits --from-beginning

9、刪除topic

bin/kafka-topics.sh --zookeeper zk_host:port --delete --topic my_topic_name

10、重新平衡分區和領導者

./kafka-preferred-replica-election.sh --zookeeper 192.168.2.70

11、擴充叢集

1)、先把要轉移的topic寫成json格式topics-to-move.json

{"topics": [

{"topic": "SYNC_DATABASE_UPDATE"},

{"topic": "SYNC_REALTIME_ALARM"},

{"topic": "SYNC_STATION_INFO"},

{"topic": "SYNC_VEHICLE_REG"},

{"topic": "ds_ctrlreq"},

{"topic": "us_ctrlrsp"},

{"topic": "us_forward"},

{"topic": "us_general"},

{"topic": "us_packet"}

],

"version":1

}

2)、用指令碼產生一個自動分區的計劃

./kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --generate --topics-to-move-json-file topics-to-move.json  --broker-list 1,2,3 

3)、把產生的建議分區儲存成json  topics-to-move-execute.json

4)、執行分區計劃

/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --execute

5)、檢查叢集擴充是否完成

/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --verify

12、增加副本數

1)、編寫擴充檔案,可以利用擴充叢集的方式匯出現在的分布然後做修改

{"version":1,

"partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]

}

2)、執行分區計劃

/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --execute

3)、檢查叢集擴充是否完成

/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --verify





本文出自 “IT工作者” 部落格,請務必保留此出處http://luhaiyou.blog.51cto.com/3179056/1701289

kafka相關命令整理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.