搭建三台机器集群,三台主机分别为hadoop101、hadoop102、hadoop103
下载安装包
下载最新的安装包: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
broker.id=101
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/home/data/kafka
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=hadoop101:2181,hadoop102:2181,hadoop103:2181
zookeeper.connection.timeout.ms=18000
group.initial.rebalance.delay.ms=0
其中:主要修改参数
- broker.id : 当前机器服务器ID
- log.dirs : 数据存放目录
- zookeeper.connect : 机器Zookeeper地址
分发安装包
- 拷贝整个目录到机器2、和机器3中
- 修改对应的broker.id,另外两台机器分别设置id为102、103
启动集群
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机器
查看状态
在hadoop101上查看:
[root@hadoop101 ~]# jps -l 2341 org.apache.zookeeper.server.quorum.QuorumPeerMain 3847 sun.tools.jps.Jps 3517 kafka.Kafka
在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
在hadoop103上查看:
[root@hadoop103 ~]# jps -l 2001 sun.tools.jps.Jps 1506 org.apache.zookeeper.server.quorum.QuorumPeerMain 1890 kafka.Kafka
停止集群
在hadoop101上建立群停脚本:stopAllKafka.sh
脚本内容如下
#! /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
停止集群 ```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集群的安装和启停。