将zookeeper压缩文件上传至node1中,Mac系统上传方式可以直接通过终端scp命令,Windows系统可以通过其他的上传工具。上传方式为:
scp /自己电脑本机路径/zookeeper-3.4.13.tar.gz [email protected]:/opt/Hadoop
上传成功之后需要对文件赋予权限
chmod u+x zookeeper-3.4.13.tar.gz
解压文件:
tar -zxvf zookeeper-3.4.13.tar.gz
创建软链接:
ln -s zookeeper-3.4.13 zookeeper
在安装zookeeper的时候我们要去修改zookeeper预装是conf目录下面的zoo_sample.cfg这个文件,首先我们要做的事就是重命名这个文件。在目录/opt/Hadoop/zookeeper/conf下,将zoo_sample.cfg改名为zoo.cfg文件,这一步非常重要,不修改的话会出现下面的问题:
ZooKeeper JMX enabled by default
Using config: /home/caizhengjie/zookeeper/bin/../conf/zoo.cfg
grep: /home/caizhengjie/zookeeper/bin/../conf/zoo.cfg: 没有那个文件或目录
mkdir: 无法创建目录"": 没有那个文件或目录
Starting zookeeper ... /home/caizhengjie/zookeeper/bin/zkServer.sh:行149: /zookeeper_server.pid: 权限不够
FAILED TO WRITE PID
这是第一个坑!
则我们需要修改文件名:
mv zoo_sample.cfg zoo.cfg
cd /opt/Hadoop/zookeeper/
mkdir tmp
cd tmp
mkdir data
cd /opt/Hadoop/zookeeper/tmp/data
vim myid
第一台主机node1添加内容:1
注意:一定要在刚才创建的data文件夹下在创建myid
如果直接在tmp文件夹下直接创建myid文件,查看zookeeper.out日志文件会报错
Caused by: java.lang.IllegalArgumentException: /opt/Hadoop/zookeeper/tmp/data/myid file is missing
这是第二个坑!
修改zookeeper/conf下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=5
#The number of ticks that can pass between
#sending a request and getting an acknowledgement
syncLimit=2
#the directory where the snapshot is stored.
#do not use /tmp for storage, /tmp here is just
#example sakes.
#**这个地方填写自己的路径**
dataDir=/opt/Hadoop/zookeeper/tmp/data
#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
#服务器名称与地址:集群信息(服务器编号、服务器编号、服务器地址、LF通信端口、选举端口)
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
配置环境变量:
vim ~/.bashrc
添加下面内容:
export ZOOKEEPER_HOME=/opt/Hadoop/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH
这里需要根据自己安装的路径来填写
使之生效:
source ~/.bashrc
在node1配置好文件之后,需要将文件分发到node2,node3机器下面。
scp -r zookeeper zookeeper-3.4.13 zookeeper-3.4.13.tar.gz caizhengjie@node2:/opt/Hadoop/
scp -r zookeeper zookeeper-3.4.13 zookeeper-3.4.13.tar.gz caizhengjie@node3:/opt/Hadoop/
参考node1的配置方法
前面在/opt/Hadoop/zookeeper/tmp/data/myid文件中,第一台主机添加内容:1
则在node2和node3中分别按下面修改
第二台主机添加内容:2
第三台主机添加内容:3
按照上面的步骤全部配置完成之后,可以启动zookeeper
启动命令(三台机同时启动):
zkServer.sh start
关闭命令:
zkServer.sh stop
出现下面的情况则安装成功
ZooKeeper JMX enabled by default
Using config: /opt/Hadoop/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
检验jps进程
4616 Jps
2041 QuorumPeerMain
查看运行状态(三台机同时)
zkServer.sh status
node1
ZooKeeper JMX enabled by default
Using config: /opt/Hadoop/zookeeper/bin/../conf/zoo.cfg
Mode: follower
node2
ZooKeeper JMX enabled by default
Using config: /opt/Hadoop/zookeeper/bin/../conf/zoo.cfg
Mode: leader
node3
ZooKeeper JMX enabled by default
Using config: /opt/Hadoop/zookeeper/bin/../conf/zoo.cfg
Mode: follower
会发现其中有一台机器是leader,其他两台机器是follower
到这里zookeeper集群模式就安装成功了!
总结:如果运行出错,多看zookeeper.out日志文件
以上内容仅供参考学习,如有侵权请联系我删除!
如果这篇文章对您有帮助,左下角的大拇指就是对博主最大的鼓励。您的鼓励就是博主最大的动力!