linux安装配置zookeeper-3.4.10
此文是基于上一篇文章:hadoop集群搭建
安装zookeeper:
【在各个slave节点安装zookeeper】
下载地址:http://mirror.bit.edu.cn/apache/zookeeper/
zk节点最好是奇数个,这样子方便在节点中选取leader节点;
上传zookeeper-3.4.10的安装包到/software目录下:
tar -zxvf zookeeper-3.4.10.tar.gz
解压到/software下;
进入zookeeper-3.4.10创建文件夹data;
mkdir -p /software/zookeeper-3.4.10/data
在data下创建文件myid,内容是1;
echo "1">>/software/zookeeper-3.4.10/data/myid
进入conf,复制一份zoo_sample.cfg命名为zoo.cfg;
cp zoo_sample.cfg zoo.cfg
修改zoo.cfg内容:
dataDir=/software/zookeeper-3.4.10/data
#这里是zookeeper快照目录,建议根据实际修改
最后一行添加:
格式:server.serverId=hostname:lfPort:txPort
# serverId是zk节点的ID编号
# hostname是主机名
# lfPort是leader与follower之间的通信端口(默认2888)
# txPort是follower之间选举leader的通信端口(默认3888)
server.1=slave01:2888:3888 #server.1中的1是id,后面是主机名和端口号 server.2=salve02:2888:3888 server.3=slave03:2888:3888
然后将zookeeper-3.4.10文件夹的权限改成hadoop;
chown -R hadoop:hadoop /software/zookeeper-3.4.10
其它节点安装只需要将整个zookeeper-3.4.10目录拷贝到其它节点相同的文件夹/software下面,并且修改data下的myid文件,修改为各自的id:
scp -r hadoop1:/hadoop/zookeeper
echo "2">/software/zookeeper-3.4.10/data/myid
为了方便可以将zookeeper的可执行文件目录添加到PATH环境变量中:
PATH=/software/zookeeper-3.4.10/bin;
分别在每个节点上/software/zookeeper-3.4.10/bin目录下
启动 ./zkServer.sh start;
查看启动状态 ./zkServer.sh status
停止 ./zkServer.sh stop
利用jps查看进程会多出:QuorumPeerMain
使用zkCli.sh -server IP:PORT来连接zookeeper集群,具体语法如下:
zkCli.sh -server 127.0.0.1:2181
使用help查看相关帮助;
[zk: 127.0.0.1:2181(CONNECTED) 0] help ZooKeeper -server host:port cmd args connect host:port get path [watch] ls path [watch] set path data [version] rmr path 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