kafka操作配置

参阅网址

http://blog.csdn.net/itleochen/article/details/18407063

http://www.bkjia.com/yjs/947570.html

http://www.aboutyun.com/thread-12882-1-1.html

http://www.cnblogs.com/davidwang456/p/4238536.html


/usr/local/kafka/kafka_2.11-0.8.2.1

修改每台服务器的config/server.properties


broker.id: 唯一,填数字,本文中分别为132/133/134


host.name:唯一,填服务器IP,之前配置时,把中间的'.'给忘写了,导致kafka集群形同虚设(基本只有leader机器在起作用),以及一系列莫名其妙的问题,伤啊


zookeeper.connect=192.168.40.134:2181,192.168.40.132:2181,192.168.40.133:2181


启动zookeeper(standalone模式):zkServer.sh stop

> bin/zookeeper-server-stop.sh config/zookeeper.properties &

启动kafka:

> bin/kafka-server-start.sh config/server.properties &


创建消息主题

bin/kafka-topics.sh --create \

--replication-factor 3 \

--partition 3 \

--topic user-behavior-topic \

--zookeeper 192.168.1.1:2181,192.168.1.2:2181,192.168.1.3:2181


查看topic的详细信息

bin/kafka-topics.sh --describe --zookeeper master:2181


生产者,输入数据

bin/kafka-console-producer.sh --broker-list master:9092 --topic user-behavior-topic


消费者,消费数据,这个和producer不是在一个窗口

bin/kafka-console-consumer.sh --zookeeper master:2181 --topic user-behavior-topic --from-beginning



bin/kafka-preferred-replica-election.sh --zookeeper 192.168.175.127:2181,192.168.75.128,192.168.75.129:2181 --path-to-json-file preferred-click.json

{

 "partitions":

  [

    {"topic": "click", "partition": 0},

    {"topic": "click", "partition": 1},

    {"topic": "click", "partition": 2},

    {"topic": "click", "partition": 3},

    {"topic": "click", "partition": 4},

    {"topic": "click", "partition": 5},

    {"topic": "click", "partition": 6},

    {"topic": "click", "partition": 7},

    {"topic": "play", "partition": 0},


    {"topic": "play", "partition": 1},


    {"topic": "play", "partition": 2},


    {"topic": "play", "partition": 3},


    {"topic": "play", "partition": 4},


    {"topic": "play", "partition": 5},


    {"topic": "play", "partition": 6},


    {"topic": "play", "partition": 7}


  ]

}

cat preferred-click.json


你可能感兴趣的:(kafka操作配置)