轻松搭建hadoop-1.2.1集群(4)--配置Zookeeper集群

 

轻松搭建hadoop-1.2.1集群(4)--配置Zookeeper集群

 

1、解压:

解压存放目录:

[root@hadoop0 local]# pwd
/usr/local
[root@hadoop0 local]#

解压完毕:

[root@hadoop0 local]# ll
总用量 148828
drwxr-xr-x. 10 root root     4096 11月  5 2012 zookeeper
-rw-r--r--. 1 root root 16402010 2月  23 12:12 zookeeper-3.4.5.tar.gz


2、配置环境变量:

 

编辑配置文件:

[root@hadoop0 local]# vim /etc/profile

 

配置内容:

#set zookeeper path
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=.:$ZOOKEEPER_HOME/bin:$PATH

是配置生效:

[root@hadoop0 local]# source /etc/profile

 

3、配置zoo.cfg文件:

把zoo_sample.cfg修改为zoo.cfg:

 

操作命令如下:

[root@hadoop0 zookeeper]# cd conf
[root@hadoop0 conf]# ls
configuration.xsl  log4j.properties  zoo_sample.cfg
[root@hadoop0 conf]# mv zoo_sample.cfgzoo.cfg
[root@hadoop0 conf]# ls
configuration.xsl  log4j.properties  zoo.cfg
[root@hadoop0 conf]#


4、编辑zoo.cfg

 

编辑的第一个地方:

dataDir=/usr/local/zookeeper/data

编辑的第二个地方:

server.0=hadoop0:2888:3888
server.1=hadoop1:2888:3888
server.2=hadoop2:2888:3888

5、配置data文件:

进入如下目录:

[root@hadoop0 zookeeper]# pwd

/usr/local/zookeeper

 

创建data文件夹:

[root@hadoop0 zookeeper]# mkdir data


创建编辑myid,在里面赋值为0:

[root@hadoop0 data]# vim myid


操作完查看myid的内容:

[root@hadoop0 data]# more myid
0
[root@hadoop0 data]#


6、把zookeeper目录拷贝到其它两台机器上:

拷贝到hadoop1机器上:

[root@hadoop0 data]# scp -r/usr/local/zookeeper 192.168.1.3:/usr/local/


拷贝到hadoop2机器上:

[root@hadoop0 data]# scp -r/usr/local/zookeeper 192.168.1.4:/usr/local/


7、把/etc/profile配置文件拷贝到其它两台机器上:

拷贝到hadoop1上去:

[root@hadoop0 data]# scp /etc/profile192.168.1.3:/etc/
profile                                                                     100% 2203     2.2KB/s  00:00


拷贝到hadoop2上去:

[root@hadoop0 data]# scp /etc/profile192.168.1.4:/etc/
profile                                                                    100% 2203     2.2KB/s   00:00


在hadoop1上执行下面命令只配置生效:

[root@hadoop1 zookeeper]# source/etc/profile


在hadoop2上执行下面命令只配置生效:

[root@hadoop2 zookeeper]# source/etc/profile


8、编辑myid文件:

编辑hadoop1上的myid并写入值为1:

[root@hadoop1 data]# vim myid
[root@hadoop1 data]# more myid
1
[root@hadoop1 data]#


编辑hadoop2上的myid并写入值为1:

[root@hadoop2 data]# vim myid
[root@hadoop2 data]# more myid
2
[root@hadoop2 data]#


9、启动zookeeper:

启动zookeeper命令:zkServer.shstart

 

启动hadoop0上的zookeeper:

 

[root@hadoop0bin]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@hadoop0 bin]#


启动hadoop1上的zookeeper:

 [root@hadoop1bin]# zkServer.sh start
JMX enabled by default
Using config:/usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@hadoop1 bin]#


启动hadoop2上的zookeeper:

 [root@hadoop2bin]# zkServer.sh start
JMX enabled by default
Using config:/usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@hadoop2 bin]#


10、查看zookeeper状态

查看zookeeper状态命令:zkServer.sh status

 

查看hadoop0机器,为follower

[root@hadoop0 bin]# zkServer.sh status
JMX enabled by default
Using config:/usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@hadoop0 bin]#


查看hadoop2机器,为leader

[root@hadoop1 bin]# zkServer.sh status
JMX enabled by default
Using config:/usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@hadoop1 bin]#


查看hadoop2机器,为follower

[root@hadoop2 bin]# zkServer.sh status
JMX enabled by default
Using config:/usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@hadoop2 bin]#


11、正常报错:

11.1、查看hadoop0上的zookeeper.out文件,会显示连接hadoop1、hadoop2错误:

 

[root@hadoop0 bin]# ls

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

 

[root@hadoop0 bin]# more zookeeper.out
2015-02-23 12:57:16,852 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading configurationfrom: /usr/local/z
ookeeper/bin/../conf/zoo.cfg
2015-02-23 12:57:16,883 [myid:] - INFO  [main:QuorumPeerConfig@334] - Defaulting tomajority quorums
2015-02-23 12:57:16,901 [myid:0] -INFO  [main:DatadirCleanupManager@78] -autopurge.snapRetainCount set to 3
2015-02-23 12:57:16,902 [myid:0] -INFO  [main:DatadirCleanupManager@79] -autopurge.purgeInterval set to 0
2015-02-23 12:57:16,903 [myid:0] -INFO  [main:DatadirCleanupManager@101] -Purge task is not scheduled.
2015-02-23 12:57:16,938 [myid:0] -INFO  [main:QuorumPeerMain@127] -Starting quorum peer
2015-02-23 12:57:17,176 [myid:0] -INFO  [main:NIOServerCnxnFactory@94] -binding to port 0.0.0.0/0.0.0.0:2181
2015-02-23 12:57:17,281 [myid:0] -INFO  [main:QuorumPeer@913] - tickTimeset to 2000
2015-02-23 12:57:17,282 [myid:0] -INFO  [main:QuorumPeer@933] -minSessionTimeout set to -1
2015-02-23 12:57:17,283 [myid:0] -INFO  [main:QuorumPeer@944] - maxSessionTimeoutset to -1
2015-02-23 12:57:17,284 [myid:0] -INFO  [main:QuorumPeer@959] - initLimitset to 10
2015-02-23 12:57:17,349 [myid:0] -INFO  [main:QuorumPeer@429] -currentEpoch not found! Creating with a reaso
nable default of 0. This should only happenwhen you are upgrading your installation
2015-02-23 12:57:17,362 [myid:0] -INFO  [main:QuorumPeer@444] -acceptedEpoch not found! Creating with a reas
onable default of 0. This should onlyhappen when you are upgrading your installation
2015-02-23 12:57:17,385 [myid:0] -INFO [Thread-1:QuorumCnxManager$Listener@486] - My election bind port: 0.0
.0.0/0.0.0.0:3888
2015-02-23 12:57:17,451 [myid:0] -INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:QuorumPeer@670] - LOOKING
2015-02-23 12:57:17,456 [myid:0] -INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@740] - Ne
w election. My id =  0, proposed zxid=0x0
2015-02-23 12:57:17,462 [myid:0] -INFO [WorkerReceiver[myid=0]:FastLeaderElection@542] - Notification: 0 (n.
leader), 0x0 (n.zxid), 0x1 (n.round),LOOKING (n.state), 0 (n.sid), 0x0 (n.peerEPoch), LOOKING (my state)
2015-02-23 12:57:17,504 [myid:0] -WARN [WorkerSender[myid=0]:QuorumCnxManager@368] - Cannot open channel to
1 at election addresshadoop1/192.168.1.3:3888
java.net.ConnectException: Connectionrefused
       at java.net.PlainSocketImpl.socketConnect(Native Method)
       at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
       at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
       atjava.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
       at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
       at java.net.Socket.connect(Socket.java:529)
       at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:354)
       atorg.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:327)
       atorg.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElec
tion.java:393)
        atorg.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection
.java:365)
       at java.lang.Thread.run(Thread.java:662)
2015-02-23 12:57:17,509 [myid:0] -WARN [WorkerSender[myid=0]:QuorumCnxManager@368] - Cannot open channel to
2 at election addresshadoop2/192.168.1.4:3888
java.net.ConnectException: Connectionrefused
       at java.net.PlainSocketImpl.socketConnect(Native Method)
       at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
        atjava.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
       at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
--More--(14%)


 

11.2、查看hadoop1上的zookeeper.out文件,会显示连接hadoop2错误:

 

[root@hadoop1 bin]# ls

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

 

[root@hadoop1 bin]# more zookeeper.out
2015-02-23 12:57:51,637 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading configurationfrom: /
okeeper/bin/../conf/zoo.cfg
2015-02-23 12:57:51,673 [myid:] - INFO  [main:QuorumPeerConfig@334] - Defaulting tomajority quorum
2015-02-23 12:57:51,688 [myid:1] -INFO  [main:DatadirCleanupManager@78] -autopurge.snapRetainCoun
2015-02-23 12:57:51,689 [myid:1] -INFO  [main:DatadirCleanupManager@79] -autopurge.purgeInterval
2015-02-23 12:57:51,690 [myid:1] -INFO  [main:DatadirCleanupManager@101] -Purge task is not sched
2015-02-23 12:57:51,741 [myid:1] -INFO  [main:QuorumPeerMain@127] -Starting quorum peer
2015-02-23 12:57:51,833 [myid:1] -INFO  [main:NIOServerCnxnFactory@94] -binding to port 0.0.0.0/0
2015-02-23 12:57:51,927 [myid:1] -INFO  [main:QuorumPeer@913] - tickTimeset to 2000
2015-02-23 12:57:51,928 [myid:1] -INFO  [main:QuorumPeer@933] -minSessionTimeout set to -1
2015-02-23 12:57:51,929 [myid:1] -INFO  [main:QuorumPeer@944] -maxSessionTimeout set to -1
2015-02-23 12:57:51,930 [myid:1] -INFO  [main:QuorumPeer@959] - initLimitset to 10
2015-02-23 12:57:51,978 [myid:1] -INFO  [main:QuorumPeer@429] -currentEpoch not found! Creating w
able default of 0. This should only happenwhen you are upgrading your installation
2015-02-23 12:57:51,999 [myid:1] -INFO  [main:QuorumPeer@444] -acceptedEpoch not found! Creating
nable default of 0. This should only happenwhen you are upgrading your installation
2015-02-23 12:57:52,020 [myid:1] -INFO [Thread-1:QuorumCnxManager$Listener@486] - My election bin
0.0/0.0.0.0:3888
2015-02-23 12:57:52,056 [myid:1] -INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer@670] -
2015-02-23 12:57:52,060 [myid:1] -INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElectio
 election. My id =  1, proposed zxid=0x0
2015-02-23 12:57:52,139 [myid:1] -INFO [WorkerReceiver[myid=1]:FastLeaderElection@542] - Notifica
eader), 0x0 (n.zxid), 0x1 (n.round),LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEPoch), LOOKING (my s
2015-02-23 12:57:52,152 [myid:1] -WARN [WorkerSender[myid=1]:QuorumCnxManager@368] - Cannot open
 atelection address hadoop2/192.168.1.4:3888
java.net.ConnectException: Connectionrefused
       at java.net.PlainSocketImpl.socketConnect(Native Method)
       at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
       at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
       at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
       at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
       at java.net.Socket.connect(Socket.java:529)
       atorg.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:354)
       atorg.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:327)
       atorg.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLea
derElection.java:393)
       at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderE
lection.java:365)


11.3、查看hadoop2上的zookeeper.out文件,无显示连接错误:

 

[root@hadoop2 bin]# ls

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

 

[root@hadoop2 bin]# more zookeeper.out
2015-02-23 12:58:09,146 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading config
ookeeper/bin/../conf/zoo.cfg
2015-02-23 12:58:09,173 [myid:] - INFO  [main:QuorumPeerConfig@334] - Defaulting to
2015-02-23 12:58:09,185 [myid:2] -INFO  [main:DatadirCleanupManager@78] -autopurge
2015-02-23 12:58:09,186 [myid:2] -INFO  [main:DatadirCleanupManager@79] -autopurge
2015-02-23 12:58:09,187 [myid:2] -INFO  [main:DatadirCleanupManager@101] -Purge ta
2015-02-23 12:58:09,220 [myid:2] -INFO  [main:QuorumPeerMain@127] -Starting quorum
2015-02-23 12:58:09,345 [myid:2] -INFO  [main:NIOServerCnxnFactory@94] -binding to
2015-02-23 12:58:09,460 [myid:2] -INFO  [main:QuorumPeer@913] - tickTimeset to 200
2015-02-23 12:58:09,461 [myid:2] -INFO  [main:QuorumPeer@933] -minSessionTimeout s
2015-02-23 12:58:09,464 [myid:2] -INFO  [main:QuorumPeer@944] -maxSessionTimeout s
2015-02-23 12:58:09,465 [myid:2] -INFO  [main:QuorumPeer@959] - initLimitset to 10
2015-02-23 12:58:09,517 [myid:2] -INFO  [main:QuorumPeer@429] -currentEpoch not fo
nable default of 0. This should only happenwhen you are upgrading your installation
2015-02-23 12:58:09,532 [myid:2] -INFO  [main:QuorumPeer@444] -acceptedEpoch not f
onable default of 0. This should onlyhappen when you are upgrading your installatio
2015-02-23 12:58:09,555 [myid:2] -INFO [Thread-1:QuorumCnxManager$Listener@486] -
.0.0/0.0.0.0:3888
2015-02-23 12:58:09,597 [myid:2] -INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Qu
2015-02-23 12:58:09,601 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Fa
w election. My id =  2, proposed zxid=0x0
2015-02-23 12:58:09,666 [myid:2] -INFO [WorkerReceiver[myid=2]:FastLeaderElection@
leader), 0x0 (n.zxid), 0x1 (n.round),LOOKING (n.state), 0 (n.sid), 0x0 (n.peerEPoch
2015-02-23 12:58:09,671 [myid:2] -INFO [WorkerReceiver[myid=2]:FastLeaderElection@
leader), 0x0 (n.zxid), 0x1 (n.round),FOLLOWING (n.state), 0 (n.sid), 0x0 (n.peerEPo
2015-02-23 12:58:09,673 [myid:2] -INFO [WorkerReceiver[myid=2]:FastLeaderElection@
leader), 0x0 (n.zxid), 0x1 (n.round),LOOKING (n.state), 2 (n.sid), 0x0 (n.peerEPoch
2015-02-23 12:58:09,674 [myid:2] -INFO [WorkerReceiver[myid=2]:FastLeaderElection@
leader), 0x0 (n.zxid), 0x1 (n.round),LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEPoch
2015-02-23 12:58:09,679 [myid:2] -INFO [WorkerReceiver[myid=2]:FastLeaderElection@
leader), 0x0 (n.zxid), 0x1 (n.round),LEADING (n.state), 1 (n.sid), 0x0 (n.peerEPoch
2015-02-23 12:58:09,684 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Qu
2015-02-23 12:58:09,709 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Le
t to: true
2015-02-23 12:58:09,729 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment:zookeeper.version=3.4.5-1392090,built on 09/30/2012 17:52 GMT
2015-02-23 12:58:09,730 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment:host.name=hadoop2
2015-02-23 12:58:09,731 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment:java.version=1.6.0_45
2015-02-23 12:58:09,738 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment:java.vendor=Sun Microsystems Inc.
2015-02-23 12:58:09,739 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment:java.home=/usr/local/jdk/jre
2015-02-23 12:58:09,740 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:java.class.path=/usr/local/zookeeper/bin/../buil
d/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../li
b/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/usr/l
ocal/zookeeper/bin/../lib/netty-3.2.2.Final.jar:/usr/local/zookeeper/bin/../lib/log4
j-1.2.15.jar:/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/b
in/../zookeeper-3.4.5.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/
zookeeper/bin/../conf:.:/usr/local/jdk/lib:/usr/local/jdk/jre/lib
2015-02-23 12:58:09,744 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:java.library.path=/usr/local/jdk/jre/lib/amd64/s
erver:/usr/local/jdk/jre/lib/amd64:/usr/local/jdk/jre/../lib/amd64:/usr/java/package
s/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2015-02-23 12:58:09,745 [myid:2] -INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:java.io.tmpdir=/tmp
2015-02-23 12:58:09,751 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:java.compiler=<NA>
2015-02-23 12:58:09,752 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:os.name=Linux
2015-02-23 12:58:09,753 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:os.arch=amd64
2015-02-23 12:58:09,756 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:os.version=2.6.32-431.el6.x86_64
2015-02-23 12:58:09,759 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:user.name=root
2015-02-23 12:58:09,760 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:user.home=/root
2015-02-23 12:58:09,761 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:En
vironment@100] - Serverenvironment:user.dir=/usr/local/zookeeper/bin
2015-02-23 12:58:09,769 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Zo
oKeeperServer@162] - Created server withtickTime 2000 minSessionTimeout 4000 maxSes
sionTimeout 40000 datadir/usr/local/zookeeper/data/version-2 snapdir /usr/local/zoo
keeper/data/version-2
2015-02-23 12:58:09,779 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Fo
llower@63] - FOLLOWING - LEADER ELECTIONTOOK - 178
2015-02-23 12:58:09,812 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Le
arner@325] - Getting a snapshot from leader
2015-02-23 12:58:09,825 [myid:2] -INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Fi
leTxnSnapLog@240] - Snapshotting:0x100000000 to /usr/local/zookeeper/data/version-2
/snapshot.100000000
2015-02-23 12:59:30,213 [myid:2] -INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:
NIOServerCnxnFactory@197] - Accepted socketconnection from /127.0.0.1:32999
2015-02-23 12:59:30,229 [myid:2] -INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:
NIOServerCnxn@821] - Processing srvrcommand from /127.0.0.1:32999
2015-02-23 12:59:30,239 [myid:2] -INFO  [Thread-2:NIOServerCnxn@1001] -Closed sock
et connection for client /127.0.0.1:32999(no session established for client)


错误分析:启动zookeeper要在各个主机上分别启动,我的操作hadoop0是最先启动的,此时hadoop1和hadoop2上的zookeeper还没有启动,所以显示连接hadoop1和hadoop2错误;再启动hadoop1,此时hadoop0的zookeeper已启动,所以只显示hadoop2连接失败;最后启动hadoop3上的zookeeper,其它两个都早已启动,所以无连接拒绝报错。

 

12、命令行操作zookeeper:

可以查看/usr/local/zookeeper/bin  下的文件:

[root@hadoop0 bin]# ls

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

[root@hadoop0 bin]#

 

 

12.1、执行zkCli.sh 命令:

[root@hadoop0 bin]# zkCli.sh
Connecting to localhost:2181
2015-02-23 13:09:23,109 [myid:] - INFO  [main:Environment@100] - Clientenvironment:zookeeper.version=3.4.5-1392090, built on09/30/2012 17:52 GMT
2015-02-23 13:09:23,136 [myid:] - INFO  [main:Environment@100] - Clientenvironment:host.name=hadoop0
2015-02-23 13:09:23,137 [myid:] - INFO  [main:Environment@100] - Clientenvironment:java.version=1.6.0_45
2015-02-23 13:09:23,142 [myid:] - INFO  [main:Environment@100] - Clientenvironment:java.vendor=Sun Microsystems Inc.
2015-02-23 13:09:23,143 [myid:] - INFO  [main:Environment@100] - Clientenvironment:java.home=/usr/local/jdk/jre
2015-02-23 13:09:23,144 [myid:] - INFO  [main:Environment@100] - Clientenvironment:java.class.path=/usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/bin/../lib/netty-3.2.2.Final.jar:/usr/local/zookeeper/bin/../lib/log4j-1.2.15.jar:/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/bin/../zookeeper-3.4.5.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/zookeeper/bin/../conf:.:/usr/local/jdk/lib:/usr/local/jdk/jre/lib
2015-02-23 13:09:23,145 [myid:] - INFO  [main:Environment@100] - Clientenvironment:java.library.path=/usr/local/jdk/jre/lib/amd64/server:/usr/local/jdk/jre/lib/amd64:/usr/local/jdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2015-02-23 13:09:23,147 [myid:] - INFO  [main:Environment@100] - Clientenvironment:java.io.tmpdir=/tmp
2015-02-23 13:09:23,151 [myid:] - INFO  [main:Environment@100] - Clientenvironment:java.compiler=<NA>
2015-02-23 13:09:23,152 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2015-02-23 13:09:23,153 [myid:] - INFO  [main:Environment@100] - Clientenvironment:os.arch=amd64
2015-02-23 13:09:23,155 [myid:] - INFO  [main:Environment@100] - Clientenvironment:os.version=2.6.32-431.el6.x86_64
2015-02-23 13:09:23,156 [myid:] - INFO  [main:Environment@100] - Clientenvironment:user.name=root
2015-02-23 13:09:23,157 [myid:] - INFO  [main:Environment@100] - Clientenvironment:user.home=/root
2015-02-23 13:09:23,159 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/usr/local/zookeeper/bin
2015-02-23 13:09:23,163 [myid:] - INFO  [main:ZooKeeper@438] - Initiating clientconnection, connectString=localhost:2181 sessionTimeout=30000watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@46ae506e
Welcome to ZooKeeper!
2015-02-23 13:09:23,374 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@966] - Openingsocket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt toauthenticate using SASL (无法定位登录配置)
JLine support is enabled
2015-02-23 13:09:23,419 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@849] - Socketconnection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
2015-02-23 13:09:23,665 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1207]- Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181,sessionid = 0x4bb4cc75980000, negotiated timeout = 30000
 
WATCHER::
 
WatchedEvent state:SyncConnected type:Nonepath:null
[zk: localhost:2181(CONNECTED) 0]


12.2、查看根目录:

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


有一个zookeeper节点,查看里面内容:

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


再进入查看,到头了:

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


 

12.3、创建myzk节点:

[zk: localhost:2181(CONNECTED) 4] create /zk myzk
Created /zk

查看根目录,可以看到刚才创建的节点:

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


12.4、查看节点内容:

[zk: localhost:2181(CONNECTED) 12] get /zk
myzk
cZxid = 0x100000002
ctime = Mon Feb 23 13:11:06 CST 2015
mZxid = 0x100000002
mtime = Mon Feb 23 13:11:06 CST 2015
pZxid = 0x100000002
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0


12.5、设置节点内容:

[zk: localhost:2181(CONNECTED) 13] set /zk youzk
cZxid = 0x100000002
ctime = Mon Feb 23 13:11:06 CST 2015
mZxid = 0x100000003
mtime = Mon Feb 23 13:13:08 CST 2015
pZxid = 0x100000002
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0


查看设置的节点内容:

[zk: localhost:2181(CONNECTED) 14] get /zk
youzk
cZxid = 0x100000002
ctime = Mon Feb 23 13:11:06 CST 2015
mZxid = 0x100000003
mtime = Mon Feb 23 13:13:08 CST 2015
pZxid = 0x100000002
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0


12.6、删除节点:

[zk: localhost:2181(CONNECTED) 15] delete /zk


查看根目录,刚才创建的节点已被删除:

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


 

13、忘记查看进程了,现在看一下:

查看hadoop0上的进程:

[root@hadoop0 bin]# jps
4109 Jps
3821 QuorumPeerMain
[root@hadoop0 bin]#


查看hadoop1上的进程:

[root@hadoop1 bin]# jps
3002 QuorumPeerMain
3253 Jps
[root@hadoop1 bin]#


查看hadoop2上的进程:

[root@hadoop2 bin]# jps
2903 QuorumPeerMain
3147 Jps
[root@hadoop2 bin]#


14、退出zookeeper:

在各个主机上执行命令:

 

zkService.sh stop

 

 

 

你可能感兴趣的:(轻松搭建hadoop-1.2.1集群(4)--配置Zookeeper集群)