zookeeper的部署

1. 下载安装包

打开官网地址:https://zookeeper.apache.org/

下载安装包 apache-zookeeper-3.5.9-bin.tar.gz

 

 

 

点击Download 进入下载页面,选择版本,进行下载。如选择3.5.9 版本进行下载。

 

 

 2. 解压文件

## 先将安装包拷贝到hadoop101 机器上到 /opt/softwares 路径下
justin@MacBook-Pro ~ % scp ~/Downloads/apache-zookeeper-3.5.9-bin.tar.gz bigdata@hadoop101:/opt/softwares The authenticity of host 'hadoop101 (172.16.9.101)' can't be established. RSA key fingerprint is SHA256:uTpmsNMG6e+MhrRoIybWf1UUimPCg0m7mSmmsS/bX8M. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'hadoop101' (RSA) to the list of known hosts. bigdata@hadoop101's password: apache-zookeeper-3.5.9-bin.tar.gz 100% 9397KB 76.5MB/s 00:00 justin@MacBook-Pro ~ % ## 登录到hadoop101 上 justin@MacBook-Pro ~ % ssh bigdata@hadoop101 bigdata@hadoop101's password: Last login: Sun Mar 7 10:12:46 2021 from hadoop103 [bigdata@hadoop101 ~]$ cd /opt/softwares/ [bigdata@hadoop101 softwares]$ ll 总用量 199924 -rw-r--r-- 1 bigdata bigdata 9623007 3月 8 22:37 apache-zookeeper-3.5.9-bin.tar.gz -rw-r--r--. 1 bigdata bigdata 195094741 3月 7 07:16 jdk-8u221-linux-x64.tar.gz
## 解压 [bigdata@hadoop101 softwares]$
tar -zxvf apache-zookeeper-3.5.9-bin.tar.gz -C /opt/modules/

[bigdata@hadoop101 modules]$ cd /opt/modules/
[bigdata@hadoop101 modules]$ ll
总用量 8
drwxrwxr-x 6 bigdata bigdata 4096 3月 8 22:45 apache-zookeeper-3.5.9-bin
drwxr-xr-x. 7 bigdata bigdata 4096 7月 4 2019 jdk1.8.0_221

 

## 为了方便和统一,将文件夹改名:apache-zookeeper-3.5.9-bin --> zookeeper-3.5.9
[bigdata@hadoop101 modules]$ mv apache-zookeeper-3.5.9-bin zookeeper-3.5.9
[bigdata@hadoop101 modules]$ ll
总用量 8
drwxr-xr-x. 7 bigdata bigdata 4096 7月 4 2019 jdk1.8.0_221
drwxrwxr-x 6 bigdata bigdata 4096 3月 8 22:45 zookeeper-3.5.9
[bigdata@hadoop101 modules]$

 

3. 配置文件

[bigdata@hadoop101 modules]$ cd zookeeper-3.5.9/
[bigdata@hadoop101 zookeeper-3.5.9]$ ll
总用量 40
drwxr-xr-x 2 bigdata bigdata  4096 1月   7 02:56 bin
drwxr-xr-x 2 bigdata bigdata  4096 1月   7 02:56 conf
drwxr-xr-x 5 bigdata bigdata  4096 1月   7 03:48 docs
drwxrwxr-x 2 bigdata bigdata  4096 3月   8 22:45 lib
-rw-r--r-- 1 bigdata bigdata 11358 10月  5 23:01 LICENSE.txt
-rw-r--r-- 1 bigdata bigdata   432 1月   7 00:12 NOTICE.txt
-rw-r--r-- 1 bigdata bigdata  1560 1月   7 02:56 README.md
-rw-r--r-- 1 bigdata bigdata  1347 1月   7 02:56 README_packaging.txt
[bigdata@hadoop101 zookeeper-3.5.9]$
[bigdata@hadoop101 zookeeper-3.5.9]$ ll bin/
总用量 56
-rwxr-xr-x 1 bigdata bigdata   232 10月  5 23:01 README.txt
-rwxr-xr-x 1 bigdata bigdata  2067 1月   7 02:56 zkCleanup.sh
-rwxr-xr-x 1 bigdata bigdata  1158 10月  5 23:01 zkCli.cmd
-rwxr-xr-x 1 bigdata bigdata  1621 1月   7 02:56 zkCli.sh
-rwxr-xr-x 1 bigdata bigdata  1766 1月   7 02:56 zkEnv.cmd
-rwxr-xr-x 1 bigdata bigdata  3690 10月  5 23:01 zkEnv.sh
-rwxr-xr-x 1 bigdata bigdata  1286 10月  5 23:01 zkServer.cmd
-rwxr-xr-x 1 bigdata bigdata  4573 1月   7 02:56 zkServer-initialize.sh
-rwxr-xr-x 1 bigdata bigdata 10682 1月   7 02:56 zkServer.sh
-rwxr-xr-x 1 bigdata bigdata   996 10月  5 23:01 zkTxnLogToolkit.cmd
-rwxr-xr-x 1 bigdata bigdata  1385 10月  5 23:01 zkTxnLogToolkit.sh
[bigdata@hadoop101 zookeeper-3.5.9]$ ll conf/
总用量 12
-rw-r--r-- 1 bigdata bigdata  535 10月  5 23:01 configuration.xsl
-rw-r--r-- 1 bigdata bigdata 2712 1月   7 02:56 log4j.properties
-rw-r--r-- 1 bigdata bigdata  922 1月   7 02:56 zoo_sample.cfg
[bigdata@hadoop101 zookeeper-3.5.9]$
[bigdata@hadoop101 zookeeper-3.5.9]$ cd conf/

## 复制 zoo_sample.cfg --> zoo.cfg

[bigdata@hadoop101 conf]$ cp zoo_sample.cfg zoo.cfg

 

 4. 本地模式安装 

[bigdata@hadoop101 zookeeper-3.5.9]$ mkdir zkData  ## 在zookeeper 文件内新建 zkData文件夹
[bigdata@hadoop101 zookeeper-3.5.9]$ ll
总用量 44
drwxr-xr-x 2 bigdata bigdata  4096 1月   7 02:56 bin
drwxr-xr-x 2 bigdata bigdata  4096 3月   8 23:08 conf
drwxr-xr-x 5 bigdata bigdata  4096 1月   7 03:48 docs
drwxrwxr-x 2 bigdata bigdata  4096 3月   8 22:45 lib
-rw-r--r-- 1 bigdata bigdata 11358 10月  5 23:01 LICENSE.txt
-rw-r--r-- 1 bigdata bigdata   432 1月   7 00:12 NOTICE.txt
-rw-r--r-- 1 bigdata bigdata  1560 1月   7 02:56 README.md
-rw-r--r-- 1 bigdata bigdata  1347 1月   7 02:56 README_packaging.txt
drwxrwxr-x 2 bigdata bigdata  4096 3月   8 23:15 zkData
[bigdata@hadoop101 zookeeper-3.5.9]$ cd zkData/
[bigdata@hadoop101 zkData]$ pwd
/opt/modules/zookeeper-3.5.9/zkData

[bigdata@hadoop101 zookeeper-3.5.9]$ cd conf/
[bigdata@hadoop101 conf]$ ll
总用量 16
-rw-r--r-- 1 bigdata bigdata  535 10月  5 23:01 configuration.xsl
-rw-r--r-- 1 bigdata bizgdata 2712 1月   7 02:56 log4j.properties
-rw-r--r-- 1 bigdata bigdata  922 3月   8 22:57 zoo.cfg
-rw-r--r-- 1 bigdata bigdata  922 1月   7 02:56 zoo_sample.cfg


## 编辑 zoo.cfg (cp zoo_sample.cfg zoo.cfg) [bigdata@hadoop101 conf]$
vi zoo.cfg # 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=/tmp/zookeeper dataDir=/opt/modules/zookeeper-3.5.9/zkData ## 将此处路径修改 # 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

 

启动本地模式  bin/zkServer.sh start 

[bigdata@hadoop101 zookeeper-3.5.9]$ cd bin/
[bigdata@hadoop101 bin]$ ll
总用量 56
-rwxr-xr-x 1 bigdata bigdata   232 10月  5 23:01 README.txt
-rwxr-xr-x 1 bigdata bigdata  2067 1月   7 02:56 zkCleanup.sh
-rwxr-xr-x 1 bigdata bigdata  1158 10月  5 23:01 zkCli.cmd
-rwxr-xr-x 1 bigdata bigdata  1621 1月   7 02:56 zkCli.sh
-rwxr-xr-x 1 bigdata bigdata  1766 1月   7 02:56 zkEnv.cmd
-rwxr-xr-x 1 bigdata bigdata  3690 10月  5 23:01 zkEnv.sh
-rwxr-xr-x 1 bigdata bigdata  1286 10月  5 23:01 zkServer.cmd
-rwxr-xr-x 1 bigdata bigdata  4573 1月   7 02:56 zkServer-initialize.sh
-rwxr-xr-x 1 bigdata bigdata 10682 1月   7 02:56 zkServer.sh
-rwxr-xr-x 1 bigdata bigdata   996 10月  5 23:01 zkTxnLogToolkit.cmd
-rwxr-xr-x 1 bigdata bigdata  1385 10月  5 23:01 zkTxnLogToolkit.sh
[bigdata@hadoop101 bin]$ ./zkServer.sh --help
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Usage: ./zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|restart|status|print-cmd}
[bigdata@hadoop101 bin]$
[bigdata@hadoop101 bin]$ ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[bigdata@hadoop101 bin]$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
[bigdata@hadoop101 bin]$

 

5. 分布式安装

集群规划:在hadoop101,hadoop102,hadoop103 三台机器上部署zookeeper 

 

a. 在zkData文件夹内新建 myid文件

[bigdata@hadoop101 zookeeper-3.5.9]$ cd zkData/
[bigdata@hadoop101 zkData]$ ll
总用量 8
drwxrwxr-x 2 bigdata bigdata 4096 3月   8 23:24 version-2
-rw-rw-r-- 1 bigdata bigdata    4 3月   8 23:24 zookeeper_server.pid
[bigdata@hadoop101 zkData]$ touch myid
[bigdata@hadoop101 zkData]$ vi myid


# 文件中写上0 ,代表第一台机器
0

 

a. 将文件( zookeeper-3.5.9 ) 同步到 其他两台机器上 

[bigdata@hadoop101 modules]$ xsync zookeeper-3.5.9/

 

b. 在其他两台机器上,修改myid 文件,hadoop102机器上到myid内容为 1 ,hadoop103机器上到myid 内容为 2 

[bigdata@hadoop101 modules]$ ssh hadoop102
Last login: Sun Mar  7 10:35:03 2021 from hadoop101
[bigdata@hadoop102 ~]$ vi /opt/modules/zookeeper-3.5.9/zkData/myid
[bigdata@hadoop102 ~]$ ssh hadoop103
Last login: Sun Mar  7 10:10:35 2021 from hadoop102
[bigdata@hadoop103 ~]$ vi /opt/modules/zookeeper-3.5.9/zkData/myid

 

c. 编辑 zoo.cfg 文件

## 在 zoo.cfg 文件末尾添加如下内容 
####### cluster ######## server.
0=hadoop101:2888:3888 server.1=hadoop102:2888:3888 server.2=hadoop103:2888:3888

 

d. 将修改后到文件 zoo.cfg 同步到其他机器

[bigdata@hadoop101 conf]$ xsync zoo.cfg
fname=zoo.cfg
pdir=/opt/modules/zookeeper-3.5.9/conf
------------------- hadoop101 --------------
sending incremental file list

sent 30 bytes  received 12 bytes  84.00 bytes/sec
total size is 1080  speedup is 25.71
------------------- hadoop102 --------------
sending incremental file list
zoo.cfg

sent 457 bytes  received 43 bytes  1000.00 bytes/sec
total size is 1080  speedup is 2.16
------------------- hadoop103 --------------
sending incremental file list
zoo.cfg

sent 457 bytes  received 43 bytes  1000.00 bytes/sec
total size is 1080  speedup is 2.16

 

e. 分布在每个机器上启动 zkServer.sh start  

[bigdata@hadoop101 conf]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Starting zookeeper ... already running as process 1999.
[bigdata@hadoop101 conf]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone  ## 刚刚到本地模式在运行
[bigdata@hadoop101 conf]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh stop  ## 停止本地模式
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[bigdata@hadoop101 conf]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[bigdata@hadoop101 conf]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.
[bigdata@hadoop101 conf]$ ssh hadoop102
Last login: Mon Mar  8 23:45:03 2021 from hadoop101
[bigdata@hadoop102 ~]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[bigdata@hadoop102 ~]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
[bigdata@hadoop102 ~]$ ssh hadoop103
Last login: Mon Mar  8 23:45:33 2021 from hadoop102
[bigdata@hadoop103 ~]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[bigdata@hadoop103 ~]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[bigdata@hadoop103 ~]$ exit
logout
Connection to hadoop103 closed.
[bigdata@hadoop102 ~]$ exit
logout
Connection to hadoop102 closed.
[bigdata@hadoop101 conf]$ /opt/modules/zookeeper-3.5.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.9/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[bigdata@hadoop101 conf]$

 

6. 客户端常用命令,启动客户端: bin/zkCli.sh 

[zk: localhost:2181(CONNECTED) 0] 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) 1]

 

posted @ 2021-03-09 00:32  Justins999  阅读(65)  评论(0)    收藏  举报