在CentOS7上安装和使用ZooKeeper最新版本(V3.4.11)

0.ZooKeeper文档

http://zookeeper.apache.org/doc/r3.4.11/zookeeperOver.html

1.准备

在CentOS7上安装zookeeper时,如下工具必须要有:wget

如果没有,则进行安装:

yum -y install wget

2.下载安装

下载到本地

  1. cd /usr/local/src

  2.  

    wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz

解压

tar -xzvf zookeeper-3.4.11.tar.gz

创建的安装目录,并移动解压后的目录到其下

  1. mkdir -p ../zookeeper

  2.  

    mv zookeeper-3.4.11/ ../zookeeper

创建数据目录,用于存放数据

mkdir -p /var/lib/zookeeper

创建配置

  1. cd ../zookeeper/zookeeper-3.4.11/conf

  2.  

    cp zoo_sample.cfg zoo.cfg

修改其中配置dataDir:

vi zoo.cfg
dataDir=/var/lib/zookeeper

3.启动服务

  1. cd ..

  2.  

    ./bin/zkServer.sh start

输出如下信息,表示启动成功

  1. Connecting to 127.0.0.1:2181

  2.  

    2018-02-09 14:56:10,914 [myid:] - INFO [main:[email protected]100] - Client environment:zookeeper.version=3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT

  3.  

    2018-02-09 14:56:10,922 [myid:] - INFO [main:[email protected]100] - Client environment:host.name=jiaodacailei-thinkpad-centos7

  4.  

    2018-02-09 14:56:10,922 [myid:] - INFO [main:[email protected]100] - Client environment:java.version=1.8.0_161

  5.  

    2018-02-09 14:56:10,927 [myid:] - INFO [main:[email protected]100] - Client environment:java.vendor=Oracle Corporation

  6.  

    2018-02-09 14:56:10,927 [myid:] - INFO [main:[email protected]100] - Client environment:java.home=/usr/local/jdk/jdk1.8.0_161/jre

  7.  

    2018-02-09 14:56:10,927 [myid:] - INFO [main:[email protected]100] - Client environment:java.class.path=/usr/local/zookeeper/zookeeper-3.4.11/bin/../build/classes:/usr/local/zookeeper/zookeeper-3.4.11/bin/../build/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/netty-3.10.5.Final.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/audience-annotations-0.5.0.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../zookeeper-3.4.11.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../src/java/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../conf::/usr/local/jdk/jdk1.8.0_161/lib/dt.jar:/usr/local/jdk/jdk1.8.0_161/lib/tools.jar:/usr/local/jdk/jdk1.8.0_161/jre/lib/dt.jar

  8.  

    2018-02-09 14:56:10,927 [myid:] - INFO [main:[email protected]100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

  9.  

    2018-02-09 14:56:10,928 [myid:] - INFO [main:[email protected]100] - Client environment:java.io.tmpdir=/tmp

  10.  

    2018-02-09 14:56:10,928 [myid:] - INFO [main:[email protected]100] - Client environment:java.compiler=<NA>

  11.  

    2018-02-09 14:56:10,928 [myid:] - INFO [main:[email protected]100] - Client environment:os.name=Linux

  12.  

    2018-02-09 14:56:10,928 [myid:] - INFO [main:[email protected]100] - Client environment:os.arch=amd64

  13.  

    2018-02-09 14:56:10,928 [myid:] - INFO [main:[email protected]100] - Client environment:os.version=3.10.0-693.el7.x86_64

  14.  

    2018-02-09 14:56:10,929 [myid:] - INFO [main:[email protected]100] - Client environment:user.name=root

  15.  

    2018-02-09 14:56:10,929 [myid:] - INFO [main:[email protected]100] - Client environment:user.home=/root

  16.  

    2018-02-09 14:56:10,929 [myid:] - INFO [main:[email protected]100] - Client environment:user.dir=/usr/local/zookeeper/zookeeper-3.4.11

  17.  

    2018-02-09 14:56:10,932 [myid:] - INFO [main:[email protected]441] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 [email protected]579bb367

  18.  

    Welcome to ZooKeeper!

  19.  

    2018-02-09 14:56:10,983 [myid:] - INFO [main-SendThread(127.0.0.1:2181):[email protected]1035] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)

  20.  

    JLine support is enabled

  21.  

    2018-02-09 14:56:11,141 [myid:] - INFO [main-SendThread(127.0.0.1:2181):[email protected]877] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session

  22.  

    [zk: 127.0.0.1:2181(CONNECTING) 0] 2018-02-09 14:56:11,242 [myid:] - INFO [main-SendThread(127.0.0.1:2181):[email protected]1302] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x1000150f9ff0000, negotiated timeout = 30000

  23.  

  24.  

    WATCHER::

  25.  

  26.  

    WatchedEvent state:SyncConnected type:None path:null

4.启动客户端

./bin/zkCli.sh -server 127.0.0.1:2181

输入如下,等待用户输入命令:

[zk: 127.0.0.1:2181(CONNECTED) 0]

5.获取帮助

输入如下命令,可以获取帮助信息:

help

输出信息如下:

  1. ZooKeeper -server host:port cmd args

  2.  

    stat path [watch]

  3.  

    set path data [version]

  4.  

    ls path [watch]

  5.  

    delquota [-n|-b] path

  6.  

    ls2 path [watch]

  7.  

    setAcl path acl

  8.  

    setquota -n|-b val path

  9.  

    history

  10.  

    redo cmdno

  11.  

    printwatches on|off

  12.  

    delete path [version]

  13.  

    sync path

  14.  

    listquota path

  15.  

    rmr path

  16.  

    get path [watch]

  17.  

    create [-s] [-e] path data acl

  18.  

    addauth scheme auth

  19.  

    quit

  20.  

    getAcl path

  21.  

    close

  22.  

    connect host:port

上面是所有可以使用的命令

6.ls命令

ls /

默认根节点下有一个zookeeper节点

[zookeeper]

7.创建节点

创建节点采用create命令,创建之后查看根路径,发现多了一个节点;

通过get命令,可以查询节点路径对应的数据

  1. [zk: 127.0.0.1:2181(CONNECTED) 4] create /zk_test test_data

  2.  

    Created /zk_test

  1. [zk: 127.0.0.1:2181(CONNECTED) 6] ls /

  2.  

    [zookeeper, zk_test]

  1. [zk: 127.0.0.1:2181(CONNECTED) 7] get /zk_test

  2.  

    test_data

  3.  

    cZxid = 0x2

  4.  

    ctime = Fri Feb 09 15:19:11 CST 2018

  5.  

    mZxid = 0x2

  6.  

    mtime = Fri Feb 09 15:19:11 CST 2018

  7.  

    pZxid = 0x2

  8.  

    cversion = 0

  9.  

    dataVersion = 0

  10.  

    aclVersion = 0

  11.  

    ephemeralOwner = 0x0

  12.  

    dataLength = 9

  13.  

    numChildren = 0

8.修改节点数据

set命令可以修改路径对应的节点数据,修改后再通过get命令查看结果

[zk: 127.0.0.1:2181(CONNECTED) 8] set /zk_test test_data_change
cZxid = 0x2
ctime = Fri Feb 09 15:19:11 CST 2018
mZxid = 0x3
mtime = Fri Feb 09 15:21:31 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 16
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 10] get /zk_test
test_data_change
cZxid = 0x2
ctime = Fri Feb 09 15:19:11 CST 2018
mZxid = 0x3
mtime = Fri Feb 09 15:21:31 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 16
numChildren = 0

9.删除节点

delete命令可以删除路径对应的节点,删除之后,通过ls命令查看其父路径,可以看到节点已经减少一个

  1. [zk: 127.0.0.1:2181(CONNECTED) 11] delete /zk_test

  2.  

    [zk: 127.0.0.1:2181(CONNECTED) 12] ls /

  3.  

    [zookeeper]

10.退出客户端

quit

11.停止服务

./bin/zkServer.sh stop

原文地址:https://www.cnblogs.com/telwanggs/p/9513582.html

时间: 2024-10-01 06:20:57

在CentOS7上安装和使用ZooKeeper最新版本(V3.4.11)的相关文章

在VMware上安装MAC OS10.15最新版本并安装Xcode11.4教程(所有坑已经走过)

最新我们新开了iOS开发这门课程但是电脑是Windows系统,所以只能在虚拟机上安装一个苹果系统的电脑来支持xcode11编写代码程序. 下面就是具体安装步骤和一些下载资源. 首先我们要知道最新版本的Xcode 11支持的是15.5以上的虚拟机以及10.15以上的苹果系统,如果这两样你没有拥有那就无法拥Xcode11. 虚拟机15.5以上的版本可以自行在官网安装这里就不多做解释了. 安装虚拟机以后如果想拥有一个苹果系统的电脑,我们需要用unlocker黑苹果工具,才能让虚拟机在新建虚拟机的时候有

在 CentOS7 上安装 zookeeper-3.4.9 服务

在 CentOS7 上安装 zookeeper-3.4.9 服务 1.创建 /usr/local/services/zookeeper 文件夹: mkdir -p /usr/local/services/zookeeper 2.进入到 /usr/local/services/zookeeper 目录中: cd /usr/local/services/zookeeper 3.下载 zookeeper-3.4.9.tar.gz: wget https://mirrors.tuna.tsinghua.

CentOS7 上安装 Zookeeper-3.4.9 服务

在 CentOS7 上安装 zookeeper-3.4.9 服务 1.创建 /usr/local/services/zookeeper 文件夹:    mkdir -p /usr/local/services/zookeeper 2.进入到 /usr/local/services/zookeeper 目录中:    cd /usr/local/services/zookeeper 3.下载 zookeeper-3.4.9.tar.gz:    wget https://mirrors.tuna.

一次在CentOS7上安装部署Zabbix3.0版本及快速进行基本配置的实例

Zabbix3.0的安装.部署.配置,必须基于LAMP环境或是是LNMP环境. 关于LAMP环境的简单快速搭建,见博客:http://afterdawn.blog.51cto.com/7503144/1923139 注意:以下步骤都是在LAMP配置之后进行的. 本文不会再对zabbix-server和zabbix-agent理论知识再进行介绍,建议看完http://afterdawn.blog.51cto.com/7503144/1922502再进行zabbix实战. Zabbix3.0对软硬件

在 CentOS7 上安装 MySQL5.7

在 CentOS7 上安装 MySQL5.7 1 通过 SecureCRT 连接到阿里云 CentOS7 服务器: 2 进入到目录 /usr/local/ 中:cd /usr/local/ 3 创建目录 /usr/local/tools,如果有则忽略: mkdir -p tools 4 创建 /usr/local/mysql 目录,如果已存在则忽略:mkdir -p mysql 5 进入到目录 /usr/local/tools 中:cd tools/ 6 查看系统中是否已安装 MySQL 服务:

CentOS7上安装稻壳CMS

CentOS7上安装稻壳CMS 1, 安装用途 为了给某公司建设一个小型网站,租用了一个阿里云ECS服务器,最基础的硬件配置,因此选择了CentOS7操作系统. 稻壳CMS(docCMS)源于深喉咙CMS,使用广泛,配置简单,因此采用其作为建站模板. 2,CentOS7环境安装 阿里云ECS中的CentOS7操作系统属于“裸”操作系统,没有配置基础的Web应用环境.为和稻壳CMS匹配,需安装配置的软件有: ²        Apache服务器Httpd ²        防火墙IPTables

CentOS7上安装、配置、监控RabbitMQ

CentOS7上安装.配置.监控RabbitMQ RabbitMQ是流行的开源消息队列系统,是AMQP(Advanced Message Queuing Protocol高级消息队列协议)的标准实现,用erlang语言开发.RabbitMQ据说具有良好的性能和时效性,同时还能够非常好的支持集群和负 载部署,非常适合在较大规模的分布式系统中使用,具体特性还在验证中,待检验.由于项目需要,安装并配置了RabbitMQ,服务器操作系统是CentOS7. 环境:CentOS7.2 步骤 一.安装Erla

(转)在 CentOS7 上安装 MongoDB

在 CentOS7 上安装 MongoDB 1 通过 SecureCRT 连接至 CentOS7 服务器: 2 进入到 /usr/local/ 目录: cd /usr/local 3 在当前目录下创建 tools 目录: mkdir -p tools 4 进入到 tools 目录中: cd tools 5 下载与 CentOS 系统匹配的 mongodb-linux-x86_64-rhel70-3.2.4.tgz 文件: wget https://fastdl.mongodb.org/linux

CentOS7上安装POCO

POCO是什么? 看官网说明: Modern, powerful open source C++ class libraries and frameworks for building network- and internet-based applications that run on desktop, server, mobile and embedded systems. 下载地址 强烈建议,唯一下载地址就是官方网站,不要图省事在某些国内站点下载.地址是:(很可惜,这个残疾的网站上发博客