Zookeeper

zookeeper安装配置

准备4台机器(4台虚拟机)

安装zookeeper之前先安装jdk

下载zookeeper,apache-zookeeper-3.5.10-bin.tar.gz ,放到 /home/ludalong/zookeeper 解压,

本地虚拟机安装的zookeeper目录 /home/ludalong/zookeeper

编辑 zoo.cfg (在config目录下)

# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/var/dalong/zk
# 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=192.168.37.131:2888:3888
server.2=192.168.37.132:2888:3888
server.3=0.0.0.0:2888:3888
server.4=192.168.37.134:2888:3888

建文件myid

创建/var/dalong/zk 目录(对应zoo.cfg文件中的dataDir路径) 再创建文件myid,写入内容 1,1是当前zookeeper的id

将zookeeper home写入环境变量

vi /etc/profile


export JAVA_HOME=/home/ludalong/zookeeper/jdk-11.0.15.1
export CLASSPATH=$JAVA_HOME/lib
export ZOOKEEPER_HOME=/home/ludalong/zookeeper/apache-zookeeper-3.5.10-bin
export KAFKA_HOME=/var/dalong/kafka
export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$KAFKA_HOME/bin

//让配置文件生效

source /etc/profile

zookeeper的命令


[root@k8s-master01 zk]# zkServer.sh
ZooKeeper JMX enabled by default
Using config: /home/ludalong/zookeeper/apache-zookeeper-3.5.10-bin/bin/../conf/zoo.cfg
Usage: /home/ludalong/zookeeper/apache-zookeeper-3.5.10-bin/bin/zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|restart|status|print-cmd}

启动命令

zkServer.sh start-foreground

zoo.cfg文件里写了4台,只有超过半数,即达到3台即可以投票选举leader,zookeeper可正常运行

zkCli.sh 进入zookeeper

zookeeper内部命令

[zk: localhost:2181(CONNECTED) 3] ls /
[admin, brokers, cluster, config, consumers, controller_epoch, feature, isr_change_notification, kafka, latest_producer_id_block, log_dir_event_notification, zookeeper]
[zk: localhost:2181(CONNECTED) 4] create  /test  "test123"
Created /test
[zk: localhost:2181(CONNECTED) 5] get /test
test123
[zk: localhost:2181(CONNECTED) 6] ls /
[admin, brokers, cluster, config, consumers, controller_epoch, feature, isr_change_notification, kafka, latest_producer_id_block, log_dir_event_notification, test, zookeeper]
[zk: localhost:2181(CONNECTED) 7] help
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
[zk: localhost:2181(CONNECTED) 8] get /test -s
test123
cZxid = 0x1500000005
ctime = Thu Mar 16 16:06:51 PDT 2023
mZxid = 0x1500000005
mtime = Thu Mar 16 16:06:51 PDT 2023
pZxid = 0x1500000005
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
[zk: localhost:2181(CONNECTED) 9]

[zk: localhost:2181(CONNECTED) 0] create -s  /test/xxx
Created /test/xxx0000000001
[zk: localhost:2181(CONNECTED) 1] ls /test
[xxx0000000000, xxx0000000001]

上面命令行中 cZxid = 0x1500000005 是事务id

create -s 创建目录防止重命名

Zookeeper是一个目录树结构

node可以存储1M数据

Zookeeper有两种状态 1.可用状态 2 不可以状态 当leader挂了即不可用

写的请求都进入leader,按顺序写入

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值