zookeeper安装

zookeeper安装及使用

前言

对于大数据开发者来说,zookeeper肯定不陌生。尤其使用过Apache相关大数据组件的同僚而言,在熟悉不过。zookeeper是Apache Hadoop 的一个子项目,是一个分布式服务框架,官网介绍说:它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务、状态同步服务、集群管理、分布式应用配置项的管理等。它可以协调主节点和备份节点,解决单点故障问题及实现自动容灾功能。根据名字简言就是管理员,起到了监督管理作用。下面我们就来介绍一下安装。

一、下载安装包并解压

1、wget https://downloads.apache.org/zookeeper/zookeeper-3.6.0/apache-zookeeper-3.6.0.tar.gz
2、tar -xzvf apache-zookeeper-3.6.0.tar.gz -C /soft/
这里我的username 是 centos,如果/soft路径不存在,需要自己创建。
3、cd /soft/
进入到解压目录
4、ln -s apache-zookeeper-3.6.0 /soft/zk
然后创建软连接
5、sudo vim /etc/profile
配置环境变量
在最后添加
#配置zk路径
export ZOOKEEPER_HOME=/soft/zk
export PATH=$PATH:$ZOOKEEPER_HOME/bin
6、source /etc/profile
使环境变量生效
7、cd /soft/zk/conf && mv zoo_sample.cfg zoo.cfg
修改配置文件
8、zkServer.sh start
启动zk进程
7、jps (java进程都可以通过该命令查看)
验证
8、zkCli.sh
进入客户端命令行 -server ip:port

二、集群搭建

1、假设有3个nodes,将刚才的操作分别在其他nodes执行一遍,如果每个node的environment一样,可以分发
2、修改配置文件
vim /soft/zk/conf/zoo.cfg
=============================================
server.1=ip:2888:3888
server.2=ip:2888:3888
server.3=ip:2888:3888

#如果要使用observer,增换一下配置
#peerType=observer
#server.4:ip:2181:3181:observer
=============================================
#server.A=ip:B:C
根据实际情况填写ip,也可以填写域名。其中A是myid号,B是leader和followers之间通信的端口,C是当leader驾崩之后其他followers用于选举new leader用的通信端口。
3、在zoo.cfg configure file中有个dataDir 参数,在改参数指定的路径下运行echo -n A > myid
根据实际情况填写A
4、在每个node,启动zk
5、zkServer.sh status
检查zk 状态

三、configure

#The number of milliseconds of each tick
#tickTime:CS通信心跳数
#Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
tickTime=2000

#The number of ticks that the initial
#synchronization phase can take
#initLimit:LF初始通信时限
#集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
initLimit=5

#The number of ticks that can pass between
#sending a request and getting an acknowledgement
#syncLimit:LF同步通信时限
#集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
syncLimit=2

#the directory where the snapshot is stored.
#do not use /tmp for storage, /tmp here is just
#example sakes.
#dataDir:数据文件目录
#Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
dataDir=/home/centos/zookeeper-3.6.0/data

#dataLogDir:日志文件目录
#Zookeeper保存日志文件的目录。
dataLogDir=/home/centos/zookeeper-3.6.0//logs
#the port at which the clients will connect
#clientPort:客户端连接端口
#客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
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.
#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
#http://zookeeper.apache.org/doc/current/zookeeperAdmin.html
#服务器名称与地址:集群信息(服务器编号,服务器地址,LF通信端口,选举端口)
#这个配置项的书写格式比较特殊,规则如下:
server.A=ip:C:D

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值