下载
链接:https://pan.baidu.com/s/1W8lVEF6Y-xlg6zr3l9QAbg?pwd=hbkt
提取码:hbkt
上传到服务器/opt目录
安装
# kafka安装目录为 /opt/kafka
cd /opt;
mkdir kafka;
mv kafka_2.13-2.7.0.tgz ./kafka;
cd kafka;
#解压
tar -zxvf kafka_2.13-2.7.0.tgz;
cd kafka_2.13-2.7.0;
启动内置zookeeper
cd /opt/kafka/kafka_2.13-2.7.0;
#注意启动方式为前台启动 窗口不能关闭
./bin/zookeeper-server-start.sh config/zookeeper.properties;
# 后台运行启动方式为
./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
#关闭zookeeper
bin/zookeeper-server-stop.sh
启动kafka server
cd /opt/kafka/kafka_2.13-2.7.0;
#前端启动方式为
./bin/kafka-server-start.sh config/server.properties;
#后台启动方式为
./bin/kafka-server-start.sh -daemon config/server.properties
#关闭kafka
bin/kafka-server-stop.sh
开放防火墙端口
firewall-cmd --add-port=9092/tcp --permanent;
firewall-cmd --reload;
设置自启动
设置kafka.service
vim /lib/systemd/system/kafka.service
内容为
[Unit]
Description=Apache Kafka server (broker)
Documentation=http://kafka.apache.org/documentation.html
Requires=network.target remote-fs.target
After=network.target remote-fs.target kafka-zookeeper.service
[Service]
Type=simple
User=root
Group=root
Environment="JAVA_HOME=/opt/jdk1.8.0_201"
ExecStart=/opt/kafka/kafka_2.13-2.7.0/bin/kafka-server-start.sh /opt/kafka/kafka_2.13-2.7.0/config/server.properties
ExecStop=/opt/kafka/kafka_2.13-2.7.0/bin/kafka-server-stop.sh
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
上面的 kafka-zookeeper.service 是后面要创建的 zookeeper 服务的名称
Environment 为 java 的安装位置,需要修改成自己的位置
ExecStart 为启动命令,可以直接复制上面测试的时候的启动命令
ExecStop 为停止命令,也可以直接复制上面的
其他就不需要做修改
设置kafka-zookeeper.service
vim /lib/systemd/system/kafka-zookeeper.service
内容为
[Unit]
Description=Apache Kafka Zookeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
User=root
Group=root
Environment="JAVA_HOME=/opt/jdk1.8.0_201"
ExecStart=/opt/kafka/kafka_2.13-2.7.0/bin/zookeeper-server-start.sh /opt/kafka/kafka_2.13-2.7.0/config/zookeeper.properties
ExecStop=/opt/kafka/kafka_2.13-2.7.0/bin/zookeeper-server-stop.sh
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
跟上面的 kafka 配置一样,将启动命令和停止命令的路径修改成自己的即可
设置开机启动
systemctl daemon-reload
systemctl enable kafka-zookeeper
systemctl start kafka-zookeeper
systemctl stop kafka-zookeeper
systemctl enable kafka
systemctl start kafka
systemctl stop kafka