博主自主知识产权《Spring Boot深入浅出系列课程》(16章97节文档) 已经上线,请关注

ZooKeeper的安装

大数据 字母哥 0评论

重要:在奇数台机器上安装zookeeper

安装步骤

步骤一

解压:


tar -xzvf zookeeper-3.4.6.tar.gz -C /home/cluster/zookeeper;

配置环境变量:


ZOOKEEPER=/home/cluster/zookeeper PATH=$PATH:$ZOOKEEPER/bin

步骤二:

  • 修改conf/zoo.cfg

cp zoo_sample.cfg zoo.cfg vi 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=/home/cluster/zookeeper/data dataLogDir=/home/cluster/zookeeper/log server.1=192.168.56.10:2888:3888 server.2=192.168.56.11:2888:3888 server.3=192.168.56.12:2888:3888 # the port at which the clients will connect clientPort=2181

新建目录


mkdir /home/cluster/zookeeper/data; mkdir /home/cluster/zookeeper/log;

安装包分发


scp -r /home/cluster/zookeeper cluster@hadoop02:/home/cluster; scp -r /home/cluster/zookeeper cluster@hadoop03:/home/cluster;

创建myid文件

在${ZOOKEEPER}/data目录下创建一个文件:myid

分别在myid上按照配置文件的server.中id的数值,在不同机器上.

192.168.56.10 的myid内容为1

192.168.56.11 的为2

192.168.56.12 的为3

启动(分机器执行)


zkServer.sh start

测试:


zkCli.sh -server 192.168.56.10:2181

查看状态


zkServer.sh status [root@master ~]# zkServer.sh status JMX enabled by default Using config: /usr/zookeeper-3.3.3/bin/../conf/zoo.cfg Mode: follower(或leader)

查看zookeeper的启动状态

echo ruok | nc 192.168.56.10 2181

控制台输出: imok

jps进程:QuorumPeerMain

基本命令使用


zkCli.sh -server 192.168.56.10:2181

用法:




#创建一个znode: /t 和数据tdata,其结点是EPHEMERAL类型的, #意味着,客户端断开后其结点就会被删除 [zk: 192.168.56.10:2181(CONNECTED) 0] create -e /t tdata Created /t [zk: 192.168.56.10:2181(CONNECTED) 1] ls / [t, zookeeper] [zk: 192.168.56.10:2181(CONNECTED) 2] ls /t [] [zk: 192.168.56.10:2181(CONNECTED) 3] get /t tdata cZxid = 0x100000008 ctime = Sat May 02 09:21:20 CST 2015 mZxid = 0x100000008 mtime = Sat May 02 09:21:20 CST 2015 pZxid = 0x100000008 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x14d1231a3590003 dataLength = 5 numChildren = 0 quit
喜欢 (135)or分享 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址