部署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 就是从头开始消费的意思