1.安装jdk1.7,配置环境变量
下载jdk http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html
tar -zxvf ./jdk-7u71-linux-x64.tar.gz
配置环境变量
进入/etc/profile, 粘贴以下脚本到文件,保存文件。
export PATH=/usr/jdk1.7.0_71/bin:$PATH
export classpath=/usr/jdk1.7.0_71/lib
export JAVA_HOME=/usr/jdk1.7.0_7
2.下载zookeeper-3.4.6.tar.gz
http://apache.fayea.com/zookeeper/zookeeper-3.4.6/
3.解压zookeeper-3.4.6.tar.gz
tar -zvxf zookeeper-3.4.6.tar.gz
4.修改zookeeper-3.4.6/conf目录,修改zookeeper_sample.cfg为 zoo.cfg
cp zoo_sample.cfg zoo.cfg
5.配置zoo.cfg dataDir目录和log目录
# 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/user/software/zookeeper-3.4.6/data
dataLogDir=/home/user/software/zookeeper-3.4.6/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.
#
# 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
参数说明:
tickTime:ZK中的一个时间单元。ZK所有时间都是以这个时间单元为基础,进行整数倍配置。例如session的最小超时时间是2*ticktime。
dataDir:zookeeper的工作目录,注释写得很清楚,只有测试环境才使用tmp目录,否则都建议进行专门的设置。
dataLogDir:zookerper日志输出的目录
clientPort:客户端的连接端口
maxClientCnxns:客户端最大连接数
clientport:客户端连接server的端口,即对外服务端口,一般设置为2181
6.启动zookeeper,进入bin目录
./zkServer.sh start
7.检查zookeeper是否启动成功,采用jps命令即可
出现如下内容说明启动成功
3129 Jps
2973 QuorumPeerMain
QuorumPeerMain这个进程就是zookeeper的进程。至此,zookeeper的单节点安装就成功了。
8.查看后台的zookeeper节点信息,进入bin目录执行如下命令
./zkCli.sh