部署zookeeper实践

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
相关文章
相关标签/搜索
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。