zookeeper集群(以3台主机为例)搭建实例

下载可用的zookeeper程序,上传至linux主机,解压缩

% tar –zxvf zookeeper-3.4.7.tar.gz

 

设置环境变量,将目录指向新解压的路径

 

export ZOOKEEPER_HOME=~/usr/software/zookeeper-3.4.7

export PATH=$PATH:$ZOOKEEPER_HOME/bin

 

然后修改配置文件 ZOOKEEPER_HOME/conf/zoo.cfg,新解压的目录没有这个文件,将zoo_sample.cfg这个文件 改名即可

 

 cp 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 isstored.

# do not use /tmp for storage, /tmp here isjust

# example sakes.

dataDir=/usr/software/zookeeper-3.4.7/tmp

# the port at which the clients will connect

clientPort=2181

# the maximum number of client connections.

# increase this if you need to handle moreclients

#maxClientCnxns=60

#

# Be sure to read the maintenance section ofthe

# administrator guide before turning onautopurge.

#

#http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# The number of snapshots to retain indataDir

#autopurge.snapRetainCount=3

# Purge task interval in hours

# Set to "0" to disable auto purgefeature

#autopurge.purgeInterval=1

server.1=192.168.56.129:2888:3888

server.2=192.168.56.130:2888:3888

server.3=192.168.56.131:2888:3888

 

以集群为3个服务器为例,如上server.1 server.2 server.3指定了3个服务器地址

Ticktime属性指定了基本时间单元(毫秒为单位)

Datadir指定了存储持久数据的本地文件系统的位置

Clientport指定用于监听客户端链接的端口,通常使用2181

 

tmp目录下,创建服务器的id文件,文件名为myid,打开文件,为对应的服务器指定id,这个id要和zoo.cfg的文件中指定的一致。

 

其余两个服务器,可以将zookeeper目录直接拷贝过去,然后修改myid的值即可

 

 

然后依次在每台服务器执行如下命令:

 

./zkServer.sh start

ZooKeeper JMX enabled by default

Using config:/usr/software/zookeeper-3.4.7/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

 

然后使用如下命令查看状态

./zkServer.sh status

ZooKeeper JMX enabled by default

Using config:/usr/software/zookeeper-3.4.7/bin/../conf/zoo.cfg

Mode: follower

 

./zkServer.sh status

ZooKeeper JMX enabled by default

Using config:/usr/software/zookeeper-3.4.7/bin/../conf/zoo.cfg

Mode: leader

 

 

OK,环境搭建完成!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值