确保Kafka自启动成功,可以通过以下步骤进行配置和验证:
使用systemd配置自启动
cd /lib/systemd/system/
kafka.service
文件,确保以下配置正确:[Unit]
Description=Apache Kafka Server
After=network.target remote-fs.target kafka-zookeeper.service
[Service]
Type=forking
User=root
Group=root
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/usr/local/kafka-2.4.1/bin/kafka-server-start.sh -daemon /usr/local/kafka-2.4.1/config/server.properties
ExecStop=/usr/local/kafka-2.4.1/bin/kafka-server-stop.sh
Restart=on-failure
systemctl daemon-reload
systemctl start kafka
systemctl enable kafka
检查Kafka服务状态
systemctl status kafka
Active: active (running)
,则表示Kafka服务已成功启动并正在运行。验证Kafka服务是否自启动
/var/log/syslog
或/var/log/messages
)以获取更多信息。通过上述步骤,您可以确保Kafka服务在系统启动时成功自启动,并能够持续稳定运行。