Linux:kafka命令

使用工具:puTTY 下载地址:Download PuTTY - a free SSH and telnet client for Windows

login as: root
root@*******'s password:
Last login: Fri Apr 28 14:54:26 2023 from *****
[root@kafka272c41 ~]# cd ..
[root@kafka272c41 /]# ls -a
. .. .autorelabel bin boot config dev etc home kafka lib lib64 media mnt opt proc root run sangfor sbin srv sys tmp usr var
[root@kafka272c41 /]# cd kafka
[root@kafka272c41 kafka]# ls -a
. .. flink-1.13.6 kafka_2.13-2.7.2 kafka-run.log lib_conn logs logs_ nifi-1.16.3 node-v16.13.2-linux-x64 streamx-console-service-1.2.3 tools zookeeper zookeeper-run.log
[root@kafka272c41 kafka]# cd kafka_2.13-2.7.2
[root@kafka272c41 kafka_2.13-2.7.2]# ls -a
. .. bin config libs LICENSE licenses logs logs_ NOTICE site-docs test

/*查看topic列表*/
[root@kafka272c41 kafka_2.13-2.7.2]# bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list
test
test1
...
[root@kafka272c41 kafka_2.13-2.7.2]#

/*查看具体topic信息*/

[root@kafka272c41 kafka_2.13-2.7.2]# bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic ****
Topic: **** PartitionCount: 30 ReplicationFactor: 1 Configs:
Topic: **** Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: **** Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: **** Partition: 2 Leader: 0 Replicas: 0 Isr: 0

...

/*删除指定topic*/

bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --delete --topic ****

/*新建topic*/

bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --create --topic **** --partitions 30 --replication-factor 1

/*查看所有的group*/

./bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --list

 /*查看group消费情况*/

./bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --group **** --describe

 /*修改Kafka分区数*/

bin/kafka-topics.sh --alter --zookeeper localhost:2181 --topic **** --partitions 20

注意:分区数量只能增加不能减少

 /*修改Kafka Topic副本数 */

bin/kafka-reassign-partitions.sh --zookeeper localhost:2181  --reassignment-json-file increase-replication-factor.json --execute

/*启动kafka服务*/

依次执行:

启动zookeeper

常规模式启动

bin/zookeeper-server-start.sh config/zookeeper.properties

进程守护模式启动

nohup bin/zookeeper-server-start.sh config/zookeeper.properties >/dev/null 2>&1 &

启动kafka

常规模式启动

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

进程守护模式启动

nohup bin/kafka-server-start.sh config/server.properties >/dev/null 2>&1 &

/*关闭kafka服务*/

关闭kafka

bin/kafka-server-stop.sh

关闭zookeeper

bin/zookeeper-server-stop.sh

/*创建主题*/

./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic ****

/*创建生产者*/

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

/*创建消费者*/

./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic ****

 

posted @ 2023-04-28 14:59  新*  阅读(134)  评论(0编辑  收藏  举报