kafka常见操作(kafka_2.10-0.8.2.2)

kafka常见操作(版本:kafka_2.10-0.8.2.2)

服务操作

1. 启动kafka服务
./bin/kafka-server-start.sh -daemon config/server.properties

Topic操作

1. 创建Topic
batman:~/kafka_2.10-0.8.2.2$ ./bin/kafka-topics.sh --create --topic test-topic --partitions 2 --replication-factor 3 --zookeeper 192.168.103.46:2181
  • 说明:
2. 删除Topic
ubuntu@batman:~/kafka_2.10-0.8.2.2$ ./bin/kafka-topics.sh --delete --topic test-topic  --zookeeper 192.168.103.46:2181
Topic test-topic is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.

ubuntu@batman:~/kafka_2.10-0.8.2.2$ ./bin/kafka-topics.sh --list --zookeeper 192.168.103.46:2181
shiquan-topic
shiquan-topic3
test-topic - marked for deletion
  • 说明:看来没有真正的删除,如需delete后立即删除,要改配置的。
3. 显示当前所有Topic
ubuntu@batman:~/kafka_2.10-0.8.2.2$ ./bin/kafka-topics.sh --list --zookeeper 192.168.103.46:2181
test-topic
user-behavior-topic
wordcount
4. 显示指定Topic详细信息
ubuntu@batman:~/kafka_2.10-0.8.2.2$ ./bin/kafka-topics.sh --describe --topic test-topic --zookeeper 192.168.103.46:2181
Topic:test-topic    PartitionCount:2    ReplicationFactor:3 Configs:
    Topic: test-topic   Partition: 0    Leader: 2   Replicas: 2,0,1 Isr: 2,0,1
    Topic: test-topic   Partition: 1    Leader: 0   Replicas: 0,1,2 Isr: 0,1,2
5. 通过consumer客户端查看Topic内容
wonderwoman:~/kafka_2.10-0.8.2.2$ ./bin/kafka-console-consumer.sh --topic storm-topic --zookeeper 192.168.103.44:2181 --from-beginning
  • 说明:
--from-beginning                        If the consumer does not already have  
                                          an established offset to consume     
                                          from, start with the earliest        
                                          message present in the log rather    
                                          than the latest message.   
kafka_2.9.2-0.8.2.1.tgz 安装 liunx环境 安装jdk vi /etc/profile在末尾追加 JAVA_HOME JRE_HOME PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib source /etc/profile使环境变量立刻生效 安装kafka 解压 tar -xzvf kafka_2.8.0-0.8.1.tgz ;rm kafka_2.8.0-0.8.1.tgz; cd kafka_2.8.0-0.8.1 修改配置 Kafka默认开启JVM压缩指针,但只是在64位的HotSpot VM受支持,如果安装了32位的HotSpot VM,需要修改/bin/kafka-run-class.sh文件 KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true" 去除-XX:+UseCompressedOops参数 启动 bin/zookeeper-server-start.sh config/zookeeper.properties & bin/kafka-server-start.sh config/server.properties & 停止 bin/kafka-server-start.sh config/server.properties & bin/zookeeper-server-start.sh config/zookeeper.properties & create a topic bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test 创建单partitions单replication的topic bin/kafka-topics.sh --list --zookeeper localhost:2181 查看topic 查看topic的分区 bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test 启动生产者 bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 启动消费者 bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning produce启动的时候参数使用的是kafka的端口而consumer启动的时候使用的是zookeeper的端口; 单机连通性能测试 运行producer bin/kafka-console-producer.sh --b
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值