设为首页 收藏本站
查看: 1038|回复: 0

[经验分享] zookeeper之系列二:安装

[复制链接]

尚未签到

发表于 2019-1-8 12:14:14 | 显示全部楼层 |阅读模式
  ZooKeeper的安装模式分为三种,分别为:单机模式(stand-alone)、集群模式和集群伪分布模式。ZooKeeper 单机模式的安装相对比较简单,如果第一次接触ZooKeeper的话,建议安装ZooKeeper单机模式或者集群伪分布模式。
  1)单机模式
  首先,从Apache官方网站下载一个ZooKeeper 的最近稳定版本。
  http://hadoop.apache.org/zookeeper/releases.html
  作为国内用户来说,选择最近的的源文件服务器所在地,能够节省不少的时间。
  http://labs.renren.com/apache-mirror//hadoop/zookeeper/
  ZooKeeper 要求 JAVA 的环境才能运行,并且需要 JAVA6 以上的版本,可以从 SUN 官网上下载,并对 JAVA 环境变量进行设置。除此之外,为了今后操作的方便,我们需要对 ZooKeeper 的环境变量进行配置,方法如下,在 /etc/profile 文件中加入如下的内容:
  #Set ZooKeeper Enviroment
  export ZOOKEEPER_HOME=/root/hadoop-0.20.2/zookeeper-3.3.1
  export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf
  ZooKeeper 服务器包含在单个 JAR 文件中,安装此服务需要用户创建一个配置文档,并对其进行设置。我们在 ZooKeeper-*.*.* 目录(我们以当前 ZooKeeper 的最新版 3.3.1 为例,故此下面的“ ZooKeeper-*.*.* ”都将写为“ ZooKeeper-3.3.1” )的 conf 文件夹下创建一个 zoo.cfg 文件,它包含如下的内容:
  tickTime=2000
  dataDir=/var/zookeeper
  clientPort=2181
  在这个文件中,我们需要指定 dataDir 的值,它指向了一个目录,这个目录在开始的时候需要为空。下面是每个参数的含义:
  tickTime :基本事件单元,以毫秒为单位。它用来指示心跳,最小的 session 过期时间为两倍的 tickTime. 。
  dataDir :存储内存中数据库快照的位置,如果不设置参数,更新事务日志将被存储到默认位置。
  clientPort :监听客户端连接的端口
  使用单机模式时用户需要注意:这种配置方式下没有 ZooKeeper 副本,所以如果 ZooKeeper 服务器出现故障,ZooKeeper 服务将会停止。
  以下代码清单 A 是我们的根据自身情况所设置的 zookeeper 配置文档: zoo.cfg
  代码清单 A : zoo.cfg
  # The number of milliseconds of each tick
  tickTime=2000
  # the directory where the snapshot is stored.
  dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/snapshot/data
  # the port at which the clients will connect
  clientPort=2181
  2)集群模式
  为了获得可靠的 ZooKeeper 服务,用户应该在一个集群上部署 ZooKeeper 。只要集群上大多数的 ZooKeeper服务启动了,那么总的 ZooKeeper 服务将是可用的。另外,最好使用奇数台机器。 如果 zookeeper 拥有 5 台机器,那么它就能处理 2 台机器的故障了。
  之后的操作和单机模式的安装类似,我们同样需要对 JAVA 环境进行设置,下载最新的 ZooKeeper 稳定版本并配置相应的环境变量。不同之处在于每台机器上 conf/zoo.cfg 配置文件的参数设置,参考下面的配置:
  tickTime=2000
  dataDir=/var/zookeeper/
  clientPort=2181
  initLimit=5
  syncLimit=2
  server.1=zoo1:2888:3888
  server.2=zoo2:2888:3888
  server.3=zoo3:2888:3888
  “ server.id=host:port:port. ”指示了不同的 ZooKeeper 服务器的自身标识,作为集群的一部分的机器应该知道ensemble 中的其它机器。用户可以从“ server.id=host:port:port. ”中读取相关的信息。 在服务器的 data ( dataDir 参数所指定的目录)目录下创建一个文件名为 myid 的文件,这个文件中仅含有一行的内容,指定的是自身的 id值。比如,服务器“ 1 ”应该在 myid 文件中写入“ 1 ”。这个 id 值必须是 ensemble 中唯一的,且大小在 1 到 255之间。这一行配置中,第一个端口( port )是从( follower )机器连接到主( leader )机器的端口,第二个端口是用来进行 leader 选举的端口。在这个例子中,每台机器使用三个端口,分别是: clientPort , 2181 ; port , 2888; port , 3888 。
  我们在拥有三台机器的 Hadoop 集群上测试使用 ZooKeeper 服务,下面代码清单 B 是我们根据自身情况所设置的 ZooKeeper 配置文档:
  代码清单 B : 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.
  dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/snapshot/d1
  # the port at which the clients will connect
  clientPort=2181
  server.1=IP1:2887:3887
  server.2=IP2:2888:3888
  server.3=IP3:2889:3889
  清单中的 IP 分别对应的配置分布式 ZooKeeper 的 IP 地址。当然,也可以通过机器名访问 zookeeper ,但是需要在 ubuntu 的 hosts 环境中进行设置。读者可以查阅 Ubuntu 以及 Linux 的相关资料进行设置。
  3)集群伪分布
  简单来说,集群伪分布模式就是在单机下模拟集群的ZooKeeper服务。
  那么,如何对配置 ZooKeeper 的集群伪分布模式呢?其实很简单,在 zookeeper 配置文档中, clientPort 参数用来设置客户端连接 zookeeper 的端口。 server.1=IP1:2887:3887 中, IP1 指示的是组成 ZooKeeper 服务的机器 IP 地址, 2887 为用来进行 leader 选举的端口, 3887 为组成 ZooKeeper 服务的机器之间通信的端口。集群伪分布模式我们使用每个配置文档模拟一台机器,也就是说,需要在单台机器上运行多个 zookeeper 实例。但是,我们必须要保证各个配置文档的 clientPort 不能冲突。
  下面是我们所配置的集群伪分布模式,通过 zoo1.cfg , zoo2.cfg , zoo3.cfg 模拟了三台机器的 ZooKeeper 集群。详见代码清单 C :
  代码清单C : zoo1.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.
  dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/d_1
  # the port at which the clients will connect
  clientPort=2181
  server.1=localhost:2887:3887
  server.2=localhost:2888:3888
  server.3=localhost:2889:3889
  zoo2.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.
  dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/d_2
  # the port at which the clients will connect
  clientPort=2182
  #the location of the log file
  dataLogDir=/root/hadoop-0.20.2/zookeeper-3.3.1/logs
  server.1=localhost:2887:3887
  server.2=localhost:2888:3888
  server.3=localhost:2889:3889
  zoo3.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.
  dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/d_2
  # the port at which the clients will connect
  clientPort=2183
  #the location of the log file
  dataLogDir=/root/hadoop-0.20.2/zookeeper-3.3.1/logs
  server.1=localhost:2887:3887
  server.2=localhost:2888:3888
  server.3=localhost:2889:3889
  从上述三个代码清单中可以看到,除了 clientPort 不同之外, dataDir 也不同。另外,不要忘记在 dataDir 所对应的目录中创建 myid 文件来指定对应的 zookeeper 服务器实例。
  这里ZooKeeper的安装已经说完了,下一节我们来谈一谈对ZooKeeper的参数配置 的理解。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-660756-1-1.html 上篇帖子: zookeeper 应用场景 下篇帖子: zookeeper选举机制及相关概念
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表