Kafka配置-安装使用(单节点单Broker)

部署kafka之前,需先安装zookeeper

此案例为:单节点单Broker

zookeeper-3.4.5-cdh5.15.1.tar.gz
解压之后,配置环境变量,修改认证文件

[root@centos7 conf]# cp zoo_sample.cfg zoo.cfg
[root@centos7 conf]# vi zoo.cfg 
dataDir=/opt/modules/zk_tmp

解压kafka_2.11-2.2.0.tgz
修改环境变量
修改配置文件

vim /opt/modules/kafka_2.11-2.2.0/config/server.properties

log.dirs=/data/log/kafka
zookeeper.connect=centos7:2181
listeners=PLAINTEXT://:9092
# Hostname and port the broker will advertise to producers and consumers. If not set, 
host.name=centos7

启动zk

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

[root@centos7 bin]# ./zkServer.sh start
JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.5-cdh5.15.1/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

启动成功
可执行jps命令查看

[root@centos7 conf]# jps
3171 QuorumPeerMain
3419 Jps

确保zookeeper成功启动之后,接下来就可以
启动kafka

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

启动成功

[2020-03-07 14:28:20,891] INFO Kafka commitId: 05fcfde8f69b0349 (org.apache.kafka.common.utils.AppInfoParser)
[2020-03-07 14:28:20,892] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)

示例:
创建tocic

[root@centos7 kafka_2.11-2.2.0]# bin/kafka-topics.sh --create --zookeeper centos7:2181 --replication-factor 1 --partitions 1 --topic 0307_test
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Created topic 0307_test.

查询topic列表

[root@centos7 kafka_2.11-2.2.0]# bin/kafka-topics.sh --list --zookeeper centos7:2181
0307_test    创建成功

启动 Producer 发送消息

bin/kafka-console-producer.sh --broker-list centos7:9092 --topic 0307_test

启动 Consumer 消费消息

bin/kafka-console-consumer.sh --bootstrap-server centos7:9092 --topic hello_topic --from-beginning
--from-beginning 就是从头开始消费的意思
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值