1.下载zookeeper
清华镜像:http://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/
2.上传至服务器
可以通过rz
或xftp
,步骤略。
3.解压并移动到指定目录
我使用的是apache-zookeeper-3.6.3-bin.tar.gz
。
使用tar -xzvf apache-zookeeper-3.6.3-bin.tar.gz
命令进行解压。
我移动到/opt/zookeeper/
。
4.修改配置文件
进入/opt/zookeeper/apache-zookeeper-3.6.3-bin/conf
(即对应目录下的conf目录)。
cp zoo_sample.cfg zoo.cfg
打开zoo.cfg
,找到dataDir
,将它的值修改为自己想存储的地方,建议修改为和zookeeper
同级的新建目录,没别的意思,就是为了好记。
5.启动
/opt/zookeeper/apache-zookeeper-3.6.3-bin/bin
./zkServer.sh start
出现如下,即为启动成功:
[root@VM-4-15-centos bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@VM-4-15-centos bin]#
**注意:**可能会存在Error: JAVA_HOME is not set and java could not be found in PATH.
错误,请检查Java环境是否已配置,如果已经配置了,请进入/opt/zookeeper/apache-zookeeper-3.6.3-bin/bin
目录,修改zkEnv.sh
文件,修改内容如下(大约在八十行左右,可以直接匹配字符JAVA_HOME
):
# 在if上方添加如下语句:JAVA_HOME='你的JAVA路径'
JAVA_HOME="/usr/local/java/jdk1.8.0_301/"
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
JAVA="$JAVA_HOME/bin/java"
elif type -p java; then
JAVA=java
else
echo "Error: JAVA_HOME is not set and java could not be found in PATH." 1>&2
exit 1
6.如遇权限问题,请直接给予相关文件执行权限
7.停止
还是在bin目录(/opt/zookeeper/apache-zookeeper-3.6.3-bin/bin/
),执行./zkServer.sh stop
[root@VM-4-15-centos bin]# ./zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... ./zkServer.sh: line 213: kill: (3448) - No such process
STOPPED
[root@VM-4-15-centos bin]#