zookeeper集群搭建

来源:互联网 发布:数据分析就业前景 编辑:程序博客网 时间:2024/06/07 20:21

zookeeper集群环境有集群环境、单机环境、伪集群三种情况。
1:创建配置文件。进入conf目录,运行命令:

cp zoo_sample.cfg zoo.cfg

zoo_sample.cfg是一个配置样例文件。修改其配置文件如下:

  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/zookeeper/2181 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 # Be sure to read the maintenance section of the  20 # administrator guide before turning on autopurge. 21 # 22 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance 23 # 24 # The number of snapshots to retain in dataDir 25 #autopurge.snapRetainCount=3 26 # Purge task interval in hours 27 # Set to "0" to disable auto purge feature 28 #autopurge.purgeInterval=1 29  30 server.1=10.66.140.32:2888:3888 31 server.2=10.66.131.57:2888:3888 32 server.3=10.66.140.32:2889:3889

配置说明:
dataDir:为zookeeper运行时数据的快照文件。
clientPort:为客户端连接端口。
server.id=host.port.port:集群节点配置。
id:为集群节点的标识。一般为整数。其他的没试过~
host:为集群节点的ip。
第一个port:follower服务器和leader服务器通信的端口。
第二个port:用于leader选举过程中的投票通信。(具体内容后续更新)


2:进入上述配置文件dataDir配置的目录中创建文件myid,并将内容设置为上述server中的id。
配置例子如下:
这里写图片描述

3:进入bin目录下启动zk。

./zkServer.sh start

4:测试启动是否正常
运行命令:telnet ip port之后输入netstat检查情况。
这里写图片描述
出现该情况原因是在集群环境下,如果只有1台服务器在运行时,zk是不对外提供的。
启动其他机器节点后,再运行该命令就可以看到各个节点自己的情况。
这里写图片描述

0 0