【Kafka】kafka使用之路(四)配置开机自启
kafka
运行就像上篇提到的那样执行一下脚本,但是一关机一重启就又需要重新启动。
zookeeper-server-start.sh
#开一个终端 zookeeper
./zookeeper-server-start.sh ./../config/zookeeper.properties
kafka-server-start.sh
#再开一个终端 kafka
./kafka-server-start.sh ./../config/server.properties
所以需要配置一下kafka
的开机自启。
1.zookeeper.service
vi /lib/systemd/system/zookeeper.service
[Unit]
Description=Zookeeper service
After=network.target
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/jdk-16.0.1/bin"
User=root
Group=root
ExecStart=/home/randyfield/kafka-release/kafka_2.12-2.8.0/bin/zookeeper-server-start.sh /home/randyfield/kafka-release/kafka_2.12-2.8.0/config/zookeeper.properties
ExecStop=/home/randyfield/kafka-release/kafka_2.12-2.8.0/bin/zookeeper-server-stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
2.kafka.service
vi /lib/systemd/system/kafka.service
[Unit]
Description=Apache Kafka server (broker)
After=network.target zookeeper.service
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/jdk-16.0.1/bin"
User=root
Group=root
ExecStart=/home/randyfield/kafka-release/kafka_2.12-2.8.0/bin/kafka-server-start.sh /home/randyfield/kafka-release/kafka_2.12-2.8.0/config/server.properties
ExecStop=/home/randyfield/kafka-release/kafka_2.12-2.8.0/bin/kafka-server-stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
3.启动服务
#刷新配置
systemctl daemon-reload
#服务加入开机自启
systemctl enable zookeeper
systemctl enable kafka
#启动/关闭/重启 启动kafka前必须先启动zookeeper
systemctl start zookeeper
systemctl start kafka
#查看状态
systemctl status zookeeper
- 原文作者:Garfield
- 原文链接:http://www.randyfield.cn/post/2021-05-05-kafka-service/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。