Kafka环境搭建(分布式)

 

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值