1.解压zookeeper

2.环境变量设置

hadoop@namenode:~/zookeeper-3.4.6/conf$ sudo vim /etc/profile

export JAVA_HOME=/usr/programs/jdk1.7.0_65

export HADOOP_HOME=/home/hadoop/hadoop-1.2.1

export HADOOP_CONF_DIR=/home/hadoop/hadoop-1.2.1/conf

export MAHOUT_HOME=/home/hadoop/mahout-distribution-0.9

export MAHOUT_CONF_DIR=/home/hadoop/mahout-distribution-0.9/conf

export ZOOKEEPER_HOME=/home/hadoop/zookeeper-3.4.6

export PATH=$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$HADOOP_HOME/bin:$MAHOUT_HOME/bin:$PATH

3.新建zookeeper暂时文件夹

hadoop@namenode:~/zookeeper-3.4.6$ mkdir temp

4.改动文件 zoo_sample.cfg

hadoop@namenode:~/zookeeper-3.4.6/conf$ sudo vim zoo_sample.cfg

改动dataDir=/home/hadoop/zookeeper-3.4.6/temp

添加

server.0=namenode:2888:3888

server.1=datanode1:2888:3888

server.2=datanode2:2888:3888

5.重命名zoo.sample.cfg

hadoop@namenode:~/zookeeper-3.4.6/conf$ mv zoo_sample.cfg zoo.cfg

6.在第3步创建的目录以下新建文件。内容为0

hadoop@namenode:~/zookeeper-3.4.6/temp$ vim myid

0

7.把zookeeper拷贝到各个节点

scp -r zookeeper-3.4.6/ hadoop@datanode1:/home/hadoop/

scp -r zookeeper-3.4.6/ hadoop@datanode2:/home/hadoop/

8.改动各个节点的myid

hadoop@namenode:~/zookeeper-3.4.6$ ssh datanode1

hadoop@datanode1:~$ cd zookeeper-3.4.6/temp/

hadoop@datanode1:~/zookeeper-3.4.6/temp$ vim myid

1

hadoop@namenode:~/zookeeper-3.4.6$ ssh datanode2

hadoop@datanode1:~$ cd zookeeper-3.4.6/temp/

hadoop@datanode1:~/zookeeper-3.4.6/temp$ vim myid

2

9.开启zookeeper

hadoop@namenode:~/zookeeper-3.4.6/bin$ zkServer.sh start

JMX enabled by default

Using config: /home/hadoop/zookeeper-3.4.6/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

你会发现多了一个zookeeper.out的文件,而且里面是报错的,报错的原因是其它节点没有开zookeeper,你得依照上面的方式在每一个节点开启zookeeper

hadoop@namenode:~/zookeeper-3.4.6/bin$ ls

README.txt  zkCleanup.sh  zkCli.cmd  zkCli.sh  zkEnv.cmd  zkEnv.sh  zkServer.cmd  zkServer.sh  zookeeper.out

10.一个错误

假设你zookeeper的环境变量没有配,会出现这种情况

 hadoop@datanode2:~/zookeeper-3.4.6/bin$ sh zkServer.sh

JMX enabled by default

zkServer.sh: 81: /home/hadoop/zookeeper-3.4.6/bin/zkEnv.sh: Syntax error: "(" unexpected (expecting "fi") 

11.命令行的操作
进入命令行
hadoop@namenode:~/zookeeper-3.4.6/bin$ zkCli.sh 
Connecting to localhost:2181

2014-11-16 01:18:30,600 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT

2014-11-16 01:18:30,604 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=namenode

2014-11-16 01:18:30,605 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_65

2014-11-16 01:18:30,608 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation

2014-11-16 01:18:30,608 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/programs/jdk1.7.0_65/jre

2014-11-16 01:18:30,609 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/hadoop/zookeeper-3.4.6/bin/../build/classes:/home/hadoop/zookeeper-3.4.6/bin/../build/lib/*.jar:/home/hadoop/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/hadoop/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/home/hadoop/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/home/hadoop/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/home/hadoop/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/home/hadoop/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/home/hadoop/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/home/hadoop/zookeeper-3.4.6/bin/../conf:

2014-11-16 01:18:30,610 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/i386:/lib:/usr/lib

2014-11-16 01:18:30,610 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp

2014-11-16 01:18:30,611 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>

2014-11-16 01:18:30,614 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux

2014-11-16 01:18:30,614 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=i386

2014-11-16 01:18:30,615 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.5.0-23-generic

2014-11-16 01:18:30,615 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=hadoop

2014-11-16 01:18:30,615 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/hadoop

2014-11-16 01:18:30,616 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/hadoop/zookeeper-3.4.6/bin

2014-11-16 01:18:30,618 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@e13c84

Welcome to ZooKeeper!

2014-11-16 01:18:30,653 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)

2014-11-16 01:18:30,665 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@852] - Socket connection established to localhost/127.0.0.1:2181, initiating session

JLine support is enabled

2014-11-16 01:18:30,679 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x49b7dc68450002, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: localhost:2181(CONNECTED) 0] ls /

[zookeeper]

[zk: localhost:2181(CONNECTED) 1] ls /zookeeper

[quota]

[zk: localhost:2181(CONNECTED) 2] ls /zookeeper/quota

[]

[zk: localhost:2181(CONNECTED) 3] create /key value

Created /key
[zk: localhost:2181(CONNECTED) 5] ls / 

[key, zookeeper]
[zk: localhost:2181(CONNECTED) 6] get /key

value

cZxid = 0x100000006

ctime = Sun Nov 16 01:20:15 PST 2014

mZxid = 0x100000006

mtime = Sun Nov 16 01:20:15 PST 2014

pZxid = 0x100000006

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 5

numChildren = 0

12.測试zookeeper的一致性
在上一步(11.命令行的操作)里面,我们在namenode里面往zookeeper里面放了key。如今我们看看在其它节点datanode1是否也会出现这个
hadoop@namenode:~/zookeeper-3.4.6/bin$ ssh datanode1
hadoop@datanode1:~$ zkCli.sh 
[zk: localhost:2181(CONNECTED) 2] get /key

value

cZxid = 0x100000006

ctime = Sun Nov 16 01:20:15 PST 2014

mZxid = 0x100000006

mtime = Sun Nov 16 01:20:15 PST 2014

pZxid = 0x100000006

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 5

numChildren = 0
也是出现了key文件,表示在各个节点是有同步的

13.最后补充一个查看mode的命令
hadoop@datanode1:~/zookeeper-3.4.6/bin$ zkServer.sh status

JMX enabled by default

Using config: /home/hadoop/zookeeper-3.4.6/bin/../conf/zoo.cfg

Mode: leader

部署zookeeper实践的更多相关文章

  1. Elasticstack 5.1.2 集群日志系统部署及实践

    Elasticstack 5.1.2 集群日志系统部署及实践 一.ELK Stack简介 ELK Stack 是Elasticsearch.Logstash.Kibana三个开源软件的组合,在实时数据 ...

  2. 在 CentOS7 上部署 zookeeper 服务

    在 CentOS7 上部署 zookeeper 服务 1 用 SecureCRT 或 XShell 等 Linux 客户端工具连接至 CentOS7 服务器: 2 进入到 /usr/local/too ...

  3. Linux环境快速部署Zookeeper集群

    一.部署前准备: 1.下载ZooKeeper的安装包: http://zookeeper.apache.org/releases.html 我下载的版本是zookeeper-3.4.9. 2.将下载的 ...

  4. 在CentOS7部署zookeeper集群以及简单API使用

    一.部署zookeeper集群 zookeeper是一个针对大型分布式系统的协调系统,提供的功能有统一名称服务.分布式同步等. 1.上传zk安装包 2.解压     tar -xzvf zookeep ...

  5. Cobbler自动化部署最佳实践

    第1章 Cobbler自动化部署最佳实践 运维自动化在生产环境中占据着举足轻重的地位,尤其是面对几百台,几千台甚至几万台的服务器时,仅仅是安装操作系统,如果不通过自动化来完成,根本是不可想象的. 面对 ...

  6. tomcat部署最佳实践(一)

    Tomcat部署最佳实践 标签: linux 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 tomcat是玩web软件必会技能之一,今天我给大家介绍一下tomc ...

  7. AWS EC2 CentOS release 6.5 部署zookeeper、kafka、dubbo

    AWS EC2 CentOS release 6.5 部署zookeeper.kafka.dubbo参考:http://blog.csdn.net/yizezhong/article/details/ ...

  8. 【公开课】【阿里在线技术峰会】魏鹏:基于Java容器的多应用部署技术实践

    对于公开课,可能目前用不上这些,但是往往能在以后想解决方案的时候帮助到我.以下是阿里对公开课的整理 摘要: 在首届阿里巴巴在线峰会上,阿里巴巴中间件技术部专家魏鹏为大家带来了题为<基于Java容 ...

  9. ZooKeeper 01 - 什么是ZooKeeper + 部署ZooKeeper集群

    目录 1 什么是ZooKeeper 2 ZooKeeper的功能 2.1 配置管理 2.2 命名服务 2.3 分布式锁 2.4 集群管理 3 部署ZooKeeper集群 3.1 下载并解压安装包 3. ...

随机推荐

  1. vue-router的创建(1)

    vue-router的创建 <!doctype html> <html lang="en"> <head> <meta charset=& ...

  2. 关于Vue实例的生命周期(2)

     关于Vue实例的生命周期(2) 创建(create)->挂载(mount)->更新(update)->销毁(destory) 钩子函数触发事件 beforeCreate 在实例初始 ...

  3. POJ 1942

    开始时竟然用了分情况讨论. 仔细思考一下,哈哈,发现不过是多重集合的组合数而已. #include <iostream> #include <cstdio> #include ...

  4. Android本地存储方案 SharedPreferences

    原文地址:http://www.yanwushu.com/post/43.html 存储位置 SharedPreferences数据保存在: /data /data/<package_name& ...

  5. [Android] Android开发优化之——对界面UI的优化(2)

    在Android应用开发过程中,屏幕上控件的布局代码和程序的逻辑代码通常是分开的.界面的布局代码是放在一个独立的xml文件中的,这个文件里面是树型组织的,控制着页面的布局.通常,在这个页面中会用到很多 ...

  6. ThinkPHP5.0框架开发--第4章 TP5.0路由

    ThinkPHP5.0框架开发--第4章 TP5.0路由 第4章 TP5.0 路由 ================================================== 上次复习 1. ...

  7. ES task管理

    Task Management API The Task Management API is new and should still be considered a beta feature. Th ...

  8. nyoj--27--水池数目(dfs)

    水池数目 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 南阳理工学院校园里有一些小河和一些湖泊,现在,我们把它们通一看成水池,假设有一张我们学校的某处的地图,这个地图上 ...

  9. java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceE解决方法

    笔者是使用spring4.0时,报的错误: 原因是没有引入spring-tx-4.0.0.RELEASE.jar包,將spring-tx-4.0.0.RELEASE.jar添加到build path中 ...

  10. 内部div自动扩张剩余宽度

    <div id="container"> <div id="left">左边</div> <div id=" ...