目录
zookeeper介绍
zookeeper单节点安装
zookeeper分布式集群安装
zookeeper命令行操作
Java编程现实命令行操作
- zookeeper介绍zookeeper是一个为分布式应用所设计的分布的、开源的协调服务,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,简化分布式应用协调及其管理的难度,提供高性能的分布式服务。zookeeper本身可以以Standalone模式安装运行,不过它的长处在于通过分布式zookeeper集群(一个Leader,多个Follower),基于一定的策略来保证zookeeper集群的稳定性和可用性,从而实现分布式应用的可靠性。
zookeeper是作为分布式协调服务,是不需要依赖于Hadoop的环境,也可以为其他的分布式环境提供服务 - zookeeper单节点安装Standalones模式系统环境:
[xulu@SZB-L0032014 ~]$ uname -a
Linux SZB-L0032014 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[xulu@SZB-L0032014 ~]$ cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m
[xulu@SZB-L0032014 ~]$ java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.4.el6-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
[xulu@SZB-L0032014 ~]$
zookeepr解压目录结构
[xulu@SZB-L0032014 zookeeper-3.4.6]$ ll
total 1505
drwxr-xr-x 2 xulu xulu 1024 Feb 20 2014 bin
-rw-rw-r-- 1 xulu xulu 82446 Feb 20 2014 build.xml
-rw-rw-r-- 1 xulu xulu 80776 Feb 20 2014 CHANGES.txt
drwxr-xr-x 2 xulu xulu 1024 Feb 20 2014 conf
drwxr-xr-x 10 xulu xulu 1024 Feb 20 2014 contrib
drwxr-xr-x 2 xulu xulu 1024 Feb 20 2014 dist-maven
drwxr-xr-x 6 xulu xulu 3072 Feb 20 2014 docs
-rw-rw-r-- 1 xulu xulu 1953 Feb 20 2014 ivysettings.xml
-rw-rw-r-- 1 xulu xulu 3375 Feb 20 2014 ivy.xml
drwxr-xr-x 4 xulu xulu 1024 Feb 20 2014 lib
-rw-rw-r-- 1 xulu xulu 11358 Feb 20 2014 LICENSE.txt
-rw-rw-r-- 1 xulu xulu 170 Feb 20 2014 NOTICE.txt
-rw-rw-r-- 1 xulu xulu 1770 Feb 20 2014 README_packaging.txt
-rw-rw-r-- 1 xulu xulu 1585 Feb 20 2014 README.txt
drwxr-xr-x 5 xulu xulu 1024 Feb 20 2014 recipes
drwxr-xr-x 8 xulu xulu 1024 Feb 20 2014 src
-rw-rw-r-- 1 xulu xulu 1340305 Feb 20 2014 zookeeper-3.4.6.jar
-rw-rw-r-- 1 xulu xulu 836 Feb 20 2014 zookeeper-3.4.6.jar.asc
-rw-rw-r-- 1 xulu xulu 33 Feb 20 2014 zookeeper-3.4.6.jar.md5
-rw-rw-r-- 1 xulu xulu 41 Feb 20 2014 zookeeper-3.4.6.jar.sha1
在conf目录下面创建一个zoo.cfg的文件,并且修改配置参数
[xulu@SZB-L0032014 conf]$ cp zoo_sample.cfg zoo.cfg
[xulu@SZB-L0032014 conf]$ cat 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/xulu/zookeeper
# the port at which the clients will connect
clientPort=3181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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
启动zookeeper服务
[xulu@SZB-L0032014 zookeeper-3.4.6]$ cd bin/
[xulu@SZB-L0032014 bin]$ ./zkServer.sh
JMX enabled by default
Using config: /home/xulu/zookeeper-3.4.6/bin/../conf/zoo.cfg
Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
[xulu@SZB-L0032014 bin]$ ./zkServer.sh start
JMX enabled by default
Using config: /home/xu