集群安装(目前企业常用版本3.4.5,3.4.6,3.4.7)
机器规划
1.官网下载zookeeper安装包
#wget https://downloads.apache.org/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz
2.解压并修改配置
#tar -zxvf apache-zookeeper-3.6.3.tar.gz -C /home/hadoop/app
#ln -s /home/hadoop/app/apache-zookeeper-3.6.3-bin /home/hadoop/app/zookeeper
#cd /ho me/hadoop/app/zookeeper/
#mkdir data log
#cd conf/
#cp zoo_sample.cfg zoo.cfg
#vim zoo.cfg
dataDir=/home/hadoop/data/zookeeper
#zoo.cfg最后加上所有服务器的配置
server.1=dba-01:2888:3888
server.2=dba-02:2888:3888
server.3=dba-03:2888:3888
server.4=dba-04:2888:3888
server.5=dba-05:2888:3888
zookeeper每台服务器都要操作
#mkdir -p /home/hadoop/data/zookeeper
#echo [server.id] >/home/hadoop/data/zookeeper/myid
说明:server.id就是zoo.cfg配置的server.1,server.2等,要把1,2这样的编号写入myid
3.添加环境变量(root用户),每台zookeeper服务器都要修改
#vim /etc/profile
export ZOOKEEPER_HOME=/home/hadoop/app/zookeeper
export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
4.zookeeper安装文件传至其他服务器
#scp -r /home/hadoop/app/apache-zookeeper-3.6.3 dba-02:/home/hadoop/app/
建立软连接
#ln -s /home/hadoop/app/apache-zookeeper-3.6.3 /home/hadoop/app/zookeeper
5.启动zookeeper集群
#./zkServer.sh start
#jps
#./zkServer.sh status
常见问题
1.Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
问题原因:下载的zookeeper安装包为源码包,未进行编译,需要下载带bin的tar包。
2.Invalid config, exiting abnormally org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /home/hadoop/app/zookeeper/bin/../conf/zoo.cfg ...Caused by: java.lang.IllegalArgumentException: myid file is missing
问题原因:zoo.cfg配置文件加入内容不正确,myid文件必须在dataDir路径下。