centos(linux/debian)安装kafka

基于dockers
(1) 启动容器:docker exec -it a6f9aca2fe6 /bin/bash
(2) 启动zk:kafka依赖zookeeper,需要先启动zookeeper。
• 安装包自带zookeeper,可以直接启动,如果已经单独安装zookeeper的话,就不需要重启启动.
• 如果启动kafka内部自带的zookeeper,修改下zookeeper的配置文件,修改端口,不要造成端口冲突,zk的默认端口是2181。 启动命令:
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
1、 修改配置文件:
cd /usr/app/kafka_2.12-2.3.0/config/
vim server.properties


配置broker.id必须是一个整数,且不可以和其他的kafak代理节点的值重复,即每个kafka节点为一个broker,拥有唯一的id值。
2、启动kafka
/usr/local/kafka_2.12-2.3.0/bin/kafka-server-start.sh /usr/local/kafka_2.12-2.3.0/config/server.properties
3、topic
创建一个topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic weather2018
(1)查看 topic 列表
/usr/local/kafka_2.12-2.3.0/bin/kafka-topics.sh --list --zookeeper localhost:2181
(2)查看指定topic信息
bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic weather2018
(3)查看topic某分区偏移量最大(小)值
./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --topic dhx --time -1 --broker-list localhost:9092 --partitions 0
:weather2018:0:112489
:dhx:0:40
注: time为-1时表示最大值,time为-2时表示最小值
(4)增加topic分区数
为topic t_cdr 增加10个分区
bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic weather2018 --partitions 10
(5)删除topic
慎用,只会删除zookeeper中的元数据,消息文件须手动删除
bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --zookeeper localhost:2181 --topic weather2018
(6)查看topic消费进度
./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic weather2018 --time -1
5、产生消息
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic weather2018
6、消费消息
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic weather2018 --from-beginning


(1)错误:
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic weather2018 --from-beginning
(2)查看:netstat -ntlp

实例:在生产者端,输入数据,如下:
{“time”:“2019-08-29T09:00:22.770Z”,“name”:“zhrj”,“age”:“4”}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值