Zookeeper简介和部署

来源:互联网 发布:淘宝客服务要订吗 编辑:程序博客网 时间:2024/06/14 21:06

Zookeeper简介和部署

1.zookeeper简介

       zookeeper分布式服务框架是Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题。例如,统一命名服务、状态同步服务、集权管理、分布式应用配置项的管理等。
       zookeeper是以Fast Paxos算法为基础的。
       zookeeper集群初始化过程:集群中所用机器以投票的方式(少数服从多数)选取一台作为leader(领导者),其余机器作为follower(追随者)。如果集群中只有一台机器,那么就这太机器就是leader,没有follower。
       zookeeper集群与客户端的交互:客户端可以在任意情况下,与zookeeper集群中任意一台机器上进行读操作;但是写操作必须得到leader的同意后才可执行。
       zookeeper选取leader的核心算法思想:如果某服务器获得N/2+1票,则该服务器成为leader,其中N为集群中机器数量。为了避免出现两台服务器获得相同票数(N/2),应该确保N为奇数,因此构建zookeeper集群最少需要3台机器。

2.zookeeper部署

2.1安装JDK

2.2 修改配置文件

1.ip及主机名

IP hostname 192.168.232.128 master 192.168.232.129 slave01 192.168.232.130 slave02

2.解压zookeeper-3.4.8.tar.gz

    tar -zxvf zookeeper-3.4.8.tar.gz

3.修改配置文件zoo.cfg
    将conf目录下的zoo_sample.cfg复制成zoo.cfg

    cd /usr/local/zookeeper/conf    mv zoo_sample.cfg zoo.cfg

   打开zoo.cfg,并编辑

   vi zoo.cfg   --------------------------------------   # 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=/usr/local/zookeeper/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   #The directory where the log is stored.   dataLogDir=/usr/local/zookeeper/log   server.1=master:2888:3888   server.2=slave01:2888:3888   server.3=slave02:2888:3888

    创建文件

mkdir /usr/local/zookeeper/datamkdir /usr/local/zookeeper/log

  将/usr/local/zookeeper目录传到另外两台机器上

scp -r /usr/local/zookeeper root@slave01:/usr/local/scp -r /usr/local/zookeeper root@slave02:/usr/local/

  分别在在三个节点上/usr/local/zookeeper/data目录下创建文件myid,并分别在myid上按照配置文件zoo.cfg中server.中的id的数值,在不同机器上的文件中填上相应数组

cd /usr/local/zookeeper/dataecho "1" >> myid    --masterecho "2" >> myid    --slave01echo "3" >> myid    --slave02

2.3启动zookeeper集群

分别进入三个节点的bin目录,启动zookeeper

cd /usr/local/zookeeper/bin./zkServer.sh start

查看zookeeper的状态信息

./zkServer.sh status

follower
leader

3.问题

  启动zookeeper集群后,查看状态看见Error contacting service. It is probably not running.
解决方案

原创粉丝点击