开发包
链接: https://pan.baidu.com/s/1jr4AKrazrp03Nrn3Nn1DfQ 密码: 2v8j
下载途径不唯一
解压改名
tar -vxf zookeeper-3.4.10.tar.gz
mv zookeeper-3.4.10 zookeeper
创建data、log文件夹以及编号
/software/zookeeper/是我开发包解压后的路径
# 创建文件夹
mkdir /software/zookeeper/data
mkdir /software/zookeeper/log
# 创建文件
touch /software/zookeeper/data/myid
# 把这个机器的编号设为0 为了后面方便选举leader
echo 0 >> /software/zookeeper/data/myid
配置zoo.cfg文件
重命名
mv zoo_sample.cfg zoo.cfg
vim zoo.cfg
dataDir是刚才创建的data文件夹路径
dataLogDir是刚才创建的log文件夹路径
clientPort是客户端的端号
quorumListenOnAllIPs=true代表在云服务器上搭建环境
server.0=yun1:2888:3888
server.1=yun2:2888:3888
0、1代表机器的编号,选举使用。
yun1、yun2代表机器的别名
2888代表第master和slave之间的通信端口
3888代表选举时的通信
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/software/zookeeper/data
# logs directory
dataLogDir=/software/zookeeper/log
# 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
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
quorumListenOnAllIPs=true
server.0=yun1:2888:3888
server.1=yun2:2888:3888
配置环境变量
vim /etc/profile
# zookeeper 环境
export ZOOKEEPER_HOME=/software/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
source /etc/profile
将配置文件拷贝到集群的其他机器
拷贝开发包
# root是用户 yun2是机器别名
scp -r /software/zookeeper/ root@yun2:/software/
拷贝过来的myid文件是不能用的,因为那是别人的编号,你需要更改成自己的编号。
拷贝环境变量
scp -r /etc/profile/ root@yun2:/etc/
测试环境
开启hadoop集群
start-dfs.sh
start-yarn.sh
开启zookeeper(每台机器都要开启,每台机器的开启间隔时间不要太长)
zkServer.sh start
查看机器状态(是leader还是追随者)
zkServer.sh status
如果你未配置成功,可以查看log文件夹(还记得log文件夹吗?)下的zookeeper.out文件,查看失败原因。
坑1(阿里云)
如果你的机器是阿里云,并且zookepper.out文件中出现以下内容。
设置阿里云的安全组,重启即可