安装zookeeper
(一)安装zookeeper (1)tar zxf zookeeper-3.3.3.tar.gz (2)mv zookeeper-3.3.3 /usr/local/zookeeper (3)cd /usr/local/zookeeper/conf/ (4)cp zoo_sample.cfg zoo.cfg (5)vim zoo.cfg 修改的内容 dataDir=/usr/local/zookeeper/zookeeper-data data LogDir=/usr/local/zookeeper/logs clientPort=2181 server.1=master:2888:3888 server.2=slave1:2888:3888 server.3=slave2:2888:3888 server.4=slave3:2888:3888 server.5=slave4:2888:3888 (6) mkdir /usr/local/zookeeper/zookeeper-data data mkdir /usr/local/zookeeper/logs (7) 在/usr/local/zookeeper/zookeeper-data data目录下创建文件,命名为myid (8) 编辑“myid”文件并在对应的IP的机器上输入对应的编号。如在master上,“myid”文件内容就是1, 在slave1上,内容就是2 (9)在 (1)cd /etc/profile.d (2)vim zookeeper.sh #keeper path ZOOKEEPER=/usr/local/zookeeper PATH=$PATH:$ZOOKEEPER/bin export PATH (3)赋权,使之可执行chmod 755 ./* 执行./zookeeper.sh (10)将/usr/local/zookeeper目录分别拷贝到192.168.10.197和192.168.10.198等四台机子下,同时修改对应的“myid”文件内容。 (二)启动zookeeper (1)在五台机器上分别执行shell脚本。 無限定誰先誰後,但三台電腦間執行此指令的間隔不宜過久(因為有設定timeout時間) 没有出错信息,则成功启动. /usr/local/zookeeper/bin/zkServer.sh start (2)启动客户端脚本 zkCli.sh -server 192.168.10.168:2181 (3)执行完成之后输入“jps”命令查看 jps (4)通过输入“/usr/local/zookeeper/bin/zkServer.sh status”检查是否启动 (5)通过在控制台输入命令检查集群zookeeper启动状态。 命令如“echo ruok | nc 192.168.10.168 2181”, 控制台输出“imok” (三)执行测试 (1)cd /usr/local/zookeeper (2)bin/zkCli.sh -server 192.168.10.196:2181 (3) [zk: 192.168.10.196:2181(CONNECTED) 0] create /mytest test Created /mytest [zk: 192.168.10.196:2181(CONNECTED) 1] ls / [mytest, zookeeper] [zk: 192.168.10.196:2181(CONNECTED) 2] get /mytest test cZxid = 0x200000006 ctime = Thu Nov 10 12:58:01 CST 2011 mZxid = 0x200000006 mtime = Thu Nov 10 12:58:01 CST 2011 pZxid = 0x200000006 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0 [zk: 192.168.10.196:2181(CONNECTED) 3] 在其他机器上查询: (1)cd /usr/local/zookeeper (2)bin/zkCli.sh -server 192.168.10.198:2181 (3) [zk: 192.168.10.198:2181(CONNECTED) 1] ls / [mytest, zookeeper] [zk: 192.168.10.198:2181(CONNECTED) 2] ls /mytest [] [zk: 192.168.10.198:2181(CONNECTED) 3] get /mytest test cZxid = 0x200000006 ctime = Thu Nov 10 12:58:01 CST 2011 mZxid = 0x200000006 mtime = Thu Nov 10 12:58:01 CST 2011 pZxid = 0x200000006 cversion = 0