Zookeeper 集群搭建

      分布式Zookeeper安装步骤:

1. 安装准备
     1.1 下载Zookeeper。下载链接:http://mirrors.hust.edu.cn/apache/zookeeper/
Zookeeper 集群搭建_第1张图片
     1.2 解压缩到指定的目录下,比如:/opt/zookeeper下。
     1.3 修改系统的hosts文件,指定域名映射。例如:
192.168.177.167 machine-1
192.168.177.168 machine-2
192.168.177.158 machine-0





      三台机器中都安装Zookeeper服务。

2. 配置zookeeper
       进入配置目录下,具体的命令如下:
[app@machine-1 conf]$ cd /opt/zookeeper/conf




       复制模板配置文件:
[app@machine-1 conf]$ cp zoo_sample.cfg zoo.cfg


      编辑文件:
[app@machine-1 conf]$ vim zoo.cfg 

<span style="font-size:18px;">     
 # 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=/opt/zookeeper/data
# the directory where transaction log is stored.
# this parameter provides dedicated log device for ZooKeeper
 dataLogDir=/opt/zookeeper/logs
# the port at which the clients will connect
clientPort=2222
server.1=machine-0:2888:3888
server.2=machine-1:2888:3888
server.3=machine-2:2888:3888
#
# 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</span>




     创建data和logs目录:
    mkdir -p /opt/zookeeper/data
    mkdir -p /opt/zookeeper/logs




3. 将zookeeper实例复制到集群
   #机器machine-1上
     scp  -r /opt/zookeeper machine-0:/opt/
     scp  -r /opt/zookeeper machine-2:/opt/






    添加myid文件到各台机器上,标示序列值不能够重复
    #一次输入1到225间的某个数,具体操作如下:
   #machine-0
   vim /opt/zookeeper/data/myid
   1
  #machine-1
   vim /opt/zookeeper/data/myid
   2
  #machine-2
   vim /opt/zookeeper/data/myid
  3




      启动各台机器的zookeeper。当然,可以将脚步添加到系统环境下,
直接执行sh脚步更方便,这里就不给出步骤了。
  
 /opt/zookeeper/bin/zkServer.sh start


    上实践本人已经运行成功了,有错误或者不足之处,请指出。
     转载,请写明出处。乐意分享!

你可能感兴趣的:(cloud)