搭建三台机器集群,三台主机分别为hadoop101、hadoop102、hadoop103

官网:http://kafka.apache.org/

下载安装包

下载最新的安装包:http://kafka.apache.org/downloads
下载成功后,解压到 /usr/local/kafka_2.12-2.5.0 目录

配置server.properties

配置文件路径:/usr/local/kafka_2.12-2.5.0/config/server.properties

  1. broker.id=101
  2. num.network.threads=3
  3. num.io.threads=8
  4. socket.send.buffer.bytes=102400
  5. socket.receive.buffer.bytes=102400
  6. socket.request.max.bytes=104857600
  7. log.dirs=/home/data/kafka
  8. num.partitions=1
  9. num.recovery.threads.per.data.dir=1
  10. offsets.topic.replication.factor=1
  11. transaction.state.log.replication.factor=1
  12. transaction.state.log.min.isr=1
  13. log.retention.hours=168
  14. log.segment.bytes=1073741824
  15. log.retention.check.interval.ms=300000
  16. zookeeper.connect=hadoop101:2181,hadoop102:2181,hadoop103:2181
  17. zookeeper.connection.timeout.ms=18000
  18. group.initial.rebalance.delay.ms=0

其中:主要修改参数

  • broker.id : 当前机器服务器ID
  • log.dirs : 数据存放目录
  • zookeeper.connect : 机器Zookeeper地址

分发安装包

  1. 拷贝整个目录到机器2、和机器3中
  2. 修改对应的broker.id,另外两台机器分别设置id为102、103

启动集群

  1. 在hadoop101上建立群起脚本:startAllKafka.sh
  2. 脚本内容如下 ```shell

    !/bin/bash

for host in “hadoop101” “hadoop102” “hadoop103” do echo “** $host **“ ssh $host “source /etc/profile; /usr/local/kafka_2.12-2.5.0/bin/kafka-server-start.sh -daemon /usr/local/kafka_2.12-2.5.0/config/server.properties” echo “*“ done


3. 启动集群
```shell
[root@hadoop101 ~]# ./startAllKafka.sh
********** hadoop101 **********
*******************************
********** hadoop102 **********
*******************************
********** hadoop103 **********
*******************************

注意:本项目配置的集群依赖外部Zookeeper集群,所以需要先启动Zookeeper机器

查看状态

  1. 在hadoop101上查看:

    [root@hadoop101 ~]# jps -l
    2341 org.apache.zookeeper.server.quorum.QuorumPeerMain
    3847 sun.tools.jps.Jps
    3517 kafka.Kafka
    
  2. 在hadoop102上查看:

    [root@hadoop102 kafka_2.12-2.5.0]# jps -l
    2612 kafka.Kafka
    2222 org.apache.zookeeper.server.quorum.QuorumPeerMain
    2703 sun.tools.jps.Jps
    
  3. 在hadoop103上查看:

    [root@hadoop103 ~]# jps -l
    2001 sun.tools.jps.Jps
    1506 org.apache.zookeeper.server.quorum.QuorumPeerMain
    1890 kafka.Kafka
    

    停止集群

  4. 在hadoop101上建立群停脚本:stopAllKafka.sh

  5. 脚本内容如下

    #! /bin/bash
    for host in "hadoop101" "hadoop102" "hadoop103"
    do
         echo "********** $host **********"
         ssh $host "source /etc/profile;/usr/local/kafka_2.12-2.5.0/bin/kafka-server-stop.sh"
         echo "*******************************"
    done
    
  6. 停止集群 ```shell [root@hadoop101 ~]# ./stopAllKafka.sh ** hadoop101 **


** hadoop102 **


** hadoop103 **


[root@hadoop101 ~]# jps -l 2341 org.apache.zookeeper.server.quorum.QuorumPeerMain 4757 sun.tools.jps.Jps ```


至此,完成了Kafka集群的安装和启停。