环境
系统:CentOS 7
软件:kafka_2.13-3.1.0.tgz
准备
安装Kafka
-
下载二进制包
- 浏览器下载:https://kafka.apache.org/downloads
- wget下载:
wget --no-check-certificat https://dlcdn.apache.org/kafka/3.1.0/kafka_2.13-3.1.0.tgz
-
安装
tar -zxvf kafka_2.13-3.1.0.tgz mv kafka_2.13-3.1.0 /usr/local/kafka
-
配置环境变量
cat << EOF >> /etc/profile # kafka export PATH=/usr/local/kafka/bin:\$PATH EOF source /etc/profile
安装Zookeeper
方法一:使用Kafka自带Zookeeper
-
添加启动服务
cat << EOF > /usr/lib/systemd/system/kafka-zookeeper.service [Unit] Description=Kafka internal Zookeeper After=network.target [Service] Type=forking Environment=JAVA_HOME=/usr/local/jdk ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh -daemon /usr/local/kafka/config/zookeeper.properties ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh [Install] WantedBy=multi-user.target EOF
-
启动
systemctl enable kafka-zookeeper systemctl start kafka-zookeeper
方法二:安装独立Zookeeper
配置Kafka
vim /usr/local/kafka/config/server.properties
log.dirs=/data/kafka
zookeeper.connect=x.x.x.x:2181 配置Zookeeper地址,如使用自带Zookeeper则保持localhost:2181
启动Kafka
-
添加启动服务
cat << EOF > /usr/lib/systemd/system/kafka.service [Unit] Description=Kafka After=network.target kafka-zookeeper.service [Service] Type=forking Environment=JAVA_HOME=/usr/local/jdk ExecStart=/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh [Install] WantedBy=multi-user.target EOF
-
启动
systemctl enable kafka systemctl start kafka