kafka的安装需要jdk的支持,所以需确保系统已装有jdk:
http://blog.dongguagua.com/Index/detail/Id/40.html
下载合适的kafka版本:
http://kafka.apache.org/downloads.html
选择Binary downloads下载 (Source download需要编译才能使用)
也可以直接在linux终端下载:
wget -q http://apache.fayea.com/apache-mirror/kafka/0.8.1/kafka_2.8.0-0.8.1.tgz
解压:
tar -xzvf kafka_2.8.0-0.8.1.tgz rm kafka_2.8.0-0.8.1.tgz -rf cd kafka_2.8.0-0.8.1
修改配置:
Kafka默认开启JVM压缩指针,但只是在64位的HotSpot VM受支持,如果安装了32位的HotSpot VM,需要修改/bin/kafka-run-class.sh文件
vim bin/kafka-run-class.sh
找到如下行
KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true"
去除-XX:+UseCompressedOops参数
启动Zookeeper server:
nohup bin/zookeeper-server-start.sh config/zookeeper.properties &
启动Kafka server:
nohup bin/kafka-server-start.sh config/server.properties &
停止Kafka server:
bin/kafka-server-stop.sh
停止Zookeeper server:
bin/zookeeper-server-stop.sh
单机连通性测试
运行producer:
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
早版本的Kafka,--broker-list localhost:9092需改为--zookeeper localhost:2181
运行consumer:
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
在producer端输入字符串并回车,查看consumer端是否显示。
单机版如果希望其他主机请求接入,需在server.property中加上以下配置:
port=9092 host.name=192.168.2.221
kafka删除topic方法
在配置文件serve.properties里配置delete.topic.enable=true
若没有该条配置项,则手动添加,重启服务
1)运行删除命令
kafka-topics.sh --delete --zookeeper host:port --topic topicname
2)删除kafka存储目录(server.properties文件log.dirs配置,默认为"/tmp/kafka-logs")相关topic目录删除zookeeper "/brokers/topics/"目录下相关topic节点
在kafka使用期间可能遇到的错误:
default info:“no brokers found when trying to rebalance” reply to the problem: by default kafka stores all the information in the /tmp folder. The tmp folder gets deleted everytime you restart. You can change the placement of those files by changing in the properties file config/server.properties the property log.dirs
解决方法:修改config/server.properties 中配置项 log.dirs 的路径,最好不要放在临时目录/tmp中。
重新分配partition
bin/kafka-topics.sh --zookeeper host:port --topic topicname --alter --partitions 3
将topicname的partition增加到3个,这里只能做增加,不能减少
kafka自带的zookeeper客户端
bin/zookeeper-shell.sh --zookeeper host:port
相关博文
php扩展rdkafka的安装http://blog.dongguagua.com/Index/detail/Id/42.html
php扩展rdkafka的使用http://blog.dongguagua.com/Index/detail/Id/39.html
参考博文
http://czj4451.iteye.com/blog/2041096
http://www.osyunwei.com/archives/9252.html