ZooKeeper安装过程

来源:互联网 发布:php进销存源码erp 编辑:程序博客网 时间:2024/05/01 07:34

0.首先安装jdk

1.Zookeeper下载:http://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/

2.解压安装:tar -zxvf zookeeper-3.4.5.tar.gz 生成zookeeper-3.4.5目录

3.进入conf中,cp zoo_sample.cfg zoo.cfg

4.修改zoo.cfg配置文件

# 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=/tmp/zookeeper
dataDir=/usr/local/app/zookeeper-3.4.5/data


# the port at which the clients will connect
clientPort=2181
#
# 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

#master为192.168.70.115
#slave1 192.168.70.116
#slave2 192.168.70.117
#2881是各zookeeper服务器之间通信端口
#3881是zookeeper与其它应用程序之间的通信端口
#端口都是可以自定义的,非固定

server.1=192.168.70.115:2881:3881
server.2=192.168.70.116:2881:3881
server.3=192.168.70.117:2881:3881

3.4.6版本需要在dataDir中创建myid文件,内容分别是1/2/3,最大255


5.三台机器分别配置jdk-Zookeeper-zoo.cfg后,在所有机器上分别启动 bin/zkServer.sh start

[root@hadoop2 zookeeper-3.4.5]# bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/app/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@hadoop2 zookeeper-3.4.5]# jps
15985 Jps
15959 QuorumPeerMain

启动成功。

6.leader服务器

[root@hadoop3 bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/app/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: leader


后面启动的是slave

[root@hadoop1 bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/app/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower
当我们起第二个zookeeper实例后,leader将会被选出,从而一致性服务开始可以使用,这是因为3台机器只要有2台可用就可以选出leader并且对外提供服务(2n+1台机器,可以容n台机器挂掉)

7.客户端链接

[zk: localhost:2181(CONNECTED) 1] ls
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
[zk: localhost:2181(CONNECTED) 2] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 3]