阿里云CentOS7安装ZooKeeper单机模式

前提条件

阿里云CentOS7安装好jdk,可参 hadoop安装 的jdk安装部分

下载

复制代码
[hadoop@node1 ~]$ cd softinstall
[hadoop@node1 softinstall]$ wget https://archive.apache.org/dist/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz

解压

复制代码
[hadoop@node1 softinstall]$ ls
apache-zookeeper-3.7.1-bin.tar.gz  hadoop-3.3.4.tar.gz  jdk-8u271-linux-x64.tar.gz
[hadoop@node1 softinstall]$ tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz -C ~/soft

查看解压后的文件

复制代码
[hadoop@node1 softinstall]$ cd ~/soft
[hadoop@node1 soft]$ ls
apache-zookeeper-3.7.1-bin  hadoop-3.3.4  jdk1.8.0_271
​

配置环境变量

复制代码
[hadoop@node1 soft]$ sudo nano /etc/profile.d/my_env.sh

末尾添加如下内容

复制代码
export ZOOKEEPER_HOME=/home/hadoop/soft/apache-zookeeper-3.7.1-bin
export PATH=$PATH:$ZOOKEEPER_HOME/bin

让配置生效

复制代码
source /etc/profile

配置ZooKeeper

复制代码
[hadoop@node1 soft]$ cd $ZOOKEEPER_HOME/conf
[hadoop@node1 conf]$ ls
configuration.xsl  log4j.properties  zoo_sample.cfg
[hadoop@node1 conf]$ mv zoo_sample.cfg zoo.cfg
[hadoop@node1 conf]$ nano zoo.cfg 

修改dataDir的值如下

复制代码
dataDir=/home/hadoop/soft/apache-zookeeper-3.7.1-bin/zkData

启动ZooKeeper服务

复制代码
[hadoop@node1 conf]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/hadoop/soft/apache-zookeeper-3.7.1-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
​

看到Starting zookeeper ... STARTED输出,说明启动成功

查看进程

复制代码
[hadoop@node1 conf]$ jps
20178 Jps
18391 QuorumPeerMain

QuorumPeerMain进程是ZooKeeper服务端的进程。

查看状态

复制代码
[hadoop@node1 conf]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hadoop/soft/apache-zookeeper-3.7.1-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone

看到Mode为standalone(单机)模式。

ZooKeeper命令行的简单操作

进入客户端

复制代码
[hadoop@node1 conf]$ zkCli.sh 

看到部分输出信息如下

复制代码
2024-03-28 21:17:48,132 [myid:] - INFO  [main:ClientCnxn@1735] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2024-03-28 21:17:48,166 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1171] - Opening socket connection to server localhost/127.0.0.1:2181.
2024-03-28 21:17:48,167 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2024-03-28 21:17:48,203 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1005] - Socket connection established, initiating session, client: /127.0.0.1:52730, server: localhost/127.0.0.1:2181
2024-03-28 21:17:48,287 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1446] - Session establishment complete on server localhost/127.0.0.1:2181, session id = 0x10005db0b280000, negotiated timeout = 30000
​
WATCHER::
​
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]

查看帮助

复制代码
[zk: localhost:2181(CONNECTED) 0] help
ZooKeeper -server host:port -client-configuration properties-file cmd args
    addWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVE
    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 [-b batch size]
    delquota [-n|-b|-N|-B] path
    get [-s] [-w] path
    getAcl [-s] path
    getAllChildrenNumber path
    getEphemerals path
    history 
    listquota path
    ls [-s] [-w] [-R] path
    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]
    set [-s] [-v version] path data
    setAcl [-s] [-v version] [-R] path acl
    setquota -n|-b|-N|-B val path
    stat [-w] path
    sync path
    version 
    whoami 
Command not found: Command not found help

退出客户端

复制代码
[zk: localhost:2181(CONNECTED) 1] quit
​
WATCHER::
​
WatchedEvent state:Closed type:None path:null
2024-03-28 21:18:00,150 [myid:] - INFO  [main:ZooKeeper@1288] - Session: 0x10005db0b280000 closed
2024-03-28 21:18:00,151 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@568] - EventThread shut down for session: 0x10005db0b280000
2024-03-28 21:18:00,154 [myid:] - ERROR [main:ServiceUtils@48] - Exiting JVM with code 127

关闭ZooKeeper服务端

复制代码
[hadoop@node1 conf]$ zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /home/hadoop/soft/apache-zookeeper-3.7.1-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
​

查看进程

复制代码
[hadoop@node1 conf]$ jps
20493 Jps

发现ZooKeeper服务端进程已关闭。

完成!enjoy it!

相关推荐
Java林间7 小时前
Zookeeper是什么?基于zookeeper实现分布式锁
分布式·zookeeper·wpf
云闲不收8 小时前
CAP原理,zookeeper是强一致性么?为什么zookeeper不满足线性一致性依然可以实现分布式锁?
分布式·zookeeper·云原生
XINVRY-FPGA14 小时前
XCZU19EG-2FFVC1760I Xilinx赛灵思FPGA Zynq UltraScale+MPSoC
c++·嵌入式硬件·阿里云·fpga开发·云计算·硬件工程·fpga
Saggitarxm1 天前
阿里云镜像加速仅支持阿里云产品了
阿里云·docker·云计算·镜像加速
TIF星空1 天前
【在阿里云或其他 CentOS/RHEL 系统上安装和配置 Dante SOCKS5 代理服务】
经验分享·笔记·阿里云·centos·云计算
podoor2 天前
在阿里云虚拟主机上启用WordPress伪静态
阿里云·wordpress伪静态
中电金信2 天前
中电金信联合阿里云推出智能陪练Agent
阿里云·云计算
zqh176736464692 天前
2025年阿里云云计算ACP高级工程师认证模拟试题(附答案解析)
阿里云·云计算·阿里云acp·阿里云acp云计算·acp云计算
奔跑的皮皮虾2 天前
Laravel 对接阿里云 OSS 说明文档
阿里云·php·laravel
XINVRY-FPGA2 天前
XCZU7EG‑L1FFVC1156I 赛灵思XilinxFPGA ZynqUltraScale+ MPSoC EG
c++·嵌入式硬件·阿里云·fpga开发·云计算·fpga·pcb工艺