1)解压安装包

[atguigu@hadoop102 software]$ tar -zxvf kafka_2.11-0.11.0.0.tgz -C /opt/module/

2)修改解压后的文件名称

[atguigu@hadoop102 module]$ mv kafka_2.11-0.11.0.0/ kafka

3)在/opt/module/kafka目录下创建logs文件夹

[atguigu@hadoop102 kafka]$ mkdir logs

4)修改配置文件

[atguigu@hadoop102 kafka]$ cd config/ [atguigu@hadoop102 config]$ vi server.properties


  1. #broker的全局唯一编号,不能重复
  2. broker.id=0
  3. #删除topic功能使能
  4. delete.topic.enable=true
  5. #处理网络请求的线程数量
  6. num.network.threads=3
  7. #用来处理磁盘IO的现成数量
  8. num.io.threads=8
  9. #发送套接字的缓冲区大小
  10. socket.send.buffer.bytes=102400
  11. #接收套接字的缓冲区大小
  12. socket.receive.buffer.bytes=102400
  13. #请求套接字的缓冲区大小
  14. socket.request.max.bytes=104857600
  15. #kafka运行日志存放的路径
  16. log.dirs=/opt/module/kafka/logs
  17. #topic在当前broker上的分区个数
  18. num.partitions=1
  19. #用来恢复和清理data下数据的线程数量
  20. num.recovery.threads.per.data.dir=1
  21. #segment文件保留的最长时间,超时将被删除
  22. log.retention.hours=168
  23. #配置连接Zookeeper集群地址
  24. zookeeper.connect=node101:2181,node102:2181,node103:2181

5)配置环境变量

[atguigu@hadoop102 module]$ sudo vi /etc/profile
#KAFKA_HOME export KAFKA_HOME=/opt/module/kafka export PATH=$PATH:$KAFKA_HOME/bin

[atguigu@hadoop102 module]$ source /etc/profile


6)分发安装包

[atguigu@hadoop102 module]$ xsync kafka/

  1. 注意:分发之后记得配置其他机器的环境变量

7)配置

分别在node102和node103上修改配置文件/opt/module/kafka/config/server.properties中的broker.id=1、broker.id=2
注:broker.id不得重复

8)启动集群

依次在hadoop102、hadoop103、hadoop104节点上启动kafka
[atguigu@hadoop102 kafka]$ bin/kafka-server-start.sh config/server.properties &
[atguigu@hadoop103 kafka]$ bin/kafka-server-start.sh config/server.properties &
[atguigu@hadoop104 kafka]$ bin/kafka-server-start.sh config/server.properties &

9)关闭集群

[atguigu@hadoop102 kafka]$ bin/kafka-server-stop.sh stop
[atguigu@hadoop103 kafka]$ bin/kafka-server-stop.sh stop
[atguigu@hadoop104 kafka]$ bin/kafka-server-stop.sh stop

启停脚本

zk.sh

  1. #! /bin/bash
  2. case $1 in
  3. "start"){
  4. for i in node101 node102 node103
  5. do
  6. echo " --------启动 $i Kafka-------"
  7. # 用于KafkaManager监控
  8. ssh $i "export JMX_PORT=9988 && /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties "
  9. done
  10. };;
  11. "stop"){
  12. for i in node101 node102 node103
  13. do
  14. echo " --------停止 $i Kafka-------"
  15. ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh stop"
  16. done
  17. };;
  18. esac