kafka常用脚本及参数解释

启动

$ nohup  ./bin/kafka-server-start.sh  ./config/server.properties  &

[root@master ~]# jps

3098 ZooKeeperMain

3037 Kafka

创建topic

$ bin/kafka-topics.sh --zookeeper 192.168.1.107:2181,192.168.1.108:2181

   --topic topicName --replication-factor 1 --partitions 1 --create

其中, --topic 定义topic名

            --replication-factor  定义副本数

            --partitions  定义分区数

查看全部Topic

bin/kafka-topics.sh --zookeeper 192.168.1.107:2181,192.168.1.107:2181 --list

删除Topic:

./bin/kafka-topics.sh --topic topicName –zookeeper \ 192.168.1.107:2181,192.168.1.107:2181 --delete

查看Topic明细:

./kafka-topics.sh --topic test --describe --zookeeper 192.168.1.107:2181,192.168.1.107:2181

生产和消费

Productor

bin/kafka-console-producer.sh --broker-list  

192.168.1.107:9092,192.168.1.108:9092 --topic topicName

Consumer:

bin/kafka-console-consumer.sh --zookeeper 192.168.1.107:2181,192.168.1.107:2181 --topic topicName --from-beginning

 

 

服务端config/server.properties 中配置项:

 

 

broker.id

整数,建议根据ip区分

 

log.dirs

kafka存放消息文件的路径,

默认/tmp/kafka-logs

port

broker用于接收producer消息的端口

9092

zookeeper.connnect

Zookeeper server 列表

格式为  ip1:port,ip2:port,ip3:port

message.max.bytes

单条消息的最大长度

 

num.network.threads

broker用于处理网络请求的线程数

如不配置默认为3,server.properties默认是2

num.io.threads

broker用于执行网络请求的IO线程数

如不配置默认为8,server.properties默认是2可适当增大,

queued.max.requests

排队等候IO线程执行的requests

默认为500

host.name

broker的hostname

默认null,建议写主机的ip,不然消费端不配置hosts会有麻烦

num.partitions

topic的默认分区数

默认2

log.retention.hours

消息被删除前保存多少小时

默认1周168小时

auto.create.topics.enable

是否可以程序自动创建Topic

默认true,建议false

default.replication.factor

消息备份数目

默认1不做复制,建议修改

num.replica.fetchers

用于复制leader消息到follower的IO线程数

默认1

Consumer设置

Consumer从kafka集群消费(pull或push方式)数据,并控制获取消息的offset偏移量。

Property

Default

Description

group.id

 

可用于标识部门,it1it2…

zookeeper.connect

 

ZK Server 列表

consumer.id

null

自动生成,不需设置

socket.timeout.ms

30 * 1000

 

socket.receive.buffer.bytes

64 * 1024

The socket receive buffer for network requests

auto.commit.enable

true

定期写offsetsZK中,记录消费过的位置,程序重新消费时可从zk里读取位置继续消费

auto.commit.interval.ms

60 * 1000

offsetsZK的频率,多久写一次

auto.offset.reset

largest

What to do when there is no initial offset in ZooKeeper or if an offset is out of range:
* smallest : automatically reset the offset to the smallest offset
* largest : automatically reset the offset to the largest offset
* anything else: throw exception to the consumer

 

转载于:https://my.oschina.net/iioschina/blog/828163

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值