1、安装kafka(要先安装jdk)
#进入自己要安装的目录
wget https://downloads.apache.org/kafka/3.3.1/kafka_2.12-3.3.1.tgz
2、解压
tar -zxvf kafka_2.12-3.3.1.tgz
# 改名
mv kafka_2.12-3.3.1 kafka
# 创建zk存储路径 和 kafka存储路径
mkdir -p /mnt/software/kafka/zk/datas
mkdir -p /mnt/software/kafka/datas
3、修改配置文件
3.1 配置 zookeeper.properties 配置文件
vim /mnt/software/kafka/config/zookeeper.properties
#数据存放路径
dataDir=/mnt/data/kafka/zk/datas
#kafka内置zookeeper启动失败报错,添加解决
audit.enable=true
3.2 修改kafka的server.properties配置文件
vim /mnt/software/kafka/config/server.properties
#存放消息数据的文件地址
log.dirs=/mnt/data/kafka/datas
4 启动kafka
4.1启动zk
-daemon 为后台启动!
/mnt/software/kafka/bin/zookeeper-server-start.sh /mnt/software/kafka/config/zookeeper.properties
4.2 启动kafka
/mnt/software/kafka/bin/kafka-server-start.sh -daemon /mnt/software/kafka/config/server.properties
4.3 验证是否启动成功
5 停止
1、先停止kafka
/mnt/software/kafka/bin/kafka-server-stop.sh
2、再停止zk
/mnt/software/kafka/bin/zookeeper-server-stop.sh
6 开机启动
6.1 配置zookeeper服务
vim /etc/systemd/system/zookeeper.service
[Unit]
Description=zookeeper.service
After=network.target
[Service]
Type=simple
Environment=JAVA_HOME=/usr/java/jdk1.8.0_131
User=root
Group=root
ExecStart=/mnt/software/kafka/bin/zookeeper-server-start.sh /mnt/software/kafka/config/zookeeper.properties
ExecStop=/mnt/software/kafka/bin/zookeeper-server-stop.sh
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
6.2 配置Kafka服务
vim /etc/systemd/system/kafka.service
[Unit]
Description=kafkaservice
After=network.target
[Service]
Type=simple
Environment=JAVA_HOME=/usr/java/jdk1.8.0_131
ExecStart=/mnt/software/kafka/bin/kafka-server-start.sh /data/software/kafka/config/server.properties
ExecStop=/mnt/software/kafka/bin/kafka-server-stop.sh
User=root
Group=root
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
7 验证
7.1 生产者发送消息
/mnt/software/kafka/bin/kafka-console-producer.sh --broker-list *.*.*.*:9092 --topic fb
7.2 消费者接受消息
/mnt/software/kafka/bin/kafka-console-consumer.sh --bootstrap-server 8.136.99.217:9092 --topic fb --from-beginning
8 指令
systemctl daemon-reload
systemctl enable kafka.service
systemctl start kafka.service
systemctl restart kafka.service
systemctl status kafka.service
标签:kafka3.3,bin,zookeeper,mnt,kafka,centos7,server,安装,software
From: https://www.cnblogs.com/cc-boy/p/16791540.html