前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Zookeeper 安装

Zookeeper 安装

作者头像
用户5760343
发布2019-10-25 18:37:19
5210
发布2019-10-25 18:37:19
举报
文章被收录于专栏:sktjsktj

ZooKeeper服务器是用Java创建的,它在JVM上运行。你需要使用JDK 6或更高版本。

现在,按照以下步骤在你的机器上安装ZooKeeper框架。

步骤1:验证Java安装

相信你已经在系统上安装了Java环境。现在只需使用以下命令验证它。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">$ java -version
 </pre>

如果你在机器上安装了Java,那么可以看到已安装的Java的版本。否则,请按照以下简单步骤安装最新版本的Java。

步骤1.1:下载JDK

通过访问链接下载最新版本的JDK,并下载最新版本的Java。

最新版本(在编写本教程时)是JDK 8u 60,文件是“jdk-8u60-linuxx64.tar.gz"。请在你的机器上下载该文件。

步骤1.2:提取文件

通常,文件会下载到download文件夹中。验证并使用以下命令提取tar设置。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
 tar -zxf jdk-8u60-linux-x64.gz
 </pre>

步骤1.3:移动到opt目录

要使Java对所有用户可用,请将提取的Java内容移动到“/usr/local/java"文件夹。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
 mkdir /opt/jdk
 $ mv jdk-1.8.0_60 /opt/jdk/
 </pre>

步骤1.4:设置路径

要设置路径和JAVA_HOME变量,请将以下命令添加到〜/.bashrc文件中。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">export JAVA_HOME = /usr/jdk/jdk-1.8.0_60
 export PATH=
JAVA_HOME/bin
 </pre>

现在,将所有更改应用到当前运行的系统中。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">$ source ~/.bashrc
 </pre>

步骤1.5:Java替代

使用以下命令更改Java替代项。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_60/bin/java 100
 </pre>

步骤1.6

使用步骤1中说明的验证命令(java -version)验证Java安装。

步骤2:ZooKeeper框架安装

步骤2.1:下载ZooKeeper

要在你的计算机上安装ZooKeeper框架,请访问以下链接并下载最新版本的ZooKeeper。http://zookeeper.apache.org/releases.html

到目前为止,最新版本的ZooKeeper是3.4.6(ZooKeeper-3.4.6.tar.gz)。

步骤2.2:提取tar文件

使用以下命令提取tar文件

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">tar -zxf zookeeper-3.4.6.tar.gz
 mkdir data
 </pre>

步骤2.3:创建配置文件

使用命令** vi conf/zoo.cfg 和所有以下参数设置为起点,打开名为 conf/zoo.cfg **的配置文件。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">$ vi conf/zoo.cfg
tickTime = 2000
 dataDir = /path/to/zookeeper/data
 clientPort = 2181
 initLimit = 5
 syncLimit = 2
 </pre>

一旦成功保存配置文件,再次返回终端。你现在可以启动zookeeper服务器。

步骤2.4:启动ZooKeeper服务器

执行以下命令

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">$ bin/zkServer.sh start
 </pre>

执行此命令后,你将收到以下响应

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
 Using config: /Users/../zookeeper-3.4.6/bin/../conf/zoo.cfg
 $ Starting zookeeper ... STARTED
 </pre>

步骤2.5:启动CLI

键入以下命令

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">$ bin/zkCli.sh
 </pre>

键入上述命令后,将连接到ZooKeeper服务器,你应该得到以下响应。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Connecting to localhost:2181
 ................
 ................
 ................
 Welcome to ZooKeeper!
 ................
 ................
 WATCHER::
 WatchedEvent state:SyncConnected type: None path:null
 [zk: localhost:2181(CONNECTED) 0]
 </pre>

停止ZooKeeper服务器

连接服务器并执行所有操作后,可以使用以下命令停止zookeeper服务器。

代码语言:javascript
复制
<pre class="result notranslate" style="margin: 15px 0px; padding: 10px; position: relative; width: 700px; box-sizing: border-box; display: block; line-height: 1.7; background-color: rgb(32, 30, 47); border-radius: 3px; font-size: 14px; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; overflow-x: auto; border: 1px solid rgb(32, 30, 47); color: rgb(248, 248, 242); overflow-wrap: break-word !important; white-space: pre-wrap !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">$ bin/zkServer.sh stop</pre>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.10.24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 步骤1:验证Java安装
    • 步骤1.1:下载JDK
      • 步骤1.2:提取文件
        • 步骤1.3:移动到opt目录
          • 步骤1.4:设置路径
            • 步骤1.5:Java替代
              • 步骤1.6
              • 步骤2:ZooKeeper框架安装
                • 步骤2.1:下载ZooKeeper
                  • 步骤2.2:提取tar文件
                    • 步骤2.3:创建配置文件
                      • 步骤2.4:启动ZooKeeper服务器
                        • 步骤2.5:启动CLI
                          • 停止ZooKeeper服务器
                          领券
                          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档