码迷,mamicode.com
首页 > 其他好文 > 详细

Zookeeper 分布式环境搭建

时间:2014-06-13 17:27:08      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

Zookeeper 分布式环境搭建

一、前期环境

  • 安装概览
IP Host Name     Software    
192.168.23.128     ae01 JDK 1.7
192.168.23.129 ae02 JDK 1.7
192.168.23.130 ae03 JDK 1.7
    若使用虚拟机安装,可以安装samba, smbfs方面对于文件的控制。
  • 系统环境: ubuntu-12.04.2-server-amd64
  • 安装目录: /usr/local/ae
  • JDK 安装目录: export JAVA_HOME=/usr/local/ae/jdk1.7.0_51
  • Zookeeper版本: zookeeper-3.4.5

二、Zookeeper 安装

  • 修改host文件,添加3台服务器的hostname, 以ae01 为例。
    user@ae01:/usr/local/ae$ sudo vim /etc/hosts
    127.0.0.1         localhost
    192.168.23.128    ae01
    192.168.23.129    ae02
    192.168.23.129    ae03
  • 解压zookeeper-3.4.5.tar.gz 到/usr/local/ae 目录
    user@ae01:/usr/local/ae$ sudo tar -zxvf zookeeper-3.4.5.tar.gz
  • 复制$ZOOKEEPER_HOME/conf/zoo_sample.cfg 为zoo.cfg 并修改
    user@ae01:/usr/local/ae/zookeeper-3.4.5/conf$ sudo vm zoo_sample.cfg zoo.cfg
  • 修改zoo.cfg
    bubuko.com,布布扣
    # The number of milliseconds of each tick
    tickTime=2000
    # The number of ticks that the initial 
    # synchronization phase can take
    initLimit=5
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    syncLimit=2
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    dataDir=/usr/local/ae/storage/zookeeper
    # the port at which the clients will connect
    clientPort=2181
    #
    # 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=ae01:2888:3888
    server.2=ae02:2888:3888
    server.3=ae03:2888:3888
    bubuko.com,布布扣
    dataDir 为Zookeeper保存数据的文件夹
    server.1=ae01:2888:3888 ‘2888‘为连接所使用的端口号,‘3888‘为选举leader使用的端口号
  • 复制zookeeper-3.4.5 到ae02,ae03
    user@ae01:/usr/local/ae$ scp -r zookeeper-3.3.5/ user@ae01:/usr/local/ae
    user@ae01:/usr/local/ae$ scp -r zookeeper-3.3.5/ user@ae02:/usr/local/ae
  • 设置myid
    user@ae01:/usr/local/ae$ echo "1" > /usr/local/ae/storage/zookeeper/myid
    user@ae02:/usr/local/ae$ echo "1" > /usr/local/ae/storage/zookeeper/myid
    user@ae03:/usr/local/ae$ echo "1" > /usr/local/ae/storage/zookeeper/myid

三、启动Zookeeper 集群

  • 启动Zookeeper
    user@ae01:/usr/local/ae/zookeeper-3.4.5/bin$ sudo zkServer.sh start
    user@ae02:/usr/local/ae/zookeeper-3.4.5/bin$ sudo zkServer.sh start
    user@ae03:/usr/local/ae/zookeeper-3.4.5/bin$ sudo zkServer.sh start

    由于ZooKeeper集群启动的时候,每个结点都试图去连接集群中的其它结点,先启动的肯定连不上后面还没启动的,日志前面部分出现连接异常(java.net.ConnectException: Connection refused )是可以忽略的。集群在选出一个Leader后,最后稳定了。

  • 验证启动
    user@ae01:/usr/local/ae/zookeeper-3.4.5/bin$ zkServer.sh status
    JMX enabled by default
    Using config: /usr/local/ae/zookeeper-3.4.5/bin/../conf/zoo.cfg
    Mode: leader
    user@ae02:/usr/local/ae/zookeeper-3.4.5/bin$ zkServer.sh status
    JMX enabled by default
    Using config: /usr/local/ae/zookeeper-3.4.5/bin/../conf/zoo.cfg
    Mode: follower
    user@ae03:/usr/local/ae/zookeeper-3.4.5/bin$ zkServer.sh status
    JMX enabled by default
    Using config: /usr/local/ae/zookeeper-3.4.5/bin/../conf/zoo.cfg
    Mode: follower

四、文档参考

  • http://zookeeper.apache.org/doc/trunk/zookeeperOver.html

Zookeeper 分布式环境搭建,布布扣,bubuko.com

Zookeeper 分布式环境搭建

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/tannerBG/p/3784540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!