Zookeeper 可以实现同步服务,配置维护和名命服务
可以保证集群之间的数据的事务的一致性
Zk的安装与配置
下载安装包,解压到指定目录
修改环境变量
Gedit /etc/profile 添加如下内容:(未作修改)
Export ZK_HOME=/software/zookeeper/zookeeper-3.3.2/data
Export PATH=.:$HADOOP_HOME/bin:$JAVA_HOME/bin:ZK_HOME/bin:$PATH
//使配置生效
Source /ect/profile
修改配置文件:
Mv zookeeper_simple.cfg zoo.cfg
Gedit xoo.cfg添加如下内容:
dataDir=/software/zookeeper/zookeeper-3.3.2/data
Server.0=hadoop0:2888:3888
//如果多个节点,则继续添加
Server.1=hadoop1:2888:3888
Server.2=hadoop2:2888:3888
创建标识符号
Cd /software/zookeeper/zookeeper-3.3.2/data
Gedit myid添加内容:0
//查看文件内容:
root@vm:/software/zookeeper/zookeeper-3.3.2/data# cat myid
0
如果是集群环,需要将当前配置复制到其他节点:
//复制源文件
Cd /software/zookeeper/
Scp -r zookeeper-3.3.2/ 节点名:/同目录下
//复制环境变量
Scp /etc/profile 节点名:/etc/
//使其生效
Ssh 节点名
Source /etc/profile
//修改节点中/data/myid 修改为1或2
启动zookeeper,(如果是集群环境,需要在各个节点上执行相同命令)
//首先启动hadoop
//再启动zookeeper
root@vm:/software/zookeeper/zookeeper-3.3.2/bin# zkServer.sh start
JMX enabled by default
Using config: /software/zookeeper/zookeeper-3.3.2/bin/../conf/zoo.cfg
Starting zookeeper ...
STARTED
//查看启动情况,在各个节点执行
zkServer.sh status
//命令操作
zkCli.sh
[zk: localhost:2181(CONNECTED) 1] ls
ZooKeeper -server host:port cmd args
connect host:port
get path [watch]
ls path [watch]
set path data [version]
delquota [-n|-b] path
quit
printwatches on|off
create [-s] [-e] path data acl
stat path [watch]
close
ls2 path [watch]
history
listquota path
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
setquota -n|-b val path
//查看根目录
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
//创健
[zk: localhost:2181(CONNECTED) 2] create /retacn hadoop
Created /retacn
//查看
[zk: localhost:2181(CONNECTED) 3] get /retacn
hadoop
cZxid = 0x4
ctime = Sun Nov 15 10:57:31 CST 2015
mZxid = 0x4
mtime = Sun Nov 15 10:57:31 CST 2015
pZxid = 0x4
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0
//也可以在不同节点上查看
Get /retacn
在hbase应用中会用得到