zoukankan      html  css  js  c++  java
  • zookeeper的安装和使用

    文章作者:foochane

    原文链接:https://foochane.cn/article/2019062601.html

    zookeeper数据存储形式 zookeeper安装 zookeeper命令行客户端的使用

    1 zookeeper数据存储形式

    zookeeper中对用户的数据采用kv形式存储

    key:是以路径的形式表示的,各key之间有父子关系,比如 / 是顶层key

    用户建的key只能在/ 下作为子节点,比如建一个key: /aa 这个key可以带value数据

    也可以建一个key/bb

    也可以建多个key/aa/xx

    zookeeper中,对每一个数据key,称作一个znode

    2 znode类型

    zookeeper中的znode有多种类型:

    • 1、PERSISTENT 持久的:创建者就算跟集群断开联系,该类节点也会持久存在与zk集群中
    • 2、EPHEMERAL 短暂的:创建者一旦跟集群断开联系,zk就会将这个节点删除
    • 3、SEQUENTIAL 带序号的:这类节点,zk会自动拼接上一个序号,而且序号是递增的

    组合类型:

    • PERSISTENT :持久不带序号
    • EPHEMERAL :短暂不带序号
    • PERSISTENTSEQUENTIAL :持久且带序号
    • EPHEMERALSEQUENTIAL :短暂且带序号

    3 安装zookeeper

    解压安装包 zookeeper-3.4.6.tar.gz

    修改conf/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=/usr/local/bigdata/data/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
    server.1=Master:2888:3888
    server.2=Slave01:2888:3888
    server.3=Slave02:2888:3888
    

    对3台节点,都创建目录 /usr/local/bigdata/data/zkdata

    对3台节点,在工作目录中生成myid文件,但内容要分别为各自的id1,2,3

    Master上:   echo 1 > /usr/local/bigdata/data/zkdata/myid
    Slave01上:  echo 2 > /usr/local/bigdata/data/zkdata/myid
    Slave02上:  echo 3 > /usr/local/bigdata/data/zkdata/myid
    

    4 启动zookeeper集群

    zookeeper没有提供自动批量启动脚本,需要手动一台一台地起zookeeper进程
    在每一台节点上,运行命令:

    $ bin/zkServer.sh start
    
    

    启动后,用jps应该能看到一个进程:QuorumPeerMain

    查看状态

    $ bin/zkServer.sh status
    
    

    5 编写启动脚本zkmanage.sh

    zookeeper没有提供批量脚本,不能像hadoop一样在一台机器上同时启动所有节点,可以自己编写脚本批量启动。

    #!/bin/bash
    for host in Master Slave01 Slave02
    do
    echo "${host}:${1}ing....."
    ssh $host "source ~/.bashrc;/usr/local/bigdata/zookeeper-3.4.6/bin/zkServer.sh $1"
    done
    
    sleep 2
    
    for host in Master Slave01 Slave02
    do
    ssh $host "source ~/.bashrc;/usr/local/bigdata/zookeeper-3.4.6/bin/zkServer.sh status"
    done
    
    
    • $1 :指接收第一个参数

    运行命令:

    sh zkmanage.sh start #启动
    sh zkmanage.sh stop  #停止
    
    

    6 zookeeper命令行客户端

    启动本地客户端:

    $ bin/zkCli.sh
    
    

    启动其他机器的客户端:

    $ bin/zkCli.sh -server Master:2181
    
    

    基本命令:

    • 查看帮助:help
    • 查看目录:ls /
    • 查看节点数据:get /zookeeper
    • 插入数据: create /节点 数据 , 如:create /aa hello
    • 更改某节点数据: set /aa helloworld
    • 删除数据:rmr /aa/bb
    • 注册监听:get /aa watch -->数据发生改变会通知 ; ls /aa watch -->目录发现改变也会通知
  • 相关阅读:
    Tiburon 支持 Unicode 的 LoadFromFile, SaveToFile
    截图:截取当前程序的界面,并保存到bmp图片中。
    List和string
    Can/CanOpen资料
    C语言的字节对齐及#pragma pack的使用
    Delphi操作Excel(2) Stringgrid导出到Excel
    zt:16进制Motorola Srecords 文件格式
    Python核心教程(第二版)读书笔记(二)
    Python核心教程(第二版)读书笔记(一)
    Python核心教程(第二版)读书笔记(三)
  • 原文地址:https://www.cnblogs.com/foochane/p/11110515.html
Copyright © 2011-2022 走看看