ZooKeeper安装方式分为两种,一种为单机模式。一个为集群模式,集群模式须要事先正确配置hadoop集群,安装方法參考hadoop-1.2.1安装方法具体解释
单机模式安装:
1、上传并解压zookeeper-3.4.5.tar.gz
[hadoop@mdw temp]$ cp
/mnt/cdrom/zookeeper-3.4.5.tar.gz .
[hadoop@mdw temp]$ tar
xzf zookeeper-3.4.5.tar.gz
2、在.bashrc文件里配置ZooKeeper环境变量,并使之生效
export ZOOKEEPER_HOME=/home/hadoop/zookeeper-3.4.5 export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HBASE_HOME/bin:$HIVE_HOME/bin:$PIG_HOME/bin:$ZOOKEEPER_HOME/bin3、创建ZooKeeper数据文件夹
[hadoop@mdw ~]$ mkdir -p /home/hadoop/data/zookeeper
4、复制/home/hadoop/zookeeper-3.4.5/conf/zoo_sample.cfg文件。命令为zoo.cfg
[hadoop@mdw conf]$ cp zoo_sample.cfg zoo.cfg
5、改动ZooKeeper的配置文件zoo.cfg中的參数,设置dataDir为刚创建的文件夹
dataDir=/home/hadoop/data/zookeeper
6、启动ZooKeeper
[hadoop@mdw ~]$ zkServer.sh start
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
能够看到ZooKeeper已启动,至此单机模式的ZooKeeper已完毕安装。
集群模式安装:
在单机模式的基础上继续改动配置:
1、停止ZooKeeper
[hadoop@mdw ~]$ zkServer.sh stop
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
2、改动zoo.cfg配置參数。加入下面内容
dataLogDir=/home/hadoop/zookeeper-3.4.5/logs
server.1=192.168.10.200:7000:7001
server.2=192.168.10.201:7000:7001
server.3=192.168.10.202:7000:7001
这里的ip是三台主机的ip
3、在ZooKeeper安装文件夹下创建日志logs文件夹,即參数dataLogDir配置的文件夹
[hadoop@sdw1 zookeeper-3.4.5]$ mkdir logs
4、在三台主机上都创建ZooKeeper的data文件夹
[hadoop@mdw ~]$ mkdir -p /home/hadoop/data/zookeeper
[hadoop@sdw1 ~]$ mkdir -p /home/hadoop/data/zookeeper
[hadoop@sdw2 ~]$ mkdir -p /home/hadoop/data/zookeeper
5、三台电脑上分别在ZooKeeper的data文件夹(/home/hadoop/data/zookeeper)创建myid文件,内容分别为1、2、3
[hadoop@mdw zookeeper]$ cat myid
1
[hadoop@swd1 zookeeper]$ cat myid
2
[hadoop@sdw2 zookeeper]$ cat myid
3
6、将配置好的ZooKeeper安装文件和.bashrc文件发送到另外两台主机
[hadoop@mdw ~]$ scp -r zookeeper-3.4.5/ sdw1:~
[hadoop@mdw ~]$ scp -r zookeeper-3.4.5/ sdw2:~
[hadoop@mdw ~]$ scp .bashrc sdw1:~
[hadoop@mdw ~]$ scp .bashrc sdw2:~
7、在三台主机上分别启动ZooKeeper
[hadoop@mdw ~]$ zkServer.sh start
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@sdw1 ~]$ zkServer.sh start
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@sdw2 ~]$ zkServer.sh start
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
8、检查ZooKeeper的状态
[hadoop@mdw ~]$ jps
3316 QuorumPeerMain
2747 JobTracker
2664 SecondaryNameNode
2517 NameNode
3333 Jps
[hadoop@mdw ~]$ zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower
[hadoop@sdw1 ~]$ jps
3006 QuorumPeerMain
2271 DataNode
3141 Jps
2335 TaskTracker
[hadoop@sdw1 ~]$ zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: leader
[hadoop@sdw2 ~]$ jps
2286 DataNode
2354 TaskTracker
2901 Jps
2796 QuorumPeerMain
[hadoop@sdw2 ~]$ zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower
到此ZooKeeper的集群模式已安装成功