kafka部署配置及常用命令总结

部署配置

1.准备部署包(自行下载)
2.配置zk

vim conf/zoo.cfg

dataDir=/data/vfan/zk/data/
dataLogDir=/data/vfan/zk/logs/
startLogDir=/data/vfan/zk/logs/
clientPort=2181
maxClientCnxns=0
initLimit=5
syncLimit=2
server.1=10.61.194.34:2801:3801
server.2=10.61.199.15:2802:3802
server.3=10.61.202.16:2803:3803
# server.A=B:C:D 其中A是一个数字,代表这是第几号服务器;B是服务器的IP地址;C表示服务器与群集中的“领导者”交换信息的端口;当领导者失效后,D表示用来执行选举时服务器相互通信的端口
snapCount=20
autopurge.snapRetainCount =3
autopurge.purgeInterval =1

zk集群配置如上,如果是单台,从server.1开始往下都注释即可

启动zk

bin/zkServer.sh start
## ps 检查进程
2.配置kafka

vim kafka/config/server.properties

broker.id=1
listeners=PLAINTEXT://10.153.204.28:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/data/vfan/kfk/logs/
# 当topic不存在系统自动创建时的分区数
num.partitions=3
# 当topic不存在系统自动创建时的副本数
default.replication.factor=3
# offset topic的replicas数量
offsets.topic.replication.factor=3
# 每个数据目录的线程数,用于启动时的日志恢复和关闭时的刷新
num.recovery.threads.per.data.dir=1
# 事务主题的复制因子
transaction.state.log.replication.factor=3
# 覆盖事务主题的min.insync.replicas配置
transaction.state.log.min.isr=3
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=10.61.194.34:2181,10.61.199.15:2181,10.61.202.16
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0

集群模式时,修改每个配置文件的 broker.id listeners 即可,zookeeper.connect若为单机就写一个

启动kafka

bin/kafka-server-start.sh -daemon config/server.properties
## ss -tnlp|grep 9092 检查端口

常用命令总结

topic相关
## 查看所有topic
./kafka-topics.sh --zookeeper localhost:2181 --list

## 查看所有topic详情(副本、分区、ISR等)
./kafka-topics.sh --zookeeper localhost:2181 --describe

## 查看某个topic详情
./kafka-topics.sh --zookeeper localhost:2181 --describe --topic test

## 创建topic,3副本 3分区
./kafka-topics.sh --zookeeper localhost:2181 --create --topic test --replication-factor 3 --partitions 3

## 调整分区数量
./kafka-topics.sh --alter --zookeeper localhost:2181 --topic test --partitions 3

## 删除topic,需要将参数设置为delete.topic.enable=true,如果还是删不了则删除kafka中的所有分区log,及通过zk客户端删除
./kafka-topics.sh --zookeeper localhost:2181 --delete --topic test

## 查看topic各个分区的消息数量
./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --time -1 --topic test
模拟kafka生产消费
## 生产
./kafka-console-producer.sh --broker-list 10.153.204.28:9092 --topic test

## 消费,--from-beginning参数表示从头开始
./kafka-console-consumer.sh --bootstrap-server 10.153.204.28:9092 --topic test --from-beginning

此处需要注意,生产者和测试者指定的broker必须和配置文件中zookeeper.connect和listeners中的地址一至,如写localhost生产者会类似如下信息:

WARN [Producer clientId=console-producer] Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

消费者会报错类似错误:

WARN [Consumer clientId=consumer-1, groupId=console-consumer-8350] Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

消费者相关
## 显示所有消费者
./kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --list

## 获取某消费者消费某个topic的offset
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group test-consumer

## 调整消费者对某个topic的offset,发生阻塞等情况时可使用
.kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupName --reset-offsets --to-offset 1000 --topic topicName --execute
调整默认分区副本数
## 配置文件中指定默认分区 副本数
num.partitions=3 ;当topic不存在系统自动创建时的分区数
default.replication.factor=3 ;当topic不存在系统自动创建时的副本数
offsets.topic.replication.factor=3 ;表示kafka的内部topic consumer_offsets副本数,默认为1
调整topic分区副本数

目前 guoqing 的topic副本和分区都为1

./kafka-topics.sh --zookeeper localhost:2181 --describe --topic guoqing
Topic:guoqing PartitionCount:1 ReplicationFactor:1 Configs:
Topic: guoqing Partition: 0 Leader: 1 Replicas: 1 Isr: 1

将分区数调整为3

## 扩容
./kafka-topics.sh --alter --zookeeper localhost:2181 --topic guoqing --partitions 3
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!

## 检查
./kafka-topics.sh --zookeeper localhost:2181 --describe --topic guoqing
Topic:guoqing PartitionCount:3 ReplicationFactor:1 Configs:
Topic: guoqing Partition: 0 Leader: 1 Replicas: 1 Isr: 1
Topic: guoqing Partition: 1 Leader: 2 Replicas: 2 Isr: 2
Topic: guoqing Partition: 2 Leader: 3 Replicas: 3 Isr: 3

注意:分区数只能增加,不能减少

将副本数调整为3,首先准备json文件,格式如下:

vim guoqing.json

{
"version": 1,
"partitions": [
{
"topic": "guoqing",
"partition": 0,
"replicas": [
1,
2,
3
]
},
{
"topic": "guoqing",
"partition": 1,
"replicas": [
2,
1,
3
]
},
{
"topic": "guoqing",
"partition": 2,
"replicas": [
3,
2,
1
]
}
]
}

执行调整命令

./kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file /tmp/guoqing.json --execute
Current partition replica assignment

{"version":1,"partitions":[{"topic":"guoqing","partition":0,"replicas":[1],"log_dirs":["any"]},{"topic":"guoqing","partition":2,"replicas":[3],"log_dirs":["any"]},{"topic":"guoqing","partition":1,"replicas":[2],"log_dirs":["any"]}]}

Save this to use as the --reassignment-json-file option during rollback
Successfully started reassignment of partitions.

检查调整进度

./kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file /tmp/guoqing.json --verify
Status of partition reassignment:
Reassignment of partition guoqing-0 completed successfully
Reassignment of partition guoqing-1 completed successfully
Reassignment of partition guoqing-2 completed successfully

检查调整后的状态

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

kafka部署配置及常用命令总结(运维必备)的更多相关文章

  1. (Linux环境Kafka集群安装配置及常用命令

    Linux环境Kafka集群安装配置及常用命令 Kafka 消息队列内部实现原理 Kafka架构 一.下载Kafka安装包 二.Kafka安装包的解压 三.设置环境变量 四.配置kafka文件 4.1 ...

  2. ansible环境部署及常用模块总结 - 运维笔记

    一.  Ansible 介绍Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于py ...

  3. 工作中常用Linux命令--服务器运维

    工作中常用Linux命令--服务器运维 lsof查看端口使用情况 lsof -i:8080更多lsof命令使用说明:http://www.cnblogs.com/peida/archive/2013/ ...

  4. centos7系统管理和运维实战——运维必备的网络管理技能(1)

    运维必备的网络管理技能 一.网络管理协议: 1.简单的两个概念:    DHCP(动态主机配置协议):如果网络结构要更改,需要从新初始化网络参数,手机用动态主机配置协议可以避免这个问题.客户端可以从D ...

  5. 简单记录五个Linux设置定时任务的步骤(自动化运维必备)

    这几天我们国庆节休息,但是作为运维工作的同学们是不是也不能闲着,担心工作中是不是有任务在执行中需要维护.于是,我们很多的运维工作都是用的自动化运维监控,如果有故障都会定时的处理和告警的.这个与我们的L ...

  6. supervisor 安装、配置、常用命令

    前言 在 web 应用部署到线上后,需要保证应用一直处于运行状态,在遇到程序异常.报错等情况,导致 web 应用终止时,需要保证程序可以立刻重启,继续提供服务. 所以,就需要一个工具,时刻监控 web ...

  7. nginx 配置以及常用命令

    windows下安装以及配置nginx http://jingyan.baidu.com/article/f3e34a12a9c1c3f5eb6535d4.html 1)下载地址: http://ng ...

  8. Java学习系列(一)Java的运行机制、JDK的安装配置及常用命令详解

    俗话说:“十五的月亮十六圆”.那学习是不是也是如此呢?如果把月亮看成是我们的愿望,那十五便是我们所处的“高原期”,坚持迈过这个坎,我相信你的愿望终究会现实的.记得马云曾说:今天很残酷,明天更残酷,后天 ...

  9. [转]supervisor 安装、配置、常用命令

    原文: http://www.cnblogs.com/xueweihan/p/6195824.html ------------------------------------------------ ...

  10. Git的配置及常用命令

    Git配置 git config --global user.name "<username>" git config --global user.email &quo ...

随机推荐

  1. NXP i.MX 8M Plus工业开发板硬件说明书( 四核ARM Cortex-A53 + 单核ARM Cortex-M7,主频1.6GHz)

    前  言 本文主要介绍创龙科技TLIMX8MP-EVM评估板硬件接口资源以及设计注意事项等内容. 创龙科技TLIMX8MP-EVM是一款基于NXP i.MX 8M Plus的四核ARM Cortex- ...

  2. 【Hive报错】在hue上执行自定义的hive函数报错 Error while compiling statement:FAILED:SemanticException [Error 10011]: Invalid function default.sqlServerdes

    在 Hive客户端中使用自定义创建UDF函数时,报"ERROR 10011","invalid function"的异常: 在Hive上自定义创建了一个函数,在 ...

  3. python3 requests 请求https报错: urllib3.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:992)

    正文 代码示例: #-*- coding:utf-8 -*- import requests url = "https://tst.com" res = requests.get( ...

  4. Kubernetes(K8S)基本概念

    前言 有公司用 java 或 go , vue 或 react , linux 或 win ,但所有的大厂都在用k8s,没有或,而且是全世界.一个熟悉k8s的开发,薪资可以轻松上25的 base . ...

  5. flutter 一直卡在Running Gradle task 'assembleDebug'...运行不起来

    大概率只有一个原因:gradle下载不完整! 要想办法让他下载完整! 解决方法: 方法一:修改远程maven仓库地址(2024.7.9下列地址可用) repositories{ maven{ url' ...

  6. 全网最适合入门的面向对象编程教程:05 类和对象的Python实现-PyCharm代码标签(一个帮你提升coding效率的小技巧)

    摘要: 本文介绍了PyCharm IDE中代码标签的定义.类型和使用方法. 往期推荐: 学嵌入式的你,还不会面向对象??! 全网最适合入门的面向对象编程教程:00 面向对象设计方法导论 全网最适合入门 ...

  7. python配置国内pypi镜像源操作步骤

    使用pip config命令设置默认镜像源,使用国内的源,提高安装速度 操作步骤 临时方式pip install xxx -i https://pypi.tuna.tsinghua.edu.cn/si ...

  8. 第六节 JMeter基础-中级登录【用户自定义变量】

    1.认识JMeter (1)配置元件:配置对应的一些数据 (例如:HTTP请求默认值.用户定义的变量) (2)[HTTP请求默认值]:HTTP请求默认值是设置的Web服务器部分信息,可以贯穿多个接口. ...

  9. 学习笔记--Java中this关键字

    Java中this关键字 关于Java语言中的this关键字 this 是一个关键字,翻译为:这个 this 是一个引用,一个变量,this变量中保存的内存地址指向自身 每一个对象都有自己的this, ...

  10. 巧用 QLineF 从 QTransform 提取角度

    我们在对 QGraphicsItem 进行变换时,QT 提供了很多便捷的方法.但当我们想获取当前变换的角度时却有些困难,因为 QTransform 没有提供获取角度的方法.在文章Qt 从 QTrans ...