macos brew zookeeper,安装后zookeeper启动失败?

时间:2022-12-10 22:46:34

一、Zookeeper安装流程

执行如下安装命令:

brew install zookeeper

执行截图如下:

macos brew zookeeper,安装后zookeeper启动失败?

安装后查看 zookeeper 安装信息(默认拉取最新版本)

brew info zookeeper

执行截图如下:

macos brew zookeeper,安装后zookeeper启动失败?

二、Zookeeper启动、状态查询、及关闭

启动执行命令:

zkServer start

执行截图如下:

macos brew zookeeper,安装后zookeeper启动失败?

状态查询执行命令:

zkServer status

执行截图如下(启动失败,翻车现场截图):

macos brew zookeeper,安装后zookeeper启动失败?

红线部分说明未启动成功,后面细谈

关闭执行命令:

zkServer stop

执行截图如下:

macos brew zookeeper,安装后zookeeper启动失败?

三、Zookeeper 启动失败

在上方我们在启动 zookeeper 时,看到好多博客要么没有截图,要么直接把启动失败截图当启动成功附上了...

当然有的小伙伴也不一定遇到这个问题哈,我们先给出错误提示:

Error contacting service. It is probably not running

如果没有出现该错误的小伙伴,可以关闭这篇文章了,下面内容主要是出错解决:

启动失败的场景:

  • 端口被占用:ps -ef | grep 2181
  • zoo.cfg 配置错误
  • 防火墙
  • zookeeper 版本问题

经过一系列排除,最终解决方法:卸载...

是的,你没有听错,由于 brew 无法选择下载的 zookeeper 版本,默认下载最新版本,而出现这种情况,大概率是版本问题,跟本地 jdk 不兼容...

macos brew zookeeper,安装后zookeeper启动失败?

don't say so much ...

执行卸载命令:

brew uninstall zookeeper

执行截图:

macos brew zookeeper,安装后zookeeper启动失败?

四、手动安装Zookeeper

1、下载zookeeper

官网下载路径:https://zookeeper.apache.org/releases.html#download

推荐下载版本:3.4.14

我提供的链接:https://niceyoo.lanzoui.com/iCG1Sgm00oh

下载后解压至:/usr/local/etc

2、配置环境变量

打开环境变量文件:

open ~/.bash_profile

添加如下:

export ZOOKEEPER_HOME=/usr/local/etc/zookeeper-3.4.14
export PATH=$PATH:$ZOOKEEPER_HOME/bin:

修改保存文件后执行:

source ~/.bash_profile

3、修改zookeeper -> conf文件

打开 zookeeper 文件下的 conf 文件夹,然后找到 zoo_sample.cfg 文件,

  1. 将 zoo_sample.cfg 重命名为 zoo.cfg
  2. 修改 dataDir 文件路径,在 zookeeper/ 根节点下新建 data 目录
  3. 将 dataDir 路径修改为:/usr/local/etc/zookeeper-3.4.14/data

详细配置如下:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/var/run/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

4、启动zookeeper

终端下执行 zkServer.sh start

zkServer.sh start

执行效果截图:

macos brew zookeeper,安装后zookeeper启动失败?

五、Zookeeper常用命令

启动:zkServer.sh start

关闭:zkServer.sh stop

状态:zkServer.sh status

重启:zkServer.sh restart

博客园持续更新,关注订阅,未来,我们一起成长。

本文首发于博客园:https://www.cnblogs.com/niceyoo/p/13666003.html