gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
将zookeeper加入到开机启动中
- User
将zookeeper加入到开机启动中
- Assistant
-
进入zookeeper安装目录,找到bin目录下的 zkServer.sh 文件。
-
打开zkServer.sh文件,在文件开头添加以下命令:
code
-
将zookeeper加入到开机启动中
进入zookeeper安装目录,找到bin目录下的 zkServer.sh 文件。
打开zkServer.sh文件,在文件开头添加以下命令:
#!/bin/bash
# chkconfig: 345 99 01
# description: Zookeeper is a centralized service for maintaining configuration information
# processname: zookeeper
### BEGIN INIT INFO
# Provides: zookeeper
# Required-Start: $network $named
# Required-Stop: $network $named
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Description: Zookeeper is a centralized service for maintaining configuration information
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
zkServer=/usr/local/zookeeper-3.4.6/bin/zkServer.sh
case "$1" in
start)
echo "Starting Zookeeper..."
$zkServer start
;;
stop)
echo "Stopping Zookeeper..."
$zkServer stop
;;
restart)
$0 stop
$0 start
;;
status)
$zkServer status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
需要注意:
在脚本中的"zkServer=/usr/local/zookeeper-3.4.6/bin/zkServer.sh"需要修改成对应zookeeper安装路径下的zkServer.sh的完整路径。
在第2行与第3行的注释中,chkconfig表示启动级别,这里设置为345;description表示描述,这里设置为“Zookeeper is a centralized service for maintaining configuration information”;processname表示进程名,这里设置为“zookeeper”。需要根据实际情况进行修改。
在第5到第15行处的注释是为了根据chkconfig来管理zookeeper的启动。
将保存好的zkServer.sh文件复制到 /etc/init.d/ 目录下。
sudo cp zkServer.sh /etc/init.d/zookeeper
需要注意:需要以root身份来执行此命令。
授予zookeeper脚本执行权限:
sudo chmod 755 /etc/init.d/zookeeper
将zookeeper加入到服务列表中:
sudo chkconfig --add zookeeper
确认zookeeper已经成功加入到开机启动列表中:
sudo chkconfig --list | grep zookeeper
如果有如下输出,则表示成功加入了开机启动列表:
zookeeper 0:off 1:off 2:on 3:on 4:on 5:on 6:off
需要注意:如果没有输出,可能需要重启系统或手动启动zookeeper来激活这个服务,然后再执行chkconfig --add zookeeper。
完成以上步骤,则zookeeper会在每次开机启动的时候自动启动。