版本3.4.10,已提前配置好jdk
三台主机:hadoop002,hadoop003.hadoop004
1.配置
将zookeeper-3.4.10.tar.gz解压后进入zookeeper-3.4.10/conf,将zoo_sample.cfg改名为zoo.cfg,编辑zoo.cfg
tickTime 心跳间隔
dataDir zk存储数据的路径,默认在/tmp
2888端口用于集群间的通信,3888是集群中的leader崩溃后用于重新选举leader的端口
1 # The number of milliseconds of each tick
2 tickTime=2000
3 # The number of ticks that the initial
4 # synchronization phase can take
5 initLimit=10
6 # The number of ticks that can pass between
7 # sending a request and getting an acknowledgement
8 syncLimit=5
9 # the directory where the snapshot is stored.
10 # do not use /tmp for storage, /tmp here is just
11 # example sakes.
12 dataDir=/opt/module/zookeeper-3.4.10/zkData
13 # the port at which the clients will connect
14 clientPort=2181
15 # the maximum number of client connections.
16 # increase this if you need to handle more clients
17 #maxClientCnxns=60
18
19
20 #######################cluster(根据各人主机名配置)##########################
21 server.2=hadoop002:2888:3888
22 server.3=hadoop003:2888:3888
23 server.4=hadoop004:2888:3888
24
25 #
26 # Be sure to read the maintenance section of the
27 # administrator guide before turning on autopurge.
28 #
29 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
30 #
31 # The number of snapshots to retain in dataDir
32 #autopurge.snapRetainCount=3
33 # Purge task interval in hours
34 # Set to "0" to disable auto purge feature
35 #autopurge.purgeInterval=1
由于在zoo.cfg中我们指定了dataDir,现在需要创建dataDir的路径,因此在zookeeper-3.4.10下创建zkData文件夹.接下来在zkData目录下创建名为myid的文件,该文件用于唯一标识zk集群中的一台机器(用于选举),编辑myid,写入的内容最后与本主机名对应,如hadoop002.在myid中就写2
接下来分发zookeeper-3.4.10文件夹到各台主机上,分发完成后,注意修改各台主机myid的值
2.启动
在hadoop002上进入zookeeper-3.4.10,执行以下命令启动zk集群
bin/zkServer.sh start
可以看到进程已经起来了.查看下状态发现并没有启动成功
没关系我们接着去hadoop003上启动zk
可以看到hadoop003上zk成功启动了,再次去hadoop002上查看状态
成功启动了,这说明分布式下的zk集群,如果leader没有启动,follower无法成功启动,接下来你可以接着去hadoop004上启动zk
关于客户端的启动执行bin/zkCli.sh即可