Linux下zookeeper集群搭建(至少需要三台主机(虚拟机))

 

1,官网下载zookeeper http://zookeeper.apache.org/releases.html

2,配置好系统的Java环境,将压缩包zookeeper-3.4.12.tar.gz解压至Linux任意目录下,

3,更改conf目录下的文件zoo_sample.cfg 重命名为zoo.cfg或则重新创建一个新的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/zookeeper-3.4.12/data
# the port at which the clients will connect
clientPort=2181
# 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
server.1= 10.10.25.20:2888:3888
server.2= 10.10.25.21:2888:3888
server.3= 10.10.25.22:2888:3888

参数说明 

10.10.25.xx记录的是每个zookeeper实例的ip

2888 每个zookeeper实例通信的端口号

3888选举leader时zookeeper实例使用的端口号

4,将上述文件分别拷贝到每个实例相同目录下

5,在每个实例的dataDir目录下(即/home/zookeeper-3.4.12/data)创建一个myid文件,myid文件内容即为zookeeper实例的***,第一个实例即1,第二个即2,以此类推

6,进入zookeeper bin目录执行sh zkServer.sh start/stop 启动或停止zookeeper

Linux下zookeeper集群搭建(至少需要三台主机(虚拟机))

7,bin目录下使用sh zkCli.sh 连接zookeeper进入命令交互模式

Linux下zookeeper集群搭建(至少需要三台主机(虚拟机))

8,create /FirstZnode “Myfirstzookeeper-app" 创建名为FirstZnode的节点并赋值为Myfirstzookeeper-app,注意节点名字必须以/开始

Linux下zookeeper集群搭建(至少需要三台主机(虚拟机))

9,get /FirstZnode获取节点的值

Linux下zookeeper集群搭建(至少需要三台主机(虚拟机))

10.rmr /FirstZnode递归删除节点 FirstZnode

11.sh zkServer.sh status查询每个节点的状态

Linux下zookeeper集群搭建(至少需要三台主机(虚拟机))

Linux下zookeeper集群搭建(至少需要三台主机(虚拟机))