Kafka安装和配置,依赖zookeeper
安装和启动zookeeper
(1)下载
http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
(2)解压
tar zxvf zookeeper-3.4.6.tar.gz
(3)配置
cd zookeeper-3.4.6
cp -rf conf/zoo_sample.cfg conf/zoo.cfg
vim zoo.cfg
将里边的目录配置成为:
dataDir=/Users/apple/Documents/soft/zookeeper_soft/zkdata #这个目录是预先创建的
(4)启动zookeeper
cd bin
sh zkServer.sh start
安装和配置kafka
(1)下载
http://apache.fayea.com/kafka/0.8.2.1/kafka_2.10-0.8.2.1.tgz
(2)解压
tar -zxf kafka_2.10-0.8.2.1.tgz
(3)配置config
vim server.properties
配置kafka的端口号
port=9092
配置ip地址
host.name=localhost
配置log路径
log.dirs=~/changxiaohui/kafka-logs
# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181 (配置zookeeper,这里可以写的localhost或者IP地址,但是一定要与produce 写消息的时候保持一致)
# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000
(4)在后台启动kafka服务,只需要后边加上&就可以了
sh bin/kafka-server-start.sh config/server.properties &
(5)创建topic
sh kafka-topics.sh --create --topic kafkatopic --replication-factor 1 --partitions 1 --zookeeper localhost:2181 &
(6)生产者写东西
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic kafkatopic (这个命令中的locahost需要和server.properties中的host.name=localhost保持一致,是ip这里就要写成ip)
操作命令如下:
MacBook-Air-2:kafka $ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic kafkatopic
[2016-01-24 12:19:01,401] WARN Property topic is not valid (kafka.utils.VerifiableProperties)
测试
(7)消费者读东西,同一个topic
操作命令如下:
MacBook-Air-2:kafka $ bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafkatopic --from-beginning
网友评论