← 返回首页
HBase基础教程(三)
发表时间:2023-04-20 01:52:57
CentOS7安装zookeeper-3.4.9

CentOS7安装zookeeper-3.4.9

1.解压缩安装

tar -zxvf zookeeper-3.4.9.tar.gz -C /usr/local
cd /usr/local
mv zookeeper-3.4.9 zookeeper

2.修改配置文档

#进入到 /usr/local/zookeeper/conf目录中:
#复制 zoo_sample.cfg 文件的并命名为为 zoo.cfg:
cp zoo_sample.cfg zoo.cfg

#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=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs

# the port at which the clients will connect
clientPort=2181
server.1=hadoop-master:2888:3888
# 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

3.添加zookeeper环境变量

vim /etc/profile

export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH


source /etc/profile

4.启动zookeeper

cd /usr/local/zookeeper/bin
zkServer.sh start

#如果出现以下提示说明zookeeper启动成功。
[root@hadoop-master bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

# jps观察进程
[root@hadoop-master bin]# jps
19872 SecondaryNameNode
14484 QuorumPeerMain
19638 DataNode
19438 NameNode
14607 Jps

#如何出现QuorumPeerMain进程,也说明zookeeper启动成功!

注意:使用zkServer.sh默认会连接本机2181端口的zookeeper服务,默认情况下zookeeper会监听2181端口。

5.zookeeper常用命令


#查看zookeeper状态
[root@hadoop-master bin]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: standalone

#关闭zookeeper
[root@hadoop-master bin]# ./zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED


#启动zookeeper客户端

[root@hadoop-master bin]# cd $ZOOKEEPER_HOME
[root@hadoop-master bin]# cd bin
[root@hadoop-master bin]# zkCli.sh

#查看根节点下面有什么内容
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper, hbase]

#创建节点
[zk: localhost:2181(CONNECTED) 3] create /test helloworld
Created /test
[zk: localhost:2181(CONNECTED) 4] ls /
[zookeeper, test, hbase]

#查看节点中的信息
[zk: localhost:2181(CONNECTED) 5] get /test
helloworld
cZxid = 0x98
ctime = Fri Oct 27 10:31:38 CST 2023
mZxid = 0x98
mtime = Fri Oct 27 10:31:38 CST 2023
pZxid = 0x98
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 10
numChildren = 0

#删除节点
[zk: localhost:2181(CONNECTED) 6] delete /test
[zk: localhost:2181(CONNECTED) 7] ls /
[zookeeper, hbase]