直接在机器上部署

下载

下载页面:https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz
下载链接:https://dlcdn.apache.org/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz

解压

tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz -C /usr/local/

配置zoo.cfg

cd /usr/local/apache-zookeeper-3.6.3-bin/conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg

  1. # The number of milliseconds of each tick
  2. tickTime=2000
  3. # The number of ticks that the initial
  4. # synchronization phase can take
  5. initLimit=10
  6. # The number of ticks that can pass between
  7. # sending a request and getting an acknowledgement
  8. syncLimit=5
  9. # the directory where the snapshot is stored.
  10. # do not use /tmp for storage, /tmp here is just
  11. # example sakes.
  12. #dataDir=/tmp/zookeeper
  13. dataDir=/data/zookeeper
  14. # the port at which the clients will connect
  15. clientPort=2181
  16. # the maximum number of client connections.
  17. # increase this if you need to handle more clients
  18. #maxClientCnxns=60
  19. #
  20. # Be sure to read the maintenance section of the
  21. # administrator guide before turning on autopurge.
  22. #
  23. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  24. #
  25. # The number of snapshots to retain in dataDir
  26. #autopurge.snapRetainCount=3
  27. # Purge task interval in hours
  28. # Set to "0" to disable auto purge feature
  29. #autopurge.purgeInterval=1
  30. ## Metrics Providers
  31. #
  32. # https://prometheus.io Metrics Exporter
  33. #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
  34. #metricsProvider.httpPort=7000
  35. #metricsProvider.exportJvmInfo=true
  36. server.1=192.168.2.20:2888:3888
  37. server.2=192.168.2.21:2888:3888
  38. server.3=192.168.2.22:2888:3888

13行:配置数据目录
37-39行:配置集群信息

配置myid文件

mkdir -p /data/zookeeper && cd /data/zookeeper
在数据存储目录下新建一个文件myid,文件内容为当前server的编号,三台主机master,node1,node2分别对应1、2、3

  1. [root@hadoop101 conf]# cat /data/zookeeper/myid
  2. 1

以上为主机1的id为1

分发安装包

  1. 拷贝整个目录到机器2(node1)、和机器3(node2)中
  2. scp -r /usr/local/apache-zookeeper-3.6.3-bin root@192.168.2.21:/usr/local/apache-zookeeper-3.6.3-bin
  3. 修改对应的数据存储目录下的myid文件内容

    启动集群

  4. 在master上建立群起脚本:startZkAll.sh

  5. /usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start
  6. 脚本内容如下 ```shell

    !/bin/bash

for host in “master” “node1” “node2” do echo “** Start server $host **“ ssh $host “source /etc/profile;/usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start” echo “** /finish $host **“ done

  1. 3. 启动集群
  2. ```shell
  3. [root@hadoop101 ~]# ./startZkAll.sh
  4. ********** Start server master **********
  5. ZooKeeper JMX enabled by default
  6. Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
  7. Starting zookeeper ... STARTED
  8. ********** /finish master **********
  9. ********** Start server node1 **********
  10. ZooKeeper JMX enabled by default
  11. Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
  12. Starting zookeeper ... STARTED
  13. ********** /finish node1 **********
  14. ********** Start server node2 **********
  15. ZooKeeper JMX enabled by default
  16. Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
  17. Starting zookeeper ... STARTED
  18. ********** /finish node2 **********

查看状态

  1. 在master机器上查看: ```shell [root@hadoop101 ~]# /usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower
  1. 2. node1机器上查看:
  2. ```shell
  3. [root@hadoop102 ~]# /usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh status
  4. ZooKeeper JMX enabled by default
  5. Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
  6. Client port found: 2181. Client address: localhost.
  7. Mode: leader
  1. 在node2机器上查看: ```shell [root@hadoop103 apache-zookeeper-3.6.3-bin]# /usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower
  1. <a name="UQLoE"></a>
  2. ## 停止集群
  3. 1. 在master机器上建立群停脚本:stopZkAll.sh
  4. 1. /usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh stop
  5. 1. 脚本内容如下
  6. ```shell
  7. [root@hadoop101 ~]# cat stopZkAll.sh
  8. #! /bin/bash
  9. for host in "master" "node1" "node2"
  10. do
  11. echo "********** Start server $host **********"
  12. ssh $host "source /etc/profile;/usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh stop"
  13. echo "********** /finish $host **********"
  14. done
  1. 停止集群 ```shell [root@hadoop101 ~]# ./stopZkAll.sh ** Start server master ** ZooKeeper JMX enabled by default Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg Stopping zookeeper … STOPPED ** /finish master ** ** Start server node1 ** ZooKeeper JMX enabled by default Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg Stopping zookeeper … STOPPED ** /finish node1 ** ** Start server node2 ** ZooKeeper JMX enabled by default Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg Stopping zookeeper … STOPPED ** /finish node2 **

```


至此,完成了Zookeeper集群的安装和启停。