念念不忘
必有回响

搭建Zookeeper集群

一、环境要求

  • OS:Centos6.x
  • JDK: 1.8
  • 防火墙:关闭

二、下载Zookeeper

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

三、安装并配置

1. 新建目录

mkdir -p /data/zookeeper  
mkdir -p /data/log/zookeeper

2. 解压zookeeper

tar -zxvf zookeeper-3.4.10.tar.gz

3. 修改配置

ln -s zookeeper-3.4.10 zookeeper 
cd zookeeper/conf/

3.1 修改配置

cp zoo_sample.cfg zoo.cfg
vim 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=/data/zookeeper
dataLogDir=/data/log/zookeeper
# 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=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888

3.2 分发配置到其它机器

scp zoo.cfg hadooper@node2:~/zookeeper/conf/
scp zoo.cfg hadooper@node3:~/zookeeper/conf/

3.3 根据server.1server.2server.3的值,在这三台机器上创建myid

touch /data/zookeeper/myid

在node1的机器上执行:

echo "1" > /data/zookeeper/myid 

在node2的机器上执行:

echo "2" > /data/zookeeper/myid 

在node3的机器上执行:

echo "3" > /data/zookeeper/myid 

执行完毕后,node1的myid值为1,node2的myid值为2,node3的myid值为3.

4. 启动zookeeper

bin/zkServer.sh start

并且查看状态

bin/zkServer.sh status

 

赞(0) 打赏
未经允许不得转载:码农志 » 搭建Zookeeper集群
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏