ZooKeeper安装方法详解

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/bin
3、创建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的集群模式已成功安装











你可能感兴趣的:(ZooKeeper,hadoop学习笔记)