前几天自己在家搞了个zookeeper+dubbo的环境。下面来介绍一下怎么在Linux下面安装Zookeeper。本文的Linux环境为CentOS6.5.
准备工作
在安装zookeeper之前我们需要先做两件事。第一是安装Oracle的JDK。具体的安装步骤请看这里 Linux(CentOs6.5)系统安装JDK。第二是下载zookeeper的安装包,下载地址请点击这里下载。安装
首先我们需要在/usr/local下面创建个zookeeper文件夹,把刚才下载下来的zookeeper放到这里。用tar -zxvf来解压zookeeper的安装包。解压完成之后我们进入到刚才解压出来的文件夹下面,内容如下所示:
我们进入到conf文件夹下面,将zoo_sample.cfg这个文件复制为zoo.cfg(必须是这个文件):

接下来我们需要需改刚才复制的zoo.cfg文件,修改内容为下面图中的蓝色部分:

........等等。
配置环境变量
上面的操作都完事之后,我们需要配置一下环境变量,配置环境变量的命令如下: export ZOOKEEPER_INSTALL=/usr/local/zookeeper/zookeeper-3.3.6/(Zookeeper所在的目录)export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
启动Zookeeper
在上面的操作都完事之后,我们需要来启动一下Zookeeper来检测下我们的成果了。首先我们进入到Zookeeper的bin目录下面,启动Zookeeper的命令为./zkServer.sh start。一定不要忘了前面的 . ,启动效果如图所示:
我们可以通过 ./zkServer.sh status命令来查看Zookeeper的运行状态。如图所示:

或者我们也可以用 ps -ef|grep zookeeper来查看Zookeeper的运行状态:

注意:如果你发现Zookeeper不是在运行状态的话,可以通过cat zookeeper.out来查看启动过程中的出错信息。 zookeeper的服务端起来之后我们需要启动Zookeeper的客户端,启动命令如下:./zkCli.sh。启动结果如下所示:

OK,到此你的Zookeeper就安装完成了。如果安装过程中遇到什么问题,请在下面留言。