分析启动脚本zkServer.sh

本文详细分析了Zookeeper的启动脚本zkServer.sh,探讨了其在分布式环境中的作用,以及如何配置和优化启动参数,以确保大数据服务的稳定运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


# use POSIX interface, symlink is followed automatically
ZOOBIN="${BASH_SOURCE-$0}"
ZOOBIN="$(dirname "${ZOOBIN}")"
ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
# 这里会先配置一些必要的环境变量
if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
  . "$ZOOBINDIR"/../libexec/zkEnv.sh
else
  . "$ZOOBINDIR"/zkEnv.sh
fi
#此处配置JMX,默认是开启的,支持本地连接,如果远程连接,需要单独配置
# See the following page for extensive details on setting
# up the JVM to accept JMX remote management:
# http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
# by default we allow local JMX connections
if [ "x$JMXLOCALONLY" = "x" ]
then
    JMXLOCALONLY=false
fi

if [ "x$JMXDISABLE" = "x" ] || [ "$JMXDISABLE" = 'false' ]
then
#执行这里
  echo "ZooKeeper JMX enabled by default" >&2
  if [ "x$JMXPORT" = "x" ]
  then
    # for some reason these two options are necessary on jdk6 on Ubuntu
    #   accord to the docs they are not necessary, but otw jconsole cannot
    #   do a local attach
#配置远程连接,修改ZOOMAIN变量
    ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY org.apache.zookeeper.server.quorum.QuorumPeerMain"
  else
    if [ "x$JMXAUTH" = "x" ]
    then
      JMXAUTH=false
    fi
    if [ "x$JMXSSL" = "x" ]
    then
      JMXSSL=false
    fi
    if [ "x$JMXLOG4J" = "x" ]
    then
      JMXLOG4J=true
    fi
    echo "ZooKeeper remote JMX Port set to $JMXPORT" >&2
    echo "ZooKeeper remote JMX authenticate set to $JMXAUTH" >&2
    echo "ZooKeeper remote JMX ssl set to $JMXSSL" >&2
    echo "ZooKeeper remote JMX log4j set to $JMXLOG4J" >&2
    ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMXPORT -Dcom.sun.management.jmxremote.authenticate=$JMXAUTH -Dcom.sun.management.jmxremote.ssl=$JMXSSL -Dzookeeper.jmx.log4j.disable=$JMXLOG4J org.apache.zookeeper.se
从您提供的信息来看,执行 `./zkServer.sh start` 命令时报错 `-bash: ./zkServer.sh: No such file or directory`。这表明当前目录下不存在名为 `zkServer.sh` 的脚本文件,或者系统无法识别该文件。 以下是可能的原因及解决办法: ### 可能原因分析 #### 1. **路径错误** 确保您位于 ZooKeeper 安装目录的 `bin` 子目录下。通常情况下,ZooKeeper启动脚本 `zkServer.sh` 就存放在这个位置。 #### 2. **环境变量未配置** 如果您的环境中尚未将 ZooKeeper 的 `bin` 目录添加到 PATH 环境变量中,那么直接通过 `./zkServer.sh` 执行会失败。您可以检查 PATH 设置是否包含正确的路径。 #### 3. **权限不足** 即使存在此文件,但如果当前用户对该文件没有读取或执行权限,同样会出现找不到文件的情况。此时需要赋予适当的权限: ```bash chmod +x zkServer.sh ``` ### 解决步骤 #### 步骤一:验证路径 首先切换至正确的位置再尝试启动服务: ```bash cd /path/to/zookeeper/bin/ ./zkServer.sh start ``` 其中 `/path/to/zookeeper/` 替换为您实际安装 ZooKeeper 的根目录地址。 #### 步骤二:确认脚本的存在性 进入上述提到的目标 bin 文件夹之后可通过列出内容来核实是否有相应的 shell 脚本: ```bash ls -l | grep zkServer.sh ``` #### 步骤三:设置合适的访问控制权 假如发现权限不够导致的问题,请调整文件属性允许被执行。 #### 步骤四:排查依赖项完整性 有时候下载压缩包解压后的部分重要组成部分缺失也可能引发这种情况发生。重新获取官方最新版本源码包然后完整部署一遍不失为一种好的选择。 完成这些操作后应该能够正常开启 Zookeeper Server 。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值