注意:我們將大數(shù)據(jù)相關(guān)組件全部安裝在/opt/bigdata目錄
1.下載zookeeper安裝包
[root@cluster201 bigdata]# pwd
/opt/bigdata
[hadoop@cluster201 bigdata]$ wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.10.tar.gz
2.解壓
[root@cluster201 bigdata]# pwd
/opt/bigdata
[hadoop@cluster201 bigdata]$ tar -zvxf zookeeper-3.4.10.tar.gz
3. 修改環(huán)境變量,在/etc/profile文件中增加如下內(nèi)容
#zookeeper
export ZOOKEEPER_HOME=/opt/bigdata/zookeeper-3.4.10
export PATH=$PATH:$ZOOKEEPER_HOME/bin
用source命令讓配置文件生效
[root@cluster201 bigdata]# source /etc/profile
4.在/opt/bigdata/zookeeper-3.4.10下創(chuàng)建存放數(shù)據(jù)與日志的目錄
[root@cluster201 bigdata]# pwd
/opt/bigdata/zookeeper-3.4.10
[root@cluster201 zookeeper-3.4.10]# mkdir data
[root@cluster201 zookeeper-3.4.10]# mkdir log
5.修改配置文件(cluster201/cluster202/cluster203執(zhí)行同樣的操作)
先拷貝樣本配置文件
[root@cluster201 conf]# pwd
/opt/bigdata/zookeeper-3.4.10/conf
[root@cluster201 conf]# cp zoo_sample.cfg zoo.cfg
將zoo.cfg的內(nèi)容修改如下
# 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.
#配置數(shù)據(jù)存放目錄
dataDir=/opt/bigdata/zookeeper-3.4.10/data
#配置日志存放目錄
dataLogDir=/opt/bigdata/zookeeper-3.4.10/log
# 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
#配置集群地址
server.1=cluster201:2888:3888
server.2=cluster202:2888:3888
server.3=cluster203:2888:3888
6.在data目錄中創(chuàng)建myid文件
cluster201(192.168.88.201)
[root@cluster201 zookeeper-3.4.10]# pwd
/opt/bigdata/zookeeper-3.4.10
[root@cluster201 zookeeper-3.4.10]# echo 1 > data/myid
cluster202(192.168.88.202)
[root@cluster202 zookeeper-3.4.10]# pwd
/opt/bigdata/zookeeper-3.4.10
[root@cluster202 zookeeper-3.4.10]# echo 2 > data/myid
cluster203(192.168.88.203)
[root@cluster203 zookeeper-3.4.10]# pwd
/opt/bigdata/zookeeper-3.4.10
[root@cluster203 zookeeper-3.4.10]# echo 3 > data/myid
7.zookeeper的啟動(dòng)还惠、停止滔以、狀態(tài)查看,三臺(tái)執(zhí)行相同操作
#啟動(dòng)zookeeper
[hadoop@cluster201 zookeeper-3.4.10]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
#查看Java進(jìn)程
[hadoop@cluster201 zookeeper-3.4.10]$ jps
2814 QuorumPeerMain
2846 Jps
#查看zookeeper狀態(tài)
[hadoop@cluster201 zookeeper-3.4.10]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
#停止zookeeper
[hadoop@cluster201 zookeeper-3.4.10]$ zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/zookeeper-3.4.10/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
#重啟zookeeper
[hadoop@cluster201 zookeeper-3.4.10]$ zkServer.sh restart
8.zookeeper基本命令
#鏈接到集群
[hadoop@cluster201 zookeeper-3.4.10]$ zkCli.sh -server cluster201:2181
#查看幫助
[zk: cluster201:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port