您的位置:首页 > 其它

zookeeper安装和集群搭建

2014-12-30 12:20 405 查看

1:前期准备

官方文档地址:http://zookeeper.apache.org/doc/r3.4.6/zookeeperStarted.html

下载:zookeeper-3.4.6.tar.gz

2:单台安转

1、配置zookeeper,解压zookeeper-3.4.6.tar.gz到D:\zookeeper-3.4.6,进入该目录下的conf中,里面包含zoo_sample.cfg和log4j.properties两个文件。
修改zoo_sample.cfg为zoo.cfg。其中个字段的含义如下:

字段含义
tickTimeZookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔。
initLimitZookeeper 服务器集群中Follower 服务器初始化连接时最长能忍受的心跳时间间隔数。心跳时间超过该间隔数,

表明Follower 服务器连接Leader服务器失败。
syncLimitLeader 与 Follower 之间发送消息时的最大请求/应答时间长度(以心跳数计算)。
dataDirZookeeper保存数据的目录。
dataLogDirZookeeper保存日志文件的目录,默认为dataDir。
clientPort这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
实例:

# 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=D:/opt/zookeeper/zookeeper-3.4.6-1/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

2、进入bin目录,执行zkServer.cmd启动zk。可通过netstat -ano查看配置的2181端口是否被监听。也可通过zkCli.cmd -server 127.0.0.1:2181来查看。

3:集群配置

1、本例通过伪集群模式,在一台机器上安装和配置多台zk实例。配置集群除了需要修改上述配置信息外,还需要新增以下配置项:

server.1=localhost:1888:1889
server.2=localhost:2888:2889
server.3=localhost:3888:3889
server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper
实例通信端口号不能一样,所以要给它们分配不同的端口号。

2、除了修改 zoo.cfg 配置文件,集群模式下还要配置一个文件 myid,这个文件在 dataDir 目录下,这个文件里面就有一个数据就是 A 的值,Zookeeper 启动时会读取这个文件,拿到里面的数据与 zoo.cfg 里面的配置信息比较从而判断到底是那个 server。

实例:

# 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=D:/****/zookeeper/zookeeper-3.4.6-1/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=localhost:1888:1889
server.2=localhost:2888:2889
server.3=localhost:3888:3889
3、执行所有zookeeper根目录下bin/zkServer.cmd
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: