kafka集群搭建

本文详细介绍Kafka 2.11的下载、配置及集群部署步骤,包括配置文件server.properties的修改要点,如broker.id设置、listeners绑定、日志路径指定及Zookeeper连接等。此外还介绍了基本命令操作,如启动服务、创建主题、查看所有主题、描述主题详情、写入消息及接收消息等。
1.  kafka2.11下载并解压


2.  修改配置文件


    · config/server.properties
broker.id=4(集群里的id不能重复,我是取每台机器IP最后一位)
listeners=PLAINTEXT://192.168.248.134:9092(格式不变,绑定本机IP)
log.dirs=/home/hadoop/kafka/logs4kafka(日志路径)
zookeeper.connect=h2:2181,h3:2181,h4:2181,h8:2181,h9:2181,h10:2181
最后一项时延可以增大一些,曾经因为超过时延而报错,修改成10倍就OK了
    · producer.properties
bootstrap.servers=h2:9092,h3:9092,h4:9092,h8:9092,h9:9092,h10:9092
    · consumer.properties
zookeeper.connect=h2:2181,h3:2181,h4:2181,h8:2181,h9:2181,h10:2181
group不配的话就是默认,看需求
3.拷贝到其他节点,注意修改listeners绑定的IP和broker.id


4 基本命令


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


#create a topic
bin/kafka-topics.sh --create --zookeeper h2:2181,h3:2181,h4:2181,h8:2181,h9:2181,h10:2181 --replication-factor 5 --partition 5 --topic T20161021




#list all topics
bin/kafka-topics.sh --zookeeper h2:2181,h3:2181,h4:2181,h8:2181,h9:2181,h10:2181 --list


#describe the detail of this topic
bin/kafka-topics.sh --describe --zookeeper h2:2181,h3:2181,h4:2181,h8:2181,h9:2181,h10:2181  --topic test101




#write some Messages to the topic
bin/kafka-console-producer.sh --broker-list h2:9092 --topic T20161021






#recerive the message producer writed
bin/kafka-console-consumer.sh --zookeeper h2:2181,h3:2181,h4:2181,h8:2181,h9:2181,h10:2181 --topic T20161021 --from-beginning

















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值