本篇内容介绍了“Kafka安装部署方法及简单命令”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
本例使用单机集群方式,在本地启用三份程序组成集群, 使用一个Zookeeper集群。
需要
1.安装JDK8 Deepin 安装jdk1.8
2.配置Zookeeper集群,参见 Zookeeper单机为伪集群
地址: http://kafka.apache.org/downloads.html
tar -zxvf kafka_2.12-2.7.0.tgz -C /usr/local/kafka/
/usr/local/kafka/kafka01
broker.id=0 #broker的id 每个节点一个不能重复,本例中三个节点分别为0,1,2 delete.topic.enable=true #开启删除topic功能## host.name=127.0.0.1 #本机名或者ip port=9091 #默认为9092 每个id内Kakfa服务器监听的端口 log.dirs=/usr/local/kafka/kafka01/logs #日志存放路径 zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 #zookeeper连接端口
kafka02/config/server.properties
broker.id=1 #broker的id 每个节点一个不能重复,本例中三个节点分别为0,1,2 delete.topic.enable=true #开启删除topic功能## host.name=127.0.0.1 #本机名或者ip port=9092 #默认为9092 每个id内Kakfa服务器监听的端口 log.dirs=/usr/local/kafka/kafka02/logs #日志存放路径 zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 #zookeeper连接端口
kafka03/config/server.properties
broker.id=2 #broker的id 每个节点一个不能重复,本例中三个节点分别为0,1,2 delete.topic.enable=true #开启删除topic功能## host.name=127.0.0.1 #本机名或者ip port=9093 #默认为9092 每个id内Kakfa服务器监听的端口 log.dirs=/usr/local/kafka/kafka03/logs #日志存放路径 zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 #zookeeper连接端口
先启动zookeeper集群
/usr/local/zookeeper/zookeeper01/bin/zkServer.sh start /usr/local/zookeeper/zookeeper02/bin/zkServer.sh start /usr/local/zookeeper/zookeeper03/bin/zkServer.sh start
再启动kafka集群
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka01/config/server.properties root@bluejay-PC:/# /usr/local/kafka/kafka02/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka02/config/server.properties root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka03/config/server.properties
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-server-stop.sh root@bluejay-PC:/# /usr/local/kafka/kafka02/bin/kafka-server-stop.sh root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-server-stop.sh
1. 创建topic
root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-topics.sh --create --zookeeper 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 --replication-factor 1 --partitions 1 --topic first Created topic first.
2. 查看当前服务器中的所有 topic
root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-topics.sh --list --zookeeper 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 first
3. 消费消息-开启监听
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9091 --topic first
4. 发送消息
root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-console-producer.sh --broker-list 127.0.0.1:9091 --topic first >hello world >atguigu atguigu >zhanghl^H^H^H >end > >^C
5. 查看某个Topic的详情
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --describe --topic first Topic: first PartitionCount: 1 ReplicationFactor: 1 Configs: Topic: first Partition: 0 Leader: 2 Replicas: 2 Isr: 2
6. 修改分区数
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --alter --topic first --partitions 6 WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected Adding partitions succeeded!
7. 删除topic
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --delete --topic first
“Kafka安装部署方法及简单命令”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。