初识zookeeper,linux 安装配置zookeeper

1、下载并解压最新稳定的zookeeper文件

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz(jar包一定要选对,否则死你都不知道怎么死的。)

tar -zxvf zookeeper-3.4.14.tar.gz 解压

新建data和logs文件

mkdir data 

mkdir logs

/conf/cp zoo_sample.cfg zoo.cfg

修改配置文件

dataDir=/usr/local/apache-zookeeper-3.5.5/data
dataLogDir=/usr/local/apache-zookeeper-3.5.5/logs

配置环境变量

/etc/profile

export ZOOKEEPER_HOME=/usr/local/zk
export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf 

ps:我这里把文件夹重命名未zk了,根据实际文件夹来改

最后就启动

进入bin目录下

./zkServer.sh start

./zkServer.sh stop

./zkServer.sh status

客户端连接

zkCli.sh -server 127.0.0.1:2181

连上了测试报错。。。

在这个过程中可能会出现问题

下面是我遇到的问题

找不到主类:原因是zookeeper版本下载错误

//错误信息
./zkServer.sh start-foreground
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
// 错误信息
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Error contacting service. It is probably not running.

 启动成功后状态查询失败

Error contacting service. It is probably not running.

如果是单机模式,清空data/logs目录下所有文件。

至此,我已经启动成功了。

原文地址:https://www.cnblogs.com/xiaobug/p/10932160.html