kafka常用操作

kafka运维常用查询操作总结以下几点:


kafka生产和消费消息测试

发送:bin/kafka-console-producer.sh --broker-list 10.46.200.165:9092 --topic contentApprove
接收:bin/kafka-console-consumer.sh --bootstrap-server 10.46.200.165:9092 --topic contentApprove --from-beginning

创建topic命令参考

.bin/kafka-topics.sh --create --zookeeper localhost:2181 --partitions 6 --replication-factor 2 --topic test
### --partition:创建分区数,一般可以是服务器数量的双倍
### --replication-factor:副本数默认为1,表示没有副本。保证冗余必须最少2

kafka修改副本数

bin/kafka-reassign-partitions.sh --zookeeper 10.124.77.41:2181 --reassignment-json-file test.json –execute

将分区数3修改为9

bin/kafka-topics.sh --zookeeper localhost:2181 --partitions 9 --alter --topic test

查询日志过大阻塞

## 最长行
awk '{if (length(max)<length()) max=$0}END{print max}' flume.log > /tmp/long.txt

## 最短行
awk '(NR==1||length(min)>length()){min=$0}END{print min}' data.txt

topic堆积查询需要用到的命令

## 查询topic
bin/kafka-topics.sh --zookeeper 10.124.14.52:2181 –list 

## 查某个topic描述信息
bin/kafka-topics.sh --zookeeper 10.124.14.52:2181 --describe --topic test

## 查看组列表
bin/kafka-consumer-groups.sh --bootstrap-server 10.124.14.57:9092 –list

## topic组堆积情况
bin/kafka-consumer-groups.sh --bootstrap-server 10.124.14.57:9092 --describe --group test_group

## 删除某个topic
kafka/bin/kafka-topics.sh --delete --zookeeper 10.124.14.52:2181 --topic test

elasticsearch查询

## 查询索引情况
curl -sk https://user:password@10.124.14.46:9200/_cat/indices?v

## 查询elastic集群状态
curl -k https://user:password@10.124.10.27:9200/_cluster/health

flume启动参考

nohup /data/flume/run/flume/bin/flume-ng agent --conf /data/flume/run/flume/conf/conf.d/ --conf-file /data/flume/run/flume/conf/conf.d/test_prod.conf --name test_prod -Dflume.codeadmin.logger=INFO,console &

启动jar包+指定端口

nohup /usr/local/jdk1.8/bin/java -XX:+UseConcMarkSweepGC -Xmx3g -Xms3g -Dserver.port=8071 -jar /data/jenkins_run/jar_home/release/h5-oms_release/h5-oms-0.0.1-SNAPSHOT.jar --spring.profiles.active=release --spring.cloud.inetutils.preferred-networks=10.46.169 > /dev/null 2>&1 &
原文地址:https://www.cnblogs.com/jiba/p/12640195.html