博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
部署zookeeper实践
阅读量:5367 次
发布时间:2019-06-15

本文共 6535 字,大约阅读时间需要 21 分钟。

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

转载于:https://www.cnblogs.com/jhcelue/p/7050759.html

你可能感兴趣的文章
编程算法基础-一刀切法
查看>>
双slave的server_uuid同样问题
查看>>
node-exporter cpu使用率为负数
查看>>
互联网广告的效果真实性
查看>>
Spatial Database使用时的一次debug(sdo_nn)
查看>>
LightTools 光谱信息导入
查看>>
操作系统的基本概念和功能
查看>>
如何将XSD文件以及引入import的文件生成相应的C#类。
查看>>
当早上醒来,能想到的只有上厕所
查看>>
专业程序员的7个特质
查看>>
OC 继承子类对象调用方法机制 子类对象访问父类中的实例变量
查看>>
我的青春
查看>>
window.opener方法的使用 js跨域
查看>>
WPF ”真正的“高仿QQ
查看>>
201621123083 《Java程序设计》第12周学习总结
查看>>
bootstrap
查看>>
博客第一天!回首~~~~~~遥望~~~~~~
查看>>
洛谷P2234 [HNOI2002] 营业额统计 [splay]
查看>>
android中asynctask的使用实例
查看>>
仰慕墙
查看>>