ubuntu18.04下zookeeper安装与简单使用

下载与解压

官网下载地址

Apache ZooKeeper

解压

tar -zxvf zookeeper-3.4.10.tar.gz

环境准备

zookeeper基于java开发,因此首先需要安装java的jdk包

bash 复制代码
sudo apt-get install openjdk-8-jdk

修改配置

进入解压目录里的conf文件夹内

bash 复制代码
mv zoo_sample.cfg zoo.cfg
bash 复制代码
 vim zoo.cfg 

如图所示,打开配置文件后,修改zk节点的数据存放目录,原来的数据存放目录是tmp文件夹,但是tmp文件夹是临时性文件,一旦重启数据就会丢失,笔者直接在解压后的zookeeper文件夹内创建了一个data目录,用于存放zk节点的数据。读者可自行定义数据存放目录

配置环境变量

bash 复制代码
sudo vim /etc/profile

在文件末尾添加

bash 复制代码
  export ZOOKEEPER=/home/pcl/softPages/zookeeper/zookeeper-3.4.10/
  export PATH=$PATH:$ZOOKEEPER/bin

其中/home/pcl/softPages/zookeeper/zookeeper-3.4.10/是笔者解压zookeeper后的文件路径

使配置文件生效

bash 复制代码
source /etc/profile

启动zk

启动zk服务端

bash 复制代码
zkServer.sh start

查看zk服务端是否启动成功

bash 复制代码
ps -ef | grep zook

启动zk客户端

bash 复制代码
zkCli.sh

启动成功会显示如下信息

bash 复制代码
Connecting to localhost:2181
2024-03-10 17:39:05,832 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
2024-03-10 17:39:05,834 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=robot
2024-03-10 17:39:05,834 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_362
2024-03-10 17:39:05,836 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Private Build
2024-03-10 17:39:05,836 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-8-openjdk-amd64/jre
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../build/classes:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../build/lib/*.jar:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/home/pcl/softPages/zookeeper/zookeeper-3.4.10/bin/../conf:
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=5.4.0-150-generic
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=pcl
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/pcl
2024-03-10 17:39:05,837 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/pcl
2024-03-10 17:39:05,838 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@255316f2
Welcome to ZooKeeper!
2024-03-10 17:39:05,854 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2024-03-10 17:39:05,989 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session
[zk: localhost:2181(CONNECTING) 0] 2024-03-10 17:39:06,030 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x18e27b576e70001, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: localhost:2181(CONNECTED) 0]

zk客户端常用命令

  • ls:查看节点目录
  • set:设置节点数据
  • get:查看节点数据
  • create:创建节点
  • delete:删除节点
相关推荐
vvw&1 小时前
如何在 Ubuntu 22.04 上安装 Ansible 教程
linux·运维·服务器·ubuntu·开源·ansible·devops
gs801402 小时前
ubuntu下 如何将 NVIDIA 内核驱动 升级到特定版本 如550.127
ubuntu·gpu·nvidia
1LOVESJohnny2 小时前
Linux | scp指令基于WSL在Windows/Ubuntu系统间传输文件
linux·ubuntu·wsl·文件传输
vvw&2 小时前
如何在 Ubuntu 22.04 上安装 Graylog 开源日志管理平台
linux·运维·服务器·ubuntu·开源·github·graylog
o(╥﹏╥)3 小时前
在 Ubuntu 上安装 VS Code
linux·运维·vscode·ubuntu·vs
Joyner20184 小时前
【Linux】ubuntu通过远程命令行启动桌面应用
linux·服务器·ubuntu
Eric.Lee20214 小时前
ubuntu paddle ocr 部署bug问题解决
ubuntu·ocr·paddle
御风_216 小时前
Linux——字符设备驱动控制LED
linux·ubuntu·linux驱动
明 庭14 小时前
Ubuntu下通过Docker部署NGINX服务器
服务器·ubuntu·docker
猿小蔡-Cool14 小时前
ubuntu20.04安装imwheel实现鼠标滚轮调速
ubuntu