直接在机器上部署
下载
下载页面: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
# 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=/data/zookeeper
# 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
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=192.168.2.20:2888:3888
server.2=192.168.2.21:2888:3888
server.3=192.168.2.22:2888:3888
配置myid文件
mkdir -p /data/zookeeper && cd /data/zookeeper
在数据存储目录下新建一个文件myid,文件内容为当前server的编号,三台主机master,node1,node2分别对应1、2、3
[root@hadoop101 conf]# cat /data/zookeeper/myid
1
以上为主机1的id为1
分发安装包
- 拷贝整个目录到机器2(node1)、和机器3(node2)中
- scp -r /usr/local/apache-zookeeper-3.6.3-bin root@192.168.2.21:/usr/local/apache-zookeeper-3.6.3-bin
-
启动集群
在master上建立群起脚本:startZkAll.sh
- /usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start
- 脚本内容如下
```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
3. 启动集群
```shell
[root@hadoop101 ~]# ./startZkAll.sh
********** Start server master **********
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
********** /finish master **********
********** Start server node1 **********
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
********** /finish node1 **********
********** Start server node2 **********
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
********** /finish node2 **********
查看状态
- 在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
2. 在node1机器上查看:
```shell
[root@hadoop102 ~]# /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: leader
- 在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
<a name="UQLoE"></a>
## 停止集群
1. 在master机器上建立群停脚本:stopZkAll.sh
1. /usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh stop
1. 脚本内容如下
```shell
[root@hadoop101 ~]# cat stopZkAll.sh
#! /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 stop"
echo "********** /finish $host **********"
done
- 停止集群 ```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集群的安装和启停。