当前位置: 首页 > 分布式系统 > 正文

Zookeeper C 系列:安装

1 星2 星3 星4 星5 星 (2 次投票, 评分: 5.00, 总分: 5)
Loading ... Loading ...
baidu_share

Zookeeper 伪分布式安装

首先是 Zookeeper 的安装,如果你没有足够的机器,建议在单机上通过伪分布式安装方法来模拟 Zookeeper 集群,我在这里提供给大家一个简单的安装包来降低伪分布式 Zookeeper 的安装难度,该安装包可以模拟一个 5 Zookeeper 实例的集群。下载 zookeeper-3.4.0-pseudoclusters.tar.bz2,解压至 /tmp/ 目录(注意,安装包里面 dataDir 和 dataLogDir 配置已经预设为 /tmp/ 目录,如果你只是自己在 Zookeeper 上做一些小实验,建议不要更改该配置,这样在你做完了实验以后删除 /tmp/zookeeper/ 目录即可),操作方法如下:

1
2
3
4
5
6
7
forhappy@haiping-ict:/tmp$ pwd
/tmp
forhappy@haiping-ict:/tmp$ tar xvf zookeeper-3.4.0-pseudoclusters.tar.bz2
forhappy@haiping-ict:/tmp$ cd zookeeper/
forhappy@haiping-ict:/tmp/zookeeper$ ls
server001  server003  server005          stopZKCluster.sh
server002  server004  startZKCluster.sh

然后在 /tmp/zookeeper 目录下执行 startZKCluster.sh 启动 Zookeeper 服务,或者执行 stopZKCluster.sh 停掉 Zookeeper 服务。

启动 Zookeeper 服务:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
forhappy@haiping-ict:/tmp/zookeeper$ ./startZKCluster.sh .
starting zookeeper instance server001...
JMX enabled by default
Using config: /tmp/zookeeper/server001/zookeeper-3.4.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
starting zookeeper instance server002...
JMX enabled by default
Using config: /tmp/zookeeper/server002/zookeeper-3.4.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
starting zookeeper instance server003...
JMX enabled by default
Using config: /tmp/zookeeper/server003/zookeeper-3.4.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
starting zookeeper instance server004...
JMX enabled by default
Using config: /tmp/zookeeper/server004/zookeeper-3.4.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
starting zookeeper instance server005...
JMX enabled by default
Using config: /tmp/zookeeper/server005/zookeeper-3.4.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

停掉 Zookeeper 服务:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
forhappy@haiping-ict:/tmp/zookeeper$ ./stopZKCluster.sh .
stopping zookeeper instance server001...
JMX enabled by default
Using config: /tmp/zookeeper/server001/zookeeper-3.4.0/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
stopping zookeeper instance server002...
JMX enabled by default
Using config: /tmp/zookeeper/server002/zookeeper-3.4.0/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
stopping zookeeper instance server003...
JMX enabled by default
Using config: /tmp/zookeeper/server003/zookeeper-3.4.0/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
stopping zookeeper instance server004...
JMX enabled by default
Using config: /tmp/zookeeper/server004/zookeeper-3.4.0/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
stopping zookeeper instance server005...
JMX enabled by default
Using config: /tmp/zookeeper/server005/zookeeper-3.4.0/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

Zookeeper C API 安装

Zookeeper C client 的实现在 src/c 目录下,进入到该目录安装 Zookeeper C client,步骤如下:

1
2
3
$ ./configure
$ make
$ sudo make install

至此,基本的准备工作已经完成,你可以通过 Zookeeper 本身提供的 Shell 来操作 Zookeeper,操作方法如下,进入 /tmp/zookeeper/server001/zookeeper-3.4.0 目录,执行bin/zkCli.sh -server 127.0.0.1:2181 进入 Zookeeper shell:

1
forhappy@haiping-ict:/tmp/zookeeper/server001/zookeeper-3.4.0$ bin/zkCli.sh -server 127.0.0.1:2181
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[zk: 127.0.0.1:2181(CONNECTED) 2] help
ZooKeeper -server host:port cmd args
    connect host:port
    get path [watch]
    ls path [watch]
    set path data [version]
    rmr path
    delquota [-n|-b] path
    quit 
    printwatches on|off
    create [-s] [-e] path data acl
    stat path [watch]
    close 
    ls2 path [watch]
    history 
    listquota path
    setAcl path acl
    getAcl path
    sync path
    redo cmdno
    addauth scheme auth
    delete path [version]
    setquota -n|-b val path

在 shell 中你可以完成基本的操作,如创建、获取、删除、设置某一节点,设置节点 ACL等,可以 zookeeper shell 中通过 help 获取相关命令的用法。

本文固定链接: http://www.chepoo.com/zookeeper-c-install.html | IT技术精华网

Zookeeper C 系列:安装:等您坐沙发呢!

发表评论