[Kafka]_0

Kafka支持的基本命令位于${KAFKA_HOME}/bin文件夹中,主要是kafka-topics.sh命令;Kafka命令参考页面: kafka-0.8.x-帮助文档

 

 -1. 查看帮助信息

bin/kafka-topics.sh --help

 

-2. 创建Topic

bin/kafka-topics.sh --create --topic test0 --zookeeper 192.168.187.146:2181 --config max.message.bytes=12800000 --config flush.messages=1 --partitions 5 --replication-factor 1

--create: 指定创建topic动作

--topic:指定新建topic的名称

--zookeeper: 指定kafka连接zk的连接url,该值和server.properties文件中的配置项{zookeeper.connect}一样

--config:指定当前topic上有效的参数值,参数列表参考文档为: Topic-level configuration

--partitions:指定当前创建的kafka分区数量,默认为1个

--replication-factor:指定每个分区的复制因子个数,默认1个

 

-3. 查看当前Kafka集群中Topic的情况

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

 

-4. 查看对应topic的描述信息

bin/kafka-topics.sh --describe --zookeeper 192.168.187.146:2181  --topic test0

--describe: 指定是展示详细信息命令

--zookeeper: 指定kafka连接zk的连接url,该值和server.properties文件中的配置项{zookeeper.connect}一样

--topic:指定需要展示数据的topic名称

 

-5. Topic信息修改

bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --config max.message.bytes=128000
bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --delete-config max.message.bytes
bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --partitions 10
bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --partitions 3 ## Kafka分区数量只允许增加,不允许减少

 

-6. Topic删除

默认情况下Kafka的Topic是没法直接删除的,需要进行相关参数配置

bin/kafka-topics.sh --delete --topic test0 --zookeeper 192.168.187.146:2181

Note: This will have no impact if delete.topic.enable is not set to true.## 默认情况下,删除是标记删除,没有实际删除这个Topic;如果运行删除Topic,两种方式:
方式一:通过delete命令删除后,手动将本地磁盘以及zk上的相关topic的信息删除即可
方式二:配置server.properties文件,给定参数delete.topic.enable=true,重启kafka服务,此时执行delete命令表示允许进行Topic的删除

 

在Hadoop 1.0.4环境中使用Apache Flume处理数据流时,通常会在每个节点的`conf`目录下的`flume`子目录中创建配置文件,例如`job/kafka_to_hdfs_log.conf`。这个文件用于定义Flume的Source(源)、Channel(通道)和Sink(sink),以便从Kafka消费数据并将它们写入HDFS。 以下是一个简单的`kafka_to_hdfs_log.conf`配置示例: ```properties # 定义source - Kafka Source agent.sources.kafka_source = org.apache.flume.source.KafkaSource agent.sources.kafka_source.bootstrap.servers = <kafka_server_ip>:9092 agent.sources.kafka_source.topic = <input_topic> agent.sources.kafka_source.group.id = flume_group # 定义channel - Memory Channel agent.channels.memory_channel = org.apache.flume.channel.MemoryChannel # 将source连接到channel agent.sources.kafka_source.channels = memory_channel # 定义sink - HDFS Sink agent.sinks.hdfs_sink = org.apache.flume.sink.HDFS sink agent.sinks.hdfs_sink.channel = memory_channel agent.sinks.hdfs_sink.hdfs.path = /path/to/hdfs/directory agent.sinks.hdfs_sink.hdfs.filePrefix = kafka_data_ # 配置Agent并启动 agent.sources = kafka_source agent.channels = memory_channel agent.sinks = hdfs_sink agent.root.channels = memory_channel agent.sources.kafka_source.startOnLoad=true agent.sinks.hdfs_sink.startOnLoad=true # 启动Flume agent bin/flume-ng start -f conf/kafka_to_hdfs_log.conf ``` 在这个例子中,你需要替换`<kafka_server_ip>`、`<input_topic>`以及`/path/to/hdfs/directory`为你实际的Kafka服务器地址、输入主题和HDFS目标路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值