zookeeper设置开机自启
时间: 2023-12-29 20:26:24 浏览: 111
Windows zookeeper/kafka开启自启动
以下是设置zookeeper开机自启的步骤:
1. 打开终端并以root用户身份登录到服务器。
2. 进入zookeeper的init.d目录:
```shell
cd /etc/init.d
```
3. 创建一个名为zookeeper的启动脚本:
```shell
vi zookeeper
```
4. 在启动脚本中添加以下内容:
```shell
#!/bin/bash
#
# zookeeper: Starts the zookeeper daemon
#
# chkconfig: 345 99 01
# description: Zookeeper is a distributed coordination service
# Source function library.
. /etc/init.d/functions
# Set environment variables
ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.5
# Start zookeeper
start() {
echo -n "Starting zookeeper: "
su -c "$ZOOKEEPER_HOME/bin/zkServer.sh start" zookeeper
echo "OK"
}
# Stop zookeeper
stop() {
echo -n "Stopping zookeeper: "
su -c "$ZOOKEEPER_HOME/bin/zkServer.sh stop" zookeeper
echo "OK"
}
# Restart zookeeper
restart() {
stop
start
}
# Check zookeeper status
status() {
echo -n "Zookeeper status: "
su -c "$ZOOKEEPER_HOME/bin/zkServer.sh status" zookeeper
}
# Main logic
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
```
5. 保存并退出编辑器。
6. 授予启动脚本执行权限:
```shell
chmod +x zookeeper
```
7. 将zookeeper添加到开机自启列表:
```shell
chkconfig --add zookeeper
```
8. 设置zookeeper开机自启:
```shell
chkconfig zookeeper on
```
9. 现在,您可以使用以下命令来启动、停止、重启和检查zookeeper的状态:
```shell
service zookeeper start
service zookeeper stop
service zookeeper restart
service zookeeper status
```
阅读全文