zookeeper源码(01)集群启动

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

解压安装

shell 复制代码
tar zxf apache-zookeeper-3.5.7-bin.tar.gz

创建数据、日志目录:

shell 复制代码
mv apache-zookeeper-3.5.7-bin /app/zookeeper-3.5.7
cd /app/zookeeper-3.5.7

mkdir data
mkdir logs

编辑配置文件

zoo.cfg文件

shell 复制代码
cp conf/zoo_sample.cfg conf/zoo.cfg

编辑conf/zoo.cfg文件:

properties 复制代码
# 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

myid文件

shell 复制代码
echo '1' > data/myid

启动zookeeper

启动/停止zookeeper服务

shell 复制代码
# 启动服务
./bin/zkServer.sh start

# 停止服务
./bin/zkServer.sh stop

zkServer.sh脚本

shell 复制代码
# ./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}

客户端

启动客户端

shell 复制代码
./bin/zkCli.sh

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

zkCli.sh脚本

shell 复制代码
# ./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
相关推荐
皮皮林55110 小时前
IDEA 源码阅读利器,你居然还不会?
java·intellij idea
卡尔特斯15 小时前
Android Kotlin 项目代理配置【详细步骤(可选)】
android·java·kotlin
白鲸开源15 小时前
Ubuntu 22 下 DolphinScheduler 3.x 伪集群部署实录
java·ubuntu·开源
ytadpole15 小时前
Java 25 新特性 更简洁、更高效、更现代
java·后端
纪莫15 小时前
A公司一面:类加载的过程是怎么样的? 双亲委派的优点和缺点? 产生fullGC的情况有哪些? spring的动态代理有哪些?区别是什么? 如何排查CPU使用率过高?
java·java面试⑧股
JavaGuide16 小时前
JDK 25(长期支持版) 发布,新特性解读!
java·后端
用户37215742613516 小时前
Java 轻松批量替换 Word 文档文字内容
java
白鲸开源16 小时前
教你数分钟内创建并运行一个 DolphinScheduler Workflow!
java
Java中文社群17 小时前
有点意思!Java8后最有用新特性排行榜!
java·后端·面试
代码匠心17 小时前
从零开始学Flink:数据源
java·大数据·后端·flink