zookeeper安装

来源:互联网 发布:淘宝美工设计难学吗 编辑:程序博客网 时间:2024/06/12 19:49

一、简介

首先,我们来看下上面是zookeeper?

根据官方的说明:zookeeper是一个分布式的应用程序协调服务(中心)。通俗点来讲,就是调度中心。具体原文如下:

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.

有兴趣可以直接访问:【zookeeper官网】进行查看更多信息。

二、Zookeeper环境搭建
【1】准备工作
1、下载安装包,具体地址见官网。
2、安装虚拟机或cent os等操作系统。
【2】安装
1、上传安装包至自定义路径,并使用命令解压到某一路径(tar -zxvf zookeeper-3.4.6.tar.gz)
2、切换到解压后目录,找到conf目录,并拷贝zoo_sample.cfg文件为zoo.cfg
3、修改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 anacknowledgement
 
syncLimit=5
 
# the directory where the snapshot isstored. //镜像数据位置
 
dataDir=D:\\data\\zookeeper
 
#日志位置
 
dataLogDir=D:\\logs\\zookeeper
 
# the port at which the clients willconnect 客户端连接的端口
 
clientPort=2181
4、如果是集群环境,则需要添加集群地址的配置,具体如下:
#这个是zookeeper集群环境的节点配置,前面是节点名后面是ip或者hostname
server.1=data1:2888:3888
server.2=data2:2888:3888
server.3=data3:2888:3888
然后在对应的data文件夹下(如上面的dataDir=D:\\data\\zookeeper)创建文件,myid(即文本文件,不管后缀名)。文件内容为当前文件所在的节点编号。
需要注意的是:
    a、zoo.cfg每个集群节点机器都需要,还有myid文件;
    b、检查ip是否正确。
注意:centos7系统可以使用下面的命令永久改变主机名。
1)查看主机名
hostnamectl status
2)修改主机名
sudo hostnamectl set-hostname newhostname
5、异常处理
(1)INFO zookeeper.ZooKeeper: Session: 0x0 closed
可能原因:
        1、zookeeper没有启动。
        2、zookeeper有“选举领导者”机制,当失效节点占比过半时,将停止工作。


原创粉丝点击