之前已经在CentOS 6.7上安装部署Hadoop 2.7.2(http://www.jb51.cc/article/p-umbfvzwc-bew.html),并正常启动Hadoop集群。
安装部署ZooKeeper
master
[root@master ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/zookeeper-3.4.9.tar.gz
[root@master ~]# tar -zxvf zookeeper-3.4.9.tar.gz
[root@master ~]# mv zookeeper-3.4.9 /usr/local/
- 提供相同应用的服务器组称为一个quorum,quorum中的所有机器都有相同的配置文件。
建立数据目录
[root@master ~]# mkdir -p /usr/local/zookeeper-3.4.9/data
编辑配置文件
[root@master ~]# cp /usr/local/zookeeper-3.4.9/conf/zoo_sample.cfg /usr/local/zookeeper-3.4.9/conf/zoo.cfg
[root@master ~]# vi /usr/local/zookeeper-3.4.9/conf/zoo.cfg
dataDir=/usr/local/zookeeper-3.4.9/data
server.1=master:2888:3888
server.2=slave:2888:3888
保存退出
- 注:2888端口号是ZooKeeper服务之间通信的端口,而3888是ZooKeeper与其他应用程序通信的端口。
ZooKeeper环境变量
[root@master ~]# vi /etc/profile.d/zookeeper.sh
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.9
export PATH=$PATH:$ZOOKEEPER_HOME/bin
保存退出
[root@master ~]# source /etc/profile.d/zookeeper.sh
[root@master ~]# scp -r /etc/profile.d/zookeeper.sh slave:/etc/profile.d/
[root@master ~]# scp -r /usr/local/zookeeper-3.4.9 slave:/usr/local/
[root@master ~]# echo $?
0
[root@master ~]# vi /usr/local/zookeeper-3.4.9/data/myid
1
保存退出
slave
[root@slave ~]# vi /usr/local/zookeeper-3.4.9/data/myid
2
保存退出
[root@slave ~]# source /etc/profile.d/zookeeper.sh
启动ZooKeeper集群
master
[root@master ~]# /usr/local/zookeeper-3.4.9/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@master ~]# /usr/local/zookeeper-3.4.9/bin/zkCli.sh -server master:2181
[zk: master:2181(CONNECTED) 0] help
[zk: master:2181(CLOSED) 3] quit
[root@master ~]#
slave
[root@slave ~]# /usr/local/zookeeper-3.4.9/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@slave ~]# /usr/local/zookeeper-3.4.9/bin/zkCli.sh -server slave:2181
[zk: slave:2181(CONNECTED) 0] quit