kafka_2.11-1.1.1.tar
zookeeper-3.4.5-cdh5.7.0.tar
1、解压
tar -zxvf kafka_2.11-1.1.1.tar -C /app
tar -zxvf zookeeper-3.4.5-cdh5.7.0.tar -C /app
创建软连接
ln -s kafka_2.11-1.1.1 kafka
ln -s zookeeper-3.4.5-cdh5.7.0 zookeeper
2、配置启动zookeeper
cd zookeeper/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
# 配置数据日志文件
dataDir=/home/hadoop/app/zookeeper/data
dataLogDir=/home/hadoop/app/zookeeper/logs
# the port at which the clients will connect
# 配置端口
clientPort=2181
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
配置好后,启动zk
cd zookeeper
bin/zkServer.sh start
bin/zkServer.sh status 查看zk服务是否正常启动 这里是单节点,显示为standalone。
3、配置启动kafka
cd kafka/config
vi server.properties 因为是单节点 这里只需改动两个地方
>>
log.dirs=/home/hadoop/app/kafka/logs
zookeeper.connect=localhost:2181/kafka 这里再后面加上/kafka是方便以后的管理,因为kafka启动后会在zookeeper上创建一个kafka节点,如果直接在zk第一级目录创建kafka的相关信息,之后想手动管理kafka的相关信息时不好定位哪些目录是属于kafka的。所以加上/kafka后,kafka的相关目录都会创建在/kafka下,方便管理。
启动kafka
nohup bin/kafka-server-start.sh config/server.properties &
jps 查看进程是否成功启动
14835 QuorumPeerMain
17238 Jps
15082 Kafka
4、测试
创建topic
bin/kafka-topics.sh --create --zookeeper localhost:2181/kafka --replication-factor 1 --partitions 1 --topic test
查看topic
bin/kafka-topics.sh --list --zookeeper localhost:2181/kafka
创建producer
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
创建consumer
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
我们在producer端输入一些信息,可以在consumer端消费到。测试成功。
在创建topic的时候,报错
Replication factor: 1 larger than available brokers: 0
这个问题是自己粗心大意了,因为我在配置kafka在zk的目录的时候加上了/kafka,而在创建topic的时候,使用
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
它在zk第一级目录上找不到broker的相关信息,所以报错。正确的命令应该是
bin/kafka-topics.sh --create --zookeeper localhost:2181/kafka --replication-factor 1 --partitions 1 --topic test
在查看topic的时候也是一样,需要加上/kafka
bin/kafka-topics.sh --list --zookeeper localhost:2181/kafka