Kafka环境搭建(分布式)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq1021979964/article/details/85080634

 

KafKa环境搭建(分布式)

 

1.上传kafka_2.11-0.10.0.0.tgz到software下面

 

2.解压kafka_2.11-0.10.0.0.tgz(并将kafka安装包放到别的文件夹中,统一管理。可以不理)

 

         tar -zxvf kafka_2.11-0.10.0.0.tgz

 

3.将kafka_2.11-0.10.0.0修改成kafka_2.11-0.10

         mv  kafka_2.11-0.10.0.0  kafka_2.11-0.10

 

4.修改namenode的server.properties

         cd  kafka_2.11-0.10/config/

         vi  server.properties

        

         broker.id=0

         host.name=188.2.72.57

         port=9092

         log.dirs=/home/hadoop/kafka_2.11-0.10/data/log-0

         zookeeper.connect=localhost:2181

 

 

5. 修改datanode1的server.properties

         cd  kafka_2.11-0.10/config/

         vi  server.properties

       

         broker.id=1

         host.name=188.2.72.58

         port=9093

         log.dirs=/home/hadoop/kafka_2.11-0.10/data/log-1

         zookeeper.connect=localhost:2181

 

 

 

6.修改datanode2的server.properties

 

         cd  kafka_2.11-0.10/config/

         vi  server.properties

        

         broker.id=2

         host.name=188.2.72.59

         port=9094

         log.dirs=/home/hadoop/kafka_2.11-0.10/data/log-2

         zookeeper.connect=localhost:2181

 

 

 

7. 启动kafka服务(分别启动三台)

 

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

 

看到三台机器分别有以下数据,启动成功

namenode

datanode1显示

datanode2显示

其中的188.2.72.57、9092、188.2.72.58、9093、188.2.72.59、9094说明我们的配置文件起到了作用,并且都启动成功

 

8. 创建topic(重新打开一个终端或是ctrl+c返回)

 

bin/kafka-topics.sh --create --zookeeper localhost:2181  --replication-factor  2  --partition  3 --topic test

 

 (也可以写为:

bin/kafka-topics.sh --create --zookeeper namenode:2181, datanode1:2181, datanode2:2181  --replication-factor  2  --partition  3 --topic test

也可以写为:

bin/kafka-topics.sh --create --zookeeper 188.2.72.57:2181, 188.2.72.58:2181, 188.2.72.59:2181  --replication-factor  2  --partition  3 --topic test

 

)

 

9.查看日志

 

cd data/log-0/test1-0

ll

 

10.列出topic

 

         cd  ..

         cd  ..

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

看到名为test1的topic(test是之前创建的)

 

11.向topic里写入日志(生产者)

 

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

this is a message:1

this is a message:3

this is a message:3

 

12.查看数据(namenode上执行)(消费者)

 

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

看到之前输入的数据,那么kafka就搭建完成了(注kafka接收是没有顺序的)

this is a message:1

this is a message:3

this is a message:3

 

猜你喜欢

转载自blog.csdn.net/qq1021979964/article/details/85080634