由于在 cli 模式下启动,停止 kafka 和zookpeer 进程命令行比较繁琐,所以推荐使用supervisor 来对进程进行管理。
systemctl start supervisord
find / -name supervisord.conf
,我的安装位置是 /etc/supervisord.conf
。[include]
files = supervisord.d/*.ini
说明子进程配置文件都包含在supervisord.d 目录下,且以ini结尾,如果习惯使用.conf结尾,可以将此处的扩展名改为.conf 5. 在supervisord.d 目录下,新建自己的文件 kafka.ini。
[program:kafka]
command=/root/kafka_2.12-2.5.0/bin/kafka-server-start.sh /root/kafka_2.12-2.5.0/config/server.properties
autostart=true
autorestart=false
stderr_logfile=/tmp/kafka_stderr.log
stdout_logfile=/tmp/kafka_stdout.log
注: command 是进程启动的命令,包含文件目录(目录也可以单独写在directory 中)。
[program:zook]
command=/root/kafka_2.12-2.5.0/bin/zookeeper-server-start.sh /root/kafka_2.12-2.5.0/config/zookeeper.properties
autostart=true
autorestart=false
stderr_logfile=/tmp/zook_stderr.log
stdout_logfile=/tmp/zook_stdout.log
supervisorctl
> status #查看程序状态
> stop name #关闭name程序
> start name #启动name程序
> restart name # 重启name程序
> reread #读取有更新的配置文件,不会启动新添加的程序
> update #重启配置文件修改过的程序