zookeeper在linux自启动
时间: 2023-11-25 11:48:34 浏览: 72
zookeeper的linux安装软件
要在Linux系统中设置Zookeeper自启动,可以按照以下步骤进行操作:
1. 将Zookeeper安装目录下的conf目录中的zoo_sample.cfg文件复制一份并重命名为zoo.cfg。
2. 修改zoo.cfg文件中的dataDir和clientPort参数,分别指定Zookeeper数据存储目录和客户端连接端口。
3. 在/etc/init.d/目录下创建zookeeper文件,并将以下脚本复制到文件中:
```
#!/bin/sh
#
# zookeeper Startup script for the Apache ZooKeeper server
#
# chkconfig: - 80 20
# description: ZooKeeper is a distributed coordination service
# that helps manage and synchronize distributed systems.
### BEGIN INIT INFO
# Provides: zookeeper
# Required-Start: $network $remote_fs $named
# Required-Stop: $network $remote_fs $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Apache ZooKeeper server
# Description: Apache ZooKeeper is a distributed coordination service
that helps manage and synchronize distributed systems.
### 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
ZOO_BIN="/usr/local/java/zookeeper-3.4.5/bin"
ZOO_DATA_DIR="/var/lib/zookeeper"
ZOO_LOG_DIR="/var/log/zookeeper"
ZOO_CONF="/usr/local/java/zookeeper-3.4.5/conf/zoo.cfg"
ZOO_USER="zookeeper"
RETVAL=0
start() {
echo -n $"Starting ZooKeeper: "
daemon --user ${ZOO_USER} ${ZOO_BIN}/zkServer.sh start ${ZOO_CONF} > /dev/null 2>&1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zookeeper
return $RETVAL
}
stop() {
echo -n $"Stopping ZooKeeper: "
daemon --user ${ZOO_USER} ${ZOO_BIN}/zkServer.sh stop ${ZOO_CONF} > /dev/null 2>&1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zookeeper
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
RETVAL=2
esac
exit $RETVAL
```
4. 修改zookeeper文件中的ZOO_BIN、ZOO_DATA_DIR、ZOO_LOG_DIR和ZOO_CONF参数,分别指定Zookeeper安装目录、数据存储目录、日志存储目录和配置文件路径。
5. 将zookeeper文件设置为可执行文件并添加到系统服务中:
```
chmod +x /etc/init.d/zookeeper
chkconfig --add zookeeper
```
现在,Zookeeper就会在Linux系统启动时自动启动了。
阅读全文