zookeeper安装与部署的几个基本步骤:
1.环境准备
由于zookeeper是用java写的当然需要有java运行环境,即JDK的安装与环境变量的设置
1)这里建议到甲骨文官网 http://www.oracle.com/technetwork/java/javase/downloads/index.html 下载jdk-7u79-linux-x64.tar.gz
2)解压到指定目录 使用如下命名解压
tar zxvf jdk-7u79-linux-x64.tar.gz -C /usr/lib/jvm
如果目录不存在 mkdir /usr/lib/jvm
3)重命名
mv jdk1.7.0_79 java
4)配置环境变量 编辑 .bashrc 文件
vim ~/.bashrc
在文件末尾追加
export JAVA_HOME=/usr/lib/jvm/java
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
5)使勇source 命名使环境变量生效
source ~/.bashrc
2.下载zookeeper安装包 zookeeper-3.4.6.tar.gz
解压到 指定目录
tar zxvf zookeeper-3.4.6.tar.gz -C /opt/zookeeper-3.4.6
3.配置zoo.cfg文件
cd /opt/zookeeper-3.4.6/zookeeper-3.4.6
初次使用,需要将zookeeper安装目录conf目录下 zoo_sample.cfg文件重命名为zoo.cfg
vim zoo.cfg
修改配置
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.
dataDir=/var/lib/zookeeper/
# do not use /tmp for storage, /tmp here is just
# example sakes.
# the port at which the clients will connect
clientPort=2181
server.1=127.0.0.1:2888:3888
4.创建myid文件
在dataDir配置目录下创建myid文件 添加内容为 对应server.后面数值
vim myid
5.启动服务器
配置zookeeper环境变量编辑 .bashrc 文件 追加
export ZOOKEEPER_HOME=/opt/zookeeper-3.4.6/zookeeper-3.4.6
export PATH=${ZOOKEEPER_HOME}/bin:$PATH
启动命令
zkServer.sh start
停止命令
zkServer.sh stop
6.验证服务器
telnet 127.0.0.1 2181
输入stat查看统计信息
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stat
Zookeeper version: 3.4.6-1569965, built on 02/20/2014 09:09 GMT
Clients:
/127.0.0.1:37360[0](queued=0,recved=1,sent=0)
Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x0
Mode: standalone
Node count: 4
Connection closed by foreign host.
看到类似信息 说明启动成功