zoukankan      html  css  js  c++  java
  • Zookeeper系列(1):安装与介绍

    简介

    ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。

    Zookeeper数据模型

    Zookeeper数据模型的结构和Unix文件系统很类似,ZooKeeper中的每个节点都称为znode,znode默认能够存储1MB的数据,并且znode的路径是znode的唯一标识。

    Zookeeper中的节点分为以下四种类型:

    1.持久节点

    • 持久节点被创建后会一直存在,直到主动的删除这个节点。

    2.持久顺序节点

    • 持久顺序节点具备持久节点的特性,并且持久顺序节点在创建时,Zookeeper会自动的在该节点名后添加一个数字后缀,这个数字后缀是有序的,由父节点维护。

    3.临时节点

    • 临时节点类似于持久节点,区别在于在客户端会话断开时,该客户端创建的临时节点将被自动删除。并且临时节点下不能创建子节点。

    4.临时顺序节点

    • 临时顺序节点类似于持久顺序节点,区别在于在客户端会话断开时,该客户端创建的临时顺序节点将被自动删除。并且临时顺序节点下不能创建子节点。

    Linux安装Zookeeper

    下载Zookeeper:

    cd /opt/
    wget https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz
    

    解压缩:

    tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz
    

    创建数据存储目录:

    mkdir /opt/zkdata
    

    将config目录下的zoo_sample.cfg重命名为zoo.cfg:

    mv zoo_sample.cfg zoo.cfg
    

    修改zoo.cfg中的dataDir为上面创建数据存储目录:

    dataDir=/opt/zkdata
    
    启动Zookeeper

    使用默认配置zoo.cfg启动Zookeeper:

    . /opt/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start
    

    指定配置文件启动Zookeeper:

    . /opt/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start /opt/apache-zookeeper-3.6.3-bin/conf/zoo.cfg
    

    使用jps查看Zookeeper是否已经启动:

    QuorumPeerMain为Zookeeper进程。

    [root@localhost ~]# jps
    2201 QuorumPeerMain
    2235 Jps
    
    启动客户端连接到Zookeeper:

    不指定server参数,默认连接到本地的Zookeeper(localhost:2181):

    . /opt/apache-zookeeper-3.6.3-bin/bin/zkCli.sh
    

    指定IP地址和端口,连接Zookeeper:

    . /opt/apache-zookeeper-3.6.3-bin/bin/zkCli.sh -server localhost:2181
    
    ZooKeeper服务器其他命令

    在前台启动ZooKeeper服务器:

    . /opt/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start-foreground
    

    重启ZooKeeper服务器:

    . /opt/apache-zookeeper-3.6.3-bin/bin/zkServer.sh restart
    

    停止ZooKeeper服务器:

    . /opt/apache-zookeeper-3.6.3-bin/bin/zkServer.sh stop
    

    配置文件解析

    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.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    dataDir=/opt/zkdata
    # 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
    
    ## Metrics Providers
    #
    # https://prometheus.io Metrics Exporter
    #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
    #metricsProvider.httpPort=7000
    #metricsProvider.exportJvmInfo=true
    

    tickTime:Zookeeper与客户端的心跳间隔时间(单位毫秒)。

    initLimit:Zookeeper集群中Leader和Follower之间初始连接的最大心跳数量。

    syncLimit:运行过程中Zookeeper集群中Leader和Follower之间的最大心跳数量。

    dataDir:数据存储位置。

    clientPort:监听客户端连接的端口,即客户端尝试连接的端口。

    maxClientCnxns:最大并发连接数。

    autopurge.snapRetainCount:指定dataDir中保留的快照数量。

    autopurge.purgeInterval:清除任务的时间间隔(小时),设置为“0”表示禁用自动清除功能。

    metricsProvider.className:设置为“org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider”以启用Prometheus.io导出器。

    metricsProvider.httpPort:Prometheus.io导出器将启动Jetty服务器并绑定到该端口,默认为7000。

    metricsProvider.exportJvmInfo:如果将此属性设置为true,则Prometheus.io将导出有关JVM的指标,默认值为true。

  • 相关阅读:
    CodeForces 347B Fixed Points (水题)
    CodeForces 347A Difference Row (水题)
    CodeForces 346A Alice and Bob (数学最大公约数)
    CodeForces 474C Captain Marmot (数学,旋转,暴力)
    CodeForces 474B Worms (水题,二分)
    CodeForces 474A Keyboard (水题)
    压力测试学习(一)
    算法学习(一)五个常用算法概念了解
    C#语言规范
    异常System.Threading.Thread.AbortInternal
  • 原文地址:https://www.cnblogs.com/seve/p/14701635.html
Copyright © 2011-2022 走看看