一、前提条件
JDK1.7+
Hadoop 2.5.0+
Zookeeper 3.4.5+
下面介绍一下Zookeeper的安装:
(1)到Zookeeper官网下载Zookeeper最新安装包,
下载地址:http://mirrors.shu.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
(2)下载完成后使用命令 tar -zxvf zookeeper-3.4.11.tar.gz进行解压
(3)然后切换到其conf目录下
使用vim zoo.cfg新建一个配置文件。内容如下:
-
# 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=/home/chenjie/zookeeper-3.4.11/tmp
-
# 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
-
server.1=pc2:2888:3888
-
server.2=pc3:2888:3888
-
server.3=pc4:2888:3888
其中的主要配置项有
dataDir=/home/chenjie/zookeeper-3.4.11/tmp
-
server.1=pc2:2888:3888
-
server.2=pc3:2888:3888
-
server.3=pc4:2888:3888
dataDir是指定zookeeper的数据目录,在此我设置在了zookeeper根目录下的tmp目录下(此目录不存在,需要使用mkdir tmp创建)
类似于
server.1=pc2:2888:3888
是配置zookeeper的节点,有多少个节点就配置多少个server,依次为server.1、server.2。。。pc2、pc3、pc4为各节点的主机名。
(4)配置完成后,切换到刚才配置的dataDir下,在此目录下新建一个myid文件(使用命令 vim myid)
进入vim后按i进入编辑模式,输入当前节点的编号(server.1的编号为1,依次类推),按esc推出编辑模式,输入shift + : 然后输入wq回车保存退出。
(5)使用命令scp -r zookeeper-3.4.11 chenjie@pc3:/home/chenjie将刚才配置好的zookeeper发送到另外两个节点上。
【然后修改另外两台节点上的dataDir/myid中的id为它们各自的id】
(6)切换到bin目录下,使用命令启动zookeeper
如果出现启动不了的情况,记得关闭防火墙
因为防火墙没有关闭。关闭防火墙:
#查看防火墙状态
sudo service iptables status
#关闭防火墙
sudo service iptables stop
#查看防火墙开机启动状态
sudo chkconfig iptables --list
#关闭防火墙开机启动
sudo chkconfig iptables off