• Kafka 集群管理


    后台和停止kafka服务

     

    注意事项: 生产环境推荐使用-daemon参数后台启动kafka,然后搭配使用nohup&

    如果不想使用kafka-server-stop.sh 关闭一台机器上的所有kafka broker,还可以使用另一种方式,首先jps查看kafka的pid,然后运行ps ax | grep -i 'kafka/Kafka' | grep java | grep -v grep | awk '${print $1}'自行寻找Kafka的PID ,最后运行kill -s TERM $PID关闭broker。

    Topic管理/命令行脚本

    创建topic

    • 自动分区分配
    bin/kafka-topics.sh --create --zookeeper localhost:2181 --partitions 6 --replication-factor 3 
    --topic topic-manager-test --config delete.retention.ms=259200000

    最后一个参数是日志存留天数3天

    • 手动分配分区
    bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic topic-manager-test2 --replica-assignment 0:1,1:2,0:2,1:2

    假设有三个broker的集群,序号为0,1,2 ,4个分区,2个副本 ,通过replica-assignment指定

    删除topic

    bin/kafka-topics.sh --delete -zookeeper localhost:2181 --topic topic-manager-test
    Topic topic-manager-test is marked for deletion.
    Note: This will have no impact if delete.topic.enable is not set to true.

    需要设置delete.topic.enable=true才会真正删除,这里只是打上删除标记

    查询topic列表

    bin/kafka-topics.sh --zookeeper localhost:2181 --list

    查询topic详情

    bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic topic-manager-test2
    Topic:topic-manager-test2	PartitionCount:4	ReplicationFactor:2	Configs:
    Topic: topic-manager-test2 Partition: 0 Leader: 0 Replicas: 0,1 Isr: 0,1
    Topic: topic-manager-test2 Partition: 1 Leader: 1 Replicas: 1,2 Isr: 1,2
    Topic: topic-manager-test2 Partition: 2 Leader: 0 Replicas: 0,2 Isr: 0,2
    Topic: topic-manager-test2 Partition: 3 Leader: 1 Replicas: 1,2 Isr: 1,2

    使用kafka-configs.sh脚本查看

    bin/kafka-configs.sh --describe --zookeeper localhost:2181 --entity-type topics --entity-name topic-manager-test2

    查看所有的主题详细信息

    bin/kafka-topics.sh --zookeeper localhost:2181 --describe

    修改toipc

    kafka允许用户对topic的某些参数如分区数,副本因子和topic级别的参数进行设置

    • 增加topic分区, 从4个分区到10个
    bin/kafka-topics.sh --alter --zookeeper localhost:2181 --partitions 10 --topic topic-manager-test2

    不支持减少分区

    • 推荐使用kafka-configs.sh配置,下面是在topic参数添加cleanup.policy=compact配置
    bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics 
    --entity-name topic-manager-test2 --add-config cleanup.policy=compact
    • 确认参数是否成功
    bin/kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type topics --entity-name topic-manager-test2

    删除topic配置

    bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name topic-manager-test2 --delete-config prealloocate

    附录

    • 常见的topic级别的参数和含义
    参数名参数含义
    cleanup.policy topic的留存策略
    compression.type 指定topic的压缩类型
    max.message.bytes broker能够接收该topic消息的最大长度
    min.insync.replicas 指定ISR中需要接收topic消息的最少的broker数,与producer端的acks=1配合使用
    preallocate 是否为该topic日志文件提前分配存储空间
    retention.ms 指定持有该topic单个分区消息的最长时间
    segment.bytes 指定topic日志段文件的大小
    unclean.leader.election.enable 是否为topic启用unclean选举

    开启JMX端口的方法

    为了实时监控kafka的健康程度,需要开启JMX端口

    前台启动broker: JMX_PORT=9997 bin/kafka-server-start.sh config/server.properties

    后台启动broker: export JMX_PORT=9997 bin/kafka-server-start.sh -daemon config/server.properties

     
  • 相关阅读:
    ios学习-2015-7-9
    ios学习-2015-7-8
    ios学习-2015-7-7
    ios学习-2015-7-6
    ios学习-2015-7-5
    ios学习-2015-7-3
    ios学习-2015-7-2
    Selenium学习笔记之003:Web UI自动化知识点整理 分类: Selenium 2015-07-14 14:19 3人阅读 评论(0) 收藏
    Selenium学习笔记之002:IDE录制和回放 分类: Selenium 2015-07-12 17:13 19人阅读 评论(0) 收藏
    Selenium学习笔记之002:IDE录制和回放
  • 原文地址:https://www.cnblogs.com/fubinhnust/p/11967930.html
Copyright © 2020-2023  润新知