Kafka安装验证及其注意

 

一、Zookeeper 配置文件说明:

# the directory where the snapshot is stored.

dataDir=/tmp/zookeeper

# the port at which the clients will connect

clientPort=2181

# disable the per-ip limit on the number of connections since this is a non-production config

maxClientCnxns=0~

使用zookeeper 工具进行验证:

在kafka的bin目录下的zookeeper-shell.sh 192.168.7.221:2181/

二、Kafka验证

往往错误不能启动的原因是因为配置文件使用的是默认的/tmp/kafka-logs 的目录我们进行替换为我们自定义的目录

如编辑service.properties 中的log.dirs=../kafkadata

    1.创建topic:

./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

Created topic "test".

    2.查看topic信息

[root@localhost bin]# ./kafka-topics.sh --list --zookeeper localhost:2181

test

3.展示topic

[root@gbd209 bin]# ./kafka-topics.sh -list --zookeeper gbd209:2181,gbd210:2181,gbd211:2181,gbd212:2181
mykafka - marked for deletion
test
test1
testKafka
testKafka_par100_rep2
testKafka_par10_rep1
testKafka_par10_rep2
testKafka_par1_rep1
testKafka_par1_rep2
topicVoice


4.生产者脚本启动

./kafka-console-producer.sh --topic test0214 --broker-list gbd209:9092

5.消费者脚本启动

./kafka-console-consumer.sh --zookeeper gbd209:2181,gbd210:2181,gbd211:2181,gbd212:2181 --from-beginning --topic test0214 --consumer.config ../config/consumer.properties

 

6.topic删除脚本

    1、删除kafka存储目录(server.properties文件log.dirs配置,默认为"/tmp/kafka-logs")相关topic目录
    2、Kafka 删除topic的命令是:

./bin/kafka-topics --delete --zookeeper 【zookeeper server】 --topic 【topic name】

    如果kafaka启动时加载的配置文件中server.properties没有配置delete.topic.enable=true,那么此时的删除并不是真正的删除,而是把topic标记为:marked for deletion

    你可以通过命令:./bin/kafka-topics --zookeeper 【zookeeper server】 --list 来查看所有topic

 7. 修改topic中分区数

topic中的分区书之只能增加不能减少

./kafka-topics.sh --zookeeper localhost:2182  --alter --partitions 20 --topic test

三、多副本测试

1.创建:

./kafka-topics.sh --create --zookeeper gbd209:2181,gbd210:2181,gbd211:2181,gbd212:2181 --replication-factor 4 --partitions 4 --topic test0215

 

2.查看全部

./kafka-topics.sh --list --zookeeper gbd209:2181,gbd210:2181,gbd211:2181,gbd212:2181

 

3.查看全部描述

./kafka-topics.sh --describe --zookeeper gbd209:2181,gbd210:2181,gbd211:2181,gbd212:2181

 

4.查看单个描述

./kafka-topics.sh --describe --topic test0215 --zookeeper gbd209:2181,gbd210:2181,gbd211:2181,gbd212:2181
Topic:test0215    PartitionCount:4    ReplicationFactor:4    Configs:
Topic: test0215    Partition: 0    Leader: 4    Replicas: 4,2,3,1    Isr: 4,2,3,1
Topic: test0215    Partition: 1    Leader: 1    Replicas: 1,3,4,2    Isr: 1,3,4,2
Topic: test0215    Partition: 2    Leader: 2    Replicas: 2,4,1,3    Isr: 2,4,1,3
Topic: test0215    Partition: 3    Leader: 3    Replicas: 3,1,2,4    Isr: 3,1,2,4

 

5.启动生产者

./kafka-console-producer.sh --topic test0215 --broker-list gbd209:9092,gbd210:9092,gbd211:9092,gbd212:9092

6.启动消费者

./kafka-console-consumer.sh --zookeeper gbd209:2181,gbd210:2181,gbd211:2181,gbd212:2181 --from-beginning --topic test0215 --consumer.config ../config/consumer.properties

 

 

四、参考博客

http://www.jasongj.com/2015/08/09/KafkaColumn4/

 

posted @ 2017-01-18 15:54  joqk  阅读(770)  评论(0编辑  收藏  举报