栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

kafka安装完整步骤(kafka的使用)

kafka安装完整步骤(kafka的使用)

Kafka的原理及安装 1. Kafka原理 2. Kafka安装

1) 上传到虚拟机,解压:

[root@cent71 module]# tar -zxf kafka_2.11-0.10.2.2.tgz.gz -C /opt/software/

2) 在安装目录下新建logs文件夹:

[root@cent71 kafka_2.11-0.10.2.2]# mkdir logs

3) 修改配置文件config/server.properties:

#broker的全局唯一编号,不能重复

broker.id=1

#kafka运行日志存放的路径

log.dirs=/opt/software/kafka_2.11-0.10.2.2/logs

#配置连接Zookeeper集群地址

zookeeper.connect=cent71:2181,cent72:2181,cent73:2181

4) 分发安装包:

[root@cent71 software]# scp -r kafka_2.11-0.10.2.2/ cent72:/opt/software/

[root@cent71 software]# scp -r kafka_2.11-0.10.2.2/ cent72:/opt/software/

5) 修改broker.id:

Cent72上:

broker.id=1

cent73上:

broker.id=2

6) 启动集群(启动前先启动zookeeper):

[root@cent71 kafka_2.11-0.10.2.2]# bin/kafka-server-start.sh config/server.properties

[root@cent72 kafka_2.11-0.10.2.2]# bin/kafka-server-start.sh config/server.properties

[root@cent73 kafka_2.11-0.10.2.2]# bin/kafka-server-start.sh config/server.properties

7) 关闭集群:

[root@cent71 kafka_2.11-0.10.2.2]# bin/kafka-server-stop.sh

[root@cent72 kafka_2.11-0.10.2.2]# bin/kafka-server-stop.sh

[root@cent73 kafka_2.11-0.10.2.2]# bin/kafka-server-stop.sh

3. Kafka测试

1) 在主节点上创建一个topic,名为test,并设置备份数是3,分区数是3:

[root@cent71 kafka_2.11-0.10.2.2]# bin/kafka-topics.sh -zookeeper cent71:2181,cent72:2181,cent73:2181 -topic test -replication-factor 3 -partitions 3 --create

2) 查看当前topic:

[root@cent71 kafka_2.11-0.10.2.2]# bin/kafka-topics.sh -zookeeper cent71:2181,cent72:2181,cent73:2181 --list

test

3) 在主节点上创建一个producer:

[root@cent71 kafka_2.11-0.10.2.2]# bin/kafka-console-producer.sh --broker-list cent71:9092 --topic test

4) 在从节点上创建一个consumer:

[root@cent72 kafka_2.11-0.10.2.2]# bin/kafka-console-consumer.sh --zookeeper cent71:2181,cent72:2181,cent73:2181 --topic test --from-beginning

5) 在主节点上输入消息,在从节点上查看:

[root@cent71 kafka_2.11-0.10.2.2]# bin/kafka-console-producer.sh --broker-list cent71:9092 --topic test

^[[Bh

hige

[root@cent72 kafka_2.11-0.10.2.2]# bin/kafka-console-consumer.sh --zookeeper cent71:2181,cent72:2181,cent73:2181 --topic test --from-beginning

Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].

h

hige

6) 删除topic:

[root@cent71 kafka_2.11-0.10.2.2]# bin/kafka-topics.sh -zookeeper cent71:2181,cent72:2181,cent73:2181 -topic test --delete

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/772287.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号