前置:
使用hadoop 用户在各节点都安装jdk 1.8
下载jdk tar 包:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
上传软件至共享目录: /opt/nfs_share/software
解压:tar -zxvf /opt/nfs_share/software/jdk-8u191-linux-x64.tar.gz
创建java目录:mkdir /opt/java
将共享目录解压后的安装目录移动: cp -R /opt/nfs_share/jdk1.8.0_191/ /opt/java/
配置java 环境变量:$JAVA_HOME/bin 置于PATH前面
vim ~/.bash_profile
#增加
export JAVA_HOME=/opt/java/jdk1.8.0_191
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.ja
export PATH=$JAVA_HOME/bin:$PATH
source ~/.bash_profile
下载jar包:
https://www.apache.org/dyn/closer.cgi/zookeeper/
使用hadoop用户登录:
上传zookeeper-3.4.12.tar.gz到服务器(192.168.1.126: /opt/nfs_share/software)
解压:tar -zxvf zookeeper-3.4.12.tar.gz
创建专用目录:mkdir -p /opt/zookeeper
移动到/opt目录下: mv zookeeper-3.4.12/ /opt/zookeeper
赋权: sudo chown -R hadoop:hadoop /opt/zookeeper/zookeeper-3.4.12/
vim ~/.bash_profile
#添加
export ZOOKEEPER_HOME=/opt/zookeeper/zookeeper-3.4.12
export PATH=$ZOOKEEPER_HOME/bin:$PATH
复制zookeeper配置模板:
cp /opt/zookeeper/zookeeper-3.4.12/conf/zoo_sample.cfg /opt/zookeeper/zookeeper-3.4.12/conf/zoo.cfg
编辑配置文件:
vim /opt/zookeeper/zookeeper-3.4.12/conf/zoo.cfg
#调整
(若无对应路径文件夹,需要创建:mkdir -p /opt/zookeeper/zookeeper-3.4.12/data)
dataDir=/opt/zookeeper/zookeeper-3.4.12/data
#注意:dataDir一定要显示写出,不要用变量如$ZOOKEEPER_HOME/data
#新增:增加三个节点的地址(zookeeper节点数量必须是奇数)
server.1=hdp-01:2888:3888
server.2=hdp-02:2888:3888
server.3=hdp-03:2888:3888
#其它根据需要自行调整
前提:各节点目标目录需要具有hadoop用户的写权限;
此处直接: chown -R hadoop:hadoop /opt
scp -r /opt/zookeeper/ hadoop@hdp-02:/opt
scp -r /opt/zookeeper/ hadoop@hdp-03:/opt
#复制
scp ~/.bash_profile hadoop@hdp-02:~/.bash_profile
scp ~/.bash_profile hadoop@hdp-03:~/.bash_profile
#立即生效
ssh hdp-02 source ~/.bash_profile
ssh hdp-03 source ~/.bash_profile
ssh hdp-02 mkdir -p $ZOOKEEPER_HOME/data
ssh hdp-03 mkdir -p $ZOOKEEPER_HOME/data
三台机器都需要创建:与zoo.cfg中的server.id 保持一致
hdp-01:
echo "1" > /opt/zookeeper/zookeeper-3.4.12/data/myid
ssh hdp-02:
ssh hdp-02 echo "2" > /opt/zookeeper/zookeeper-3.4.12/data/myid
ssh hdp-03:
ssh hdp-03 echo "3" > /opt/zookeeper/zookeeper-3.4.12/data/myid
sh /opt/zookeeper/zookeeper-3.4.12/bin/zkServer.sh start
ssh hdp-02 sh /opt/zookeeper/zookeeper-3.4.12/bin/zkServer.sh start
ssh hdp-03 sh /opt/zookeeper/zookeeper-3.4.12/bin/zkServer.sh start
启动后存在 QuorumPeerMain 进程
若无对应进程,可查看日志:(该文件存在于启动zk时的所处目录(可能会不断变化)
tail -30 zookeeper.out
sh /opt/zookeeper/zookeeper-3.4.12/bin/zkServer.sh status
会推举一个leader ,其余都是follower
sh /opt/zookeeper/zookeeper-3.4.12/bin/zkServer.sh stop
sh /opt/zookeeper/zookeeper-3.4.12/bin/zkServer.sh restart