zookeeper服务集群安装+测试+命令

    xiaoxiao2021-04-18  60

    zookeeper的安装测试

    1.下载zookeeper。//选择一个版本下载

    2.搭建多台linux虚拟机(各个虚拟机对应的hosts为m1,s1,s2)。

    3.把下载的zookeeper.tar.gz包拷贝到自己的目录下。执行tar –zvxf zookeeper.tar.gz

    4.修改环境变量

    vim/vi  /etc/profile

     在最后面添加:

    export ZOOKEEPER_HOME=/usr/local/program/zookeeper      export PATH=$ZOOKEEPER_HOME/bin:$PATH   注:修改完后profile记得执行source /etc/profile

    5.在解压后的zookeeper的目录下进入conf目录修改配置文件

    更名操作:mv zoo_sample.cfg zoo.cfg

    6.编辑zoo.cfg (vi zoo.cfg)

    修改dataDir=/home/hadoop/zookeeper/data/自己指定zookeeper的数据目录(这个目录必须存在且必须有myid文件,

    myid的值对应的是server.0=m1:2888:3888中的server.0中的0.不同的server上的myid的值不同

    新增server.0=m1:2888:3888//m1位liunx虚拟机的映射名称;2888为leader的对外接口;3888为flower的对外接口

             server.1=s1:2888:3888

             server.2=s2:2888:3888

    下面是zoo.cfg的配置文件详解:

    zoo.cfg配置信息详解

    # The number of milliseconds of each tick tickTime=2000 ##ZooKeeper的最小时间单元,单位毫秒(ms),默认值为3000 # The number of ticks that the initial # synchronization phase can take initLimit=10 ##Leader服务器等待Follower启动并完成数据同步的时间,默认值10,表示tickTime的10倍 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 ##Leader服务器和Follower之间进行心跳检测的最大延时时间,默认值5,表示tickTime的5倍 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/tmp/zookeeper ##ZooKeeper服务器存储快照文件的目录,必须配值,建议放置在var目录下 # the port at which the clients will connect clientPort=2181 ## 服务器对外服务端口,默认值为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 7. 到此为止 m1上的配置就已经完成;接下来配置s1s2. 把m1上的zookeeper的文件拷贝到s1,s2上(scp m1上的zookeeper目录s1/s2上的zookeeper目录) 8.分别设置s1,s2上的/etc/profile的环境变量 9.s1中zookeeper的basedir相应的myid中的值改为1s2zookeeper的basedir相应的myid中的值改为2 10.启动,在三个节点上分别执行命令zkServer.sh  start 11.三个节点的zookeeper都启动后。检验,在三个节点上分别执行命令zkServer.sh  status zookeeper的命令详解

    zookeeper四字命令的使用

    需要在linux系统中安装nc服务。yum install -y nc 操作命令的形式: [root@rocket zookeeper-server1]# echo stat |nc 127.0.0.1 2181

    zookeeper

    四字命令

    功能描述

    conf

    输出相关服务配置的详细信息。

    cons

    列出所有连接到服务器的客户端的完全的连接 /会话的详细信息。包括“接受 / 发送”的包数量、会话 id 、操作延迟、最后的操作执行等等信息。

    dump

    列出未经处理的会话和临时节点。

    envi

    输出关于服务环境的详细信息(区别于 conf命令)。

    reqs

    列出未经处理的请求

    ruok

    测试服务是否处于正确状态。如果确实如此,那么服务返回“imok ”,否则不做任何相应。

    stat

    输出关于性能和连接的客户端的列表。

    wchs

    列出服务器 watch的详细信息。

    wchc

    通过 session列出服务器 watch的详细信息,它的输出是一个与watch相关的会话的列表。

    wchp

    通过路径列出服务器 watch的详细信息。它输出一个与 session相关的路径

    zkServer.sh命令详解

    命令操作形式:[root@rocket zookeeper-server1]# bin/zkServer.sh status//status为命令参数 命令参数: start:开启服务; stop:停止服务; restart:重启服务; start-foreground:查看启动时报的是什么异常,同时也可以查看运行过程中的异常 upgrade:更新zookeeper; print-cmd:打印配置信息; help:列出参数,如下:

    [root@rocket zookeeper-server1]# bin/zkServer.sh help

    JMX enabled by default

    Using config: /usr/local/zookeeper-server1/bin/../conf/zoo.cfg

    Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}

    zkCli.sh命令详解

    链接:[root@rocket zookeeper-server1]# bin/zkCli.sh -server localhost:2181 [zk: localhost:2181(CONNECTED) 0] help//列出命令参数

            stat path [watch]

            set path data [version]

            ls path [watch]

            delquota [-n|-b] path

            ls2 path [watch]

            setAcl path acl

            setquota -n|-b val path

            history

            redo cmdno

            printwatches on|off

            delete path [version]

            sync path

            listquota path

            rmr path

            get path [watch]

            create [-s] [-e] path data acl

            addauth scheme auth

            quit

            getAcl path

            close

            connect host:port

    常用命令:

    1)查看当前节点列表

    [zk: localhost:2181(CONNECTED) 1] ls /

    [zookeeper]

    2)创建节点

    [zk: localhost:2181(CONNECTED) 2] create /test "test"

    Created /test

    [zk: localhost:2181(CONNECTED) 3] ls /

    [zookeeper, test]

    3)查看节点数据

    [zk: localhost:2181(CONNECTED) 4] get /test

    "test"

    cZxid = 0x300000007

    ctime = Thu Sep 24 05:54:51 PDT 2015

    mZxid = 0x300000007

    mtime = Thu Sep 24 05:54:51 PDT 2015

    pZxid = 0x300000007

    cversion = 0

    dataVersion = 0

    aclVersion = 0

    ephemeralOwner = 0x0

    dataLength = 6

    numChildren = 0

    4)设置节点数据

    [zk: localhost:2181(CONNECTED) 7] set /test "111111" 

    cZxid = 0x300000007

    ctime = Thu Sep 24 05:54:51 PDT 2015

    mZxid = 0x300000008

    mtime = Thu Sep 24 05:57:40 PDT 2015

    pZxid = 0x300000007

    cversion = 0

    dataVersion = 1

    aclVersion = 0

    ephemeralOwner = 0x0

    dataLength = 8

    numChildren = 0

    [zk: localhost:2181(CONNECTED) 8] get /test

    "111111"

    cZxid = 0x300000007

    ctime = Thu Sep 24 05:54:51 PDT 2015

    mZxid = 0x300000008

    mtime = Thu Sep 24 05:57:40 PDT 2015

    pZxid = 0x300000007

    cversion = 0

    dataVersion = 1

    aclVersion = 0

    ephemeralOwner = 0x0

    dataLength = 8

    numChildren = 0

    5)删除节点

    [zk: localhost:2181(CONNECTED) 9] delete /test

    [zk: localhost:2181(CONNECTED) 10] ls /

    [zookeeper]

    转载请注明原文地址: https://ju.6miu.com/read-674814.html

    最新回复(0)