环境说明
在安装Kafka之前,请确保已经安装了JDK和Zookeeper。运行Kafka,首先保证Java环境能正常使用,可执java -version查看。
安装JDK环境
- 下载jdk安装包
curl https://download.oracle.com/java/20/latest/jdk-20_linux-x64_bin.tar.gz -o jdk-20_linux-x64_bin.tar.gz
- 新建JDK安装环境,并把JDK软件包移到新安装位置
mkdir /usr/java
mv jdk-20_linux-x64_bin.tar.gz /usr/java/
- 解压缩
cd /usr/java/
tar -zxvf jdk-20_linux-x64_bin.tar.gz
- 配置Java环境变量,添加以下内容到/etc/profile文件中
#JAVA
export JAVA_HOME=/usr/java/jdk-20.0.1
export CLASSPATH=.:JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
- 使环境变量生效
source /etc/profile
- 查看Java安装版本
java -version
解压并安装zookeeper
- 下载zookeeper
curl https://archive.apache.org/dist/zookeeper/zookeeper-3.8.1/apache-zookeeper-3.8.1.tar.gz -o apache-zookeeper-3.8.1.tar.gz
- 创建一个Kafka文件夹,把Zookeeper解压此目录并查看
mkdir /home/kafka
tar -zxvf apache-zookeeper-3.8.1.tar.gz -C /home/kafka/
3. 创建目录环境
mkdir -p /home/kafka/apache-zookeeper-3.8.1/data
- 修改配置文件
dataDir
:zookeeper的数据目录
cllientPort
:zookeeper客户端连接端口
server.num
:zookeeper的集群地址。其中num是数字,对应的每个节点的myid。
值是IP地址:集群内机器通讯使用(Leader监听此端口):选举leader端口(所有节点都有此端口)
# 复制配置文件
egrep -v "^$|^#" /home/kafka/apache-zookeeper-3.8.1/conf/zoo_sample.cfg > /home/kafka/apache-zookeeper-3.8.1/conf/zoo.cfg
# 配置zoo.cfg文件,将以下内容加入到文件中
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/kafka/apache-zookeeper-3.8.1/data
clientPort=2181
server.1=192.168.17.129:2888:3888
server.2=192.168.17.130:2888:3888
server.3=192.168.17.131:2888:3888
- 分别在三台主机中分别配置myid
# 192.168.17.129 主机
echo 1 > /home/kafka/apache-zookeeper-3.8.1/data/myid
# 192.168.17.130 主机
echo 2 > /home/kafka/apache-zookeeper-3.8.1/data/myid
# 192.168.17.131 主机
echo 3 > /home/kafka/apache-zookeeper-3.8.1/data/myid
- 启动服务
cd /home/kafka/apache-zookeeper-3.8.1/bin/ && ./zkServer.sh start
标签:tar,zookeeper,kafka,apache,home,Kafka,安装,3.8
From: https://www.cnblogs.com/xiaodunan/p/17483026.html