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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值