准备服务器
3台服务器对应3个node,分别如下:
node1:192.168.1.101
node2:192.168.1.102
node3:192.168.1.103
下载安装包
下载zookeeper
https://dlcdn.apache.org/zookeeper/
下载kafka
https://kafka.apache.org/downloads
安装步骤
zookeeper安装
1、解压安装包
$tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz
2、$sudo mv apache-zookeeper-3.5.8-bin /usr/local/apache-zookeeper-3.5.8
3、分别在3个节点上修改配置
$cd /usr/local/apache-zookeeper-3.5.8/conf/
$cp zoo_sample.cfg zoo.cfg
$vi zoo.cfg
增加如下配置:
server.1=192.168.1.101
server.2=192.168.1.102
server.3=192.168.1.103
可以修改如下数据存储的配置:
dataDir=/data/zoookeeper
4、分别在3个节点上新建目录并新建进程号
$sudo mkdir -p /data/zookeeper
$ cd /data/zookeeper
$vi myid
增加如下配置
1
kafka安装
1、解压安装包
$tar -zxvf kafka_2.13-2.6.0.tar.gz
2、$sudo mv kafka_2.13-2.6.0 /usr/local/kafka_2.13-2.6.0
3、分别在3个节点上修改配置
$cd /usr/local/kafka_2.13-2.6.0/config/
$vi server.properties
修改如下配置:
broker.id=101
listeners=PLAINTEXT://192.168.1.101:9092
log.dirs=/data/kafka/logs
num.partitions=3
zookeeper.connect=192.168.1.101:2181,192.168.1.102:2181,192.168.1.103:2181
4、分别在3个节点上新建目录
$sudo mkdir -p /data/kafka/logs
启动
1、首先启动zookeeper
$cd /usr/local/apache-zookeeper-3.5.8/bin
$sudo ./zkServer.sh start
2、最后启动kafka
$cd /usr/local/kafka_2.13-2.6.0
$sudo bin/kafka-server-start.sh -daemon config/server.properties
启动遇到的问题及解决方案
启动zookeeper遇到jdk找不到
解决方案
$cd /usr/local/apache-zookeeper-3.5.8/bin
$vi zkEnv.sh
增加如下配置
JAVA_HOME="/usr/local/java1.8"
启动kafka遇到jdk找不到
解决方案
$cd /usr/local/kafka_2.13-2.6.0/bin
$vi kafka-run-class.sh
增加如下配置
# Which java to use
if [ -z "$JAVA_HOME" ]; thenJAVA="/usr/local/java1.8/bin/java"**(说明:此行是修改为具体的jdk地址)**
elseJAVA="$JAVA_HOME/bin/java"
fi
验证安装成功
$cd /usr/local/kafka_2.13-2.6.0/bin
$kafka-topics.sh --list --zookeeper localhost:2181