• zookeeper源码(01)集群启动


    本文介绍一下zookeeper-3.5.7集群安装。

    解压安装

    tar zxf apache-zookeeper-3.5.7-bin.tar.gz
    
    • 1

    创建数据、日志目录:

    mv apache-zookeeper-3.5.7-bin /app/zookeeper-3.5.7
    cd /app/zookeeper-3.5.7
    
    mkdir data
    mkdir logs
    
    • 1
    • 2
    • 3
    • 4
    • 5

    编辑配置文件

    zoo.cfg文件

    cp conf/zoo_sample.cfg conf/zoo.cfg
    
    • 1

    编辑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=/app/zookeeper-3.5.7/data
    # 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=cloud-server-8:2888:3888
    server.2=cloud-server-9:2888:3888
    server.3=cloud-server-10:2888:3888
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    myid文件

    echo '1' > data/myid
    
    • 1

    启动zookeeper

    启动/停止zookeeper服务

    # 启动服务
    ./bin/zkServer.sh start
    
    # 停止服务
    ./bin/zkServer.sh stop
    
    • 1
    • 2
    • 3
    • 4
    • 5

    zkServer.sh脚本

    # ./bin/zkServer.sh -help
    ZooKeeper JMX enabled by default
    Using config: /app/zookeeper-3.5.7/bin/../conf/zoo.cfg
    Usage: ./bin/zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|restart|status|print-cmd}
    
    • 1
    • 2
    • 3
    • 4

    客户端

    启动客户端

    ./bin/zkCli.sh
    
    • 1

    默认连接localhost:2181的zookeeper服务,可以使用-server选项指定服务器地址。

    zkCli.sh脚本

    # ./bin/zkCli.sh help
    Connecting to localhost:2181
    ZooKeeper -server host:port cmd args
            addauth scheme auth
            close
            config [-c] [-w] [-s]
            connect host:port
            create [-s] [-e] [-c] [-t ttl] path [data] [acl]
            delete [-v version] path
            deleteall path
            delquota [-n|-b] path
            get [-s] [-w] path
            getAcl [-s] path
            history
            listquota path
            ls [-s] [-w] [-R] path
            ls2 path [watch]
            printwatches on|off
            quit
            reconfig [-s] [-v version] [[-file path] | \
                     [-members serverID=host:port1:port2;port3[,...]*]] | \
                     [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
            redo cmdno
            removewatches path [-c|-d|-a] [-l]
            rmr path
            set [-s] [-v version] path data
            setAcl [-s] [-v version] [-R] path acl
            setquota -n|-b val path
            stat [-w] path
            sync path
    Command not found: Command not found help
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
  • 相关阅读:
    Jasper狂飙:AIGC现象级应用的增长秘笈
    【Leetcode】top 100 贪心算法
    如何选择高频器件功分器和耦合器的PCB材料
    软件测试的风险主要体现在哪里
    Java版分布式微服务云开发架构 Spring Cloud+Spring Boot+Mybatis 电子招标采购系统功能清单
    ZZNUOJ_用C语言编写程序实现1559:打印一颗树(附完整源码)
    python中的cachetools用法详解(Cached、LRUCache、TTLCache、LFUCache、RRCache)
    Day 00 python基础认识与软件安装
    SSM整合_年轻人的第一个增删改查_新增
    正则匹配以XXX开头的,XXX结束的
  • 原文地址:https://blog.csdn.net/xuguofeng2016/article/details/132972892