安装zookeeper-3.5.1之前是将hadoop已经安装完毕
下载地址
http://mirror.bit.edu.cn/apache/zookeeper/
集群节点环境
192.168.8.141 HD1
192.168.8.142 HD2
192.168.8.143 HD3
192.168.8.144 HD4
安装准备
上传至HD1 解压
gunzip zookeeper-3.5.1-alpha.tar.gz
tar –xvf zookeeper-3.5.1-alpha.tar
移至/usr 目录下
Mv zookeeper-3.5.1-alpha /usr/ zookeeper
设置环境变量
Vi /etc/profile
export ZOOKEEPER_HOME=/usr/zookeeper
exportPATH=$PATH:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf
安装zookeeper
配置zookeeper的cfg文件
Cd /usr/zookeeper/conf
Cp zoo_sample.cfg zoo.cfg
配置如下
[root@HD1 conf]# more 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 anacknowledgement
syncLimit=5
# the directory where the snapshot isstored.
# do not use /tmp for storage, /tmp here isjust
# example sakes.
dataDir=/usr/zookeeper/data
dataLogDir/usr/zookeeper/logs
# the port at which the clients willconnect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle moreclients
#maxClientCnxns=60
#
# Be sure to read the maintenance sectionof the
# administrator guide before turning onautopurge.
#
#http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain indataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable autopurge feature
#autopurge.purgeInterval=1
server.1=HD1:2888:3888
server.2=HD2:2888:3888
server.3=HD3:2888:3888
server.4=HD4:2888:3888
建立/usr/zookeeper/data这个目录
Mkdir –p /usr/zookeeper/data
建立myid
Touch /usr/zookeeper/data/myid
同步配置
复制同步配置至HD2,HD3,HD4
scp –r /usr/zookeeper HD2:/usr/.
scp –r /usr/zookeeper HD3:/usr/.
scp –r /usr/zookeeper HD4:/usr/.
Scp –r /etc/profile HD2:/etc/.
Scp –r /etc/profile HD3:/etc/.
Scp –r /etc/profile HD4:/etc/.
编辑myid
Vi /usr/zookeeper/data/myid
根据zoo.cfg的配置上server.*在1-4号机分别填入相对应的1-4
分别在1-4号机上执行 source /etc/profile
启动zookeeper
分别在1-4号机上启动zookeeper
#zkServer.shstart
Using config:/usr/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
验证zookeeper是否启动成功
[root@HD2 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config:/usr/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address:localhost.
Mode: follower