一、zookeeper的安装

1、下载zookeeper(当然在安装zookeeper之前得先装好jdk,这里就不说了),版本自己随便选一个(后面我再说版本的问题),点击这里下载。

2、然后在usr下创建zookeeper文件夹,把下载的tar包扔进去,再解压缩。

3、之后在解压缩的根目录创建data文件夹,如下:

4、创建好之后进入data文件夹,pwd命令获取到data文件夹的绝对路径。复制data的绝对路径,返回上一级,打开conf文件夹,重命名conf文件夹下的zoo_samle.cfg为zoo.cfg,再打开编辑zoo.cfg,更改dataDir的位置为刚刚复制的data目录的绝对路径:

5、到这里就已经全部安装好了,进入解压后的根目录下面的bin目录执行:./zkServer.sh start执行开启zookeeper就可以了。

6、查看当前zookeeper运行状态 ,./zkServer.sh status

JMX enabled by default
    Using config: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
    Mode: standalone

7、连接客户端 sh zkCli.sh     断开连接 ctrl+c

Connecting to localhost:2181
2019-03-11 07:30:32,026 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2019-03-11 07:30:32,028 [myid:] - INFO [main:Environment@100] - Client environment:host.name=localhost
2019-03-11 07:30:32,028 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_71
2019-03-11 07:30:32,031 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2019-03-11 07:30:32,031 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/src/java/jdk1.7.0_71/jre
2019-03-11 07:30:32,031 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/root/zookeeper-3.4.6/bin/../build/classes:/root/zookeeper-3.4.6/bin/../build/lib/*.jar:/root/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/root/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/root/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/root/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/root/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/root/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/root/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/root/zookeeper-3.4.6/bin/../conf:.:/usr/local/src/java/jdk1.7.0_71/lib.tools.jar
2019-03-11 07:30:32,031 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/i386:/lib:/usr/lib
2019-03-11 07:30:32,031 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2019-03-11 07:30:32,031 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2019-03-11 07:30:32,033 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2019-03-11 07:30:32,033 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=i386
2019-03-11 07:30:32,033 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-431.el6.i686
2019-03-11 07:30:32,033 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2019-03-11 07:30:32,033 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2019-03-11 07:30:32,033 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/root/zookeeper-3.4.6/bin
2019-03-11 07:30:32,034 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@d5e4c7
Welcome to ZooKeeper!
2019-03-11 07:30:32,080 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2019-03-11 07:30:32,102 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@852] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
2019-03-11 07:30:32,121 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x167d21b8ff0007a, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: localhost:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
connect host:port
get path [watch]
ls path [watch]
set path data [version]
rmr path
delquota [-n|-b] path
quit
printwatches on|off
create [-s] [-e] path data acl
stat path [watch]
close
ls2 path [watch]
history
listquota path
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
setquota -n|-b val path
[zk: localhost:2181(CONNECTED) 1]

8.创建一个资源节点并查看当前目录下的资源

[zk: localhost:2181(CONNECTED) 1] create /oldservice 0
Created /oldservice
[zk: localhost:2181(CONNECTED) 2] ls /
[oldservice, dubbo, zookeeper]
[zk: localhost:2181(CONNECTED) 3] create /oldservice/wsdl 1
Created /oldservice/wsdl
[zk: localhost:2181(CONNECTED) 4] ls /
[oldservice, dubbo, zookeeper]
[zk: localhost:2181(CONNECTED) 5] ls /oldservice
[wsdl]
[zk: localhost:2181(CONNECTED) 6]

9.删除节点,必须一层一层对应删除 

[zk: localhost:2181(CONNECTED) 7] delete /oldservice/wsdl
[zk: localhost:2181(CONNECTED) 8] ls /oldservice
[]
[zk: localhost:2181(CONNECTED) 9] delete /oldservice
[zk: localhost:2181(CONNECTED) 10] ls /
[dubbo, zookeeper]
[zk: localhost:2181(CONNECTED) 11]

10.拿到节点信息 --节点特性:(节点唯一,临时节点(不能有子节点  -e),有序(-s)和无序节点)

[zk: localhost:2181(CONNECTED) 13] get /dubbo
null
cZxid = 0x2
ctime = Fri Dec 21 11:26:37 PST 2018
mZxid = 0x2
mtime = Fri Dec 21 11:26:37 PST 2018
pZxid = 0x8b2
cversion = 11
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 11

获取临时节点信息:(参数解析)

get /temp
0(节点值)
cZxid = 0x400000004(创建事务id)
ctime = Thu Mar 14 04:53:57 PDT 2019
mZxid = 0x400000004(修改、更新事务id)
mtime = Thu Mar 14 04:53:57 PDT 2019
pZxid = 0x400000004(子节点变更以后才会产生pZxid的影响)
cversion = 0(当前节点子节点的版本号)(版本号类似乐观锁的概念,通过版本号去保存数据的变化)
dataVersion = 0(数据内容的版本号)
aclVersion = 0(当前节点acl(权限控制)变化的版本号)ACL CREATE/READ/WRITE/DELETE/ADMIN
ephemeralOwner = 0x3697c0684e80000(绑定当前会话信息,此节点属于当前会话,会话关闭,改临时节点被删除)
dataLength = 1(数据长度)
numChildren = 0(当前节点下子节点个数)

watcher:

get /temp true(设置watcher监听)
0
cZxid = 0x400000004
ctime = Thu Mar 14 04:53:57 PDT 2019
mZxid = 0x400000004
mtime = Thu Mar 14 04:53:57 PDT 2019
pZxid = 0x400000004
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x3697c0684e80000
dataLength = 1
numChildren = 0
[zk: localhost:2181(CONNECTED) 6]

WATCHER::

WatchedEvent state:SyncConnected type:NodeDataChanged path:/temp

另一台机器上:

[zk: localhost:2181(CONNECTED) 11] set /temp test 对节点值进行修改

cZxid = 0x400000004
ctime = Thu Mar 14 04:53:57 PDT 2019
mZxid = 0x400000005
mtime = Thu Mar 14 05:25:04 PDT 2019
pZxid = 0x400000004
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x3697c0684e80000
dataLength = 4
numChildren = 0

可以看到上面标黄的watcher通知

集群搭建:

1、下载ZooKeeper的安装包:

  2、将下载的zookeeper-3.4.6包放到/opt目录下,目录结构如下图所示:

    3、在/tmp目录下新建一个zookeeper目录,并在zookeeper目录下新建一个data目录。

    4、三台linux系统的ip:  

server.1=192.168.25.129:2888:3888
server.2=192.168.25.130:2888:3888
server.3=192.168.25.131:2888:3888

5、安装jdk8:

  下载下来后拷贝到/usr/java目录下,然后:tar-zxvf jdk-8u112-linux-i586.tar.gz解压后目录下有一个jdk1.8.0_111文件下。然后通过vi /etc/profile命令来设置环境变量:

    export JAVA_HOME=/usr/java/jdk1.8.0_111
    export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    export PATH=$PATH:$JAVA_HOME/bin

  保存后进入cd /etc目录下,输入source profile命令使修改生效,然后java -version命令查看jdk版本信息。

 6.zoo-sample.cfg文件名统一修改为zoo.cfg

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/root/tmp/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.25.129:2888:3888
server.2=192.168.25.130:2888:3888
server.3=192.168.25.131:2888:3888

  

其中:

    initLimit=10: 对于从节点最初连接到主节点时的超时时间,单位为tick值的倍数。

    syncLimit=5:对于主节点与从节点进行同步操作时的超时时间,单位为tick值的倍数。

    dataDir=/tmp/zookeeper: 用于配置内存数据库保存的模糊快照的目录。即刚刚创建的data文件夹就是在此目录中。文件信息都存放在data目录下。

    clientPort=2181: 表示客户端所连接的服务器所监听的端口号,默认是2181。即zookeeper对外提供访问的端口号。  

      server.1=192.168.25.129:2888:3888

server.2=192.168.25.130:2888:3888

server.3=192.168.25.131:2888:3888

7、新建myid文件:

    在三个linux机器上刚刚创建的data目录下新建一个myid文件并打开,vi myid命令。

    在192.168.25.129机器上输入1,保存退出;在192.168.25.130机器上输入2,保存退出;在192.168.25.131机器上输入3,保存退出。这里的1,2,3是与server1,2,3相对应的。

8、配置环境变量:

    vi  etc/profile 在最后添加如下两个。

    export ZOOKEEPER_HOME=/opt/zookeeper-3.4.6
    export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf

    保存后进入cd /etc目录下,输入source profile命令使修改生效。

9、启动zookeeper:

    分别在3台机器上/opt/zookeeper-3.4.6/bin目录下启动;

    [root@zk1 bin]# zkServer.sh start来启动。

    zkServer.sh restart  (重启)

    zkServer.sh status  (查看状态)

    zkServer.sh stop  (关闭)

    zkServer.sh start-foreground  (以打印日志方式启动)

    当对三台机器同时 zkServer.sh start启动时,发现都启动成功了,但是以zkServer.sh status命令来查看启动状态时,发现总是在报错,查看报错信息

    报这种异常一般有三种情况:

    (1):zoo.cfg配置文件中,server.x:2888:3888配置出现错误;

    (2):myid文件内容和server.x不对应,或者myid不在data目录下;

    (3):系统防火墙是否在启动。(查看防火墙状态/etc/init.d/iptables status)iptables: Firewall is not running.则是关闭的,若未关闭,则systemctl stop firewalld

    

      修改后启动ZooKeeper集群

在ZooKeeper集群的每个结点上,执行启动ZooKeeper服务的脚本,如下所示:

  1. hadoop@slave-01:~/installation/zookeeper-3.3.4$ tail -500f zookeeper.out
  2. 2012-01-08 06:51:19,117 - INFO  [main:QuorumPeerConfig@90] - Reading configuration from: /home/hadoop/installation/zookeeper-3.3.4/bin/../conf/zoo.cfg
  3. 2012-01-08 06:51:19,133 - INFO  [main:QuorumPeerConfig@310] - Defaulting to majority quorums
  4. 2012-01-08 06:51:19,167 - INFO  [main:QuorumPeerMain@119] - Starting quorum peer
  5. 2012-01-08 06:51:19,227 - INFO  [main:NIOServerCnxn$Factory@143] - binding to port 0.0.0.0/0.0.0.0:2181
  6. 2012-01-08 06:51:19,277 - INFO  [main:QuorumPeer@819] - tickTime set to 2000
  7. 2012-01-08 06:51:19,278 - INFO  [main:QuorumPeer@830] - minSessionTimeout set to -1
  8. 2012-01-08 06:51:19,279 - INFO  [main:QuorumPeer@841] - maxSessionTimeout set to -1
  9. 2012-01-08 06:51:19,281 - INFO  [main:QuorumPeer@856] - initLimit set to 5
  10. 2012-01-08 06:51:19,347 - INFO  [Thread-1:QuorumCnxManager$Listener@473] - My election bind port: 3888
  11. 2012-01-08 06:51:19,393 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumPeer@621] - LOOKING
  12. 2012-01-08 06:51:19,396 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@663] - New election. My id =  1, Proposed zxid = 0
  13. 2012-01-08 06:51:19,400 - INFO  [WorkerReceiver Thread:FastLeaderElection@496] - Notification: 1 (n.leader), 0 (n.zxid), 1 (n.round), LOOKING (n.state), 1 (n.sid), LOOKING (my state)
  14. 2012-01-08 06:51:19,416 - WARN  [WorkerSender Thread:QuorumCnxManager@384] - Cannot open channel to 2 at election address slave-02/192.168.0.178:3888
  15. java.net.ConnectException: Connection refused
  16. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  17. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  18. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  19. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  20. at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:340)
  21. at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:360)
  22. at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:333)
  23. at java.lang.Thread.run(Thread.java:662)
  24. 2012-01-08 06:51:19,420 - WARN  [WorkerSender Thread:QuorumCnxManager@384] - Cannot open channel to 3 at election address slave-03/192.168.0.177:3888
  25. java.net.ConnectException: Connection refused
  26. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  27. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  28. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  29. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  30. at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:340)
  31. at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:360)
  32. at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:333)
  33. at java.lang.Thread.run(Thread.java:662)
  34. 2012-01-08 06:51:19,612 - WARN  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@384] - Cannot open channel to 2 at election address slave-02/192.168.0.178:3888
  35. java.net.ConnectException: Connection refused
  36. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  37. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  38. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  39. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  40. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
  41. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
  42. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
  43. 2012-01-08 06:51:19,615 - WARN  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@384] - Cannot open channel to 3 at election address slave-03/192.168.0.177:3888
  44. java.net.ConnectException: Connection refused
  45. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  46. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  47. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  48. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  49. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
  50. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
  51. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
  52. 2012-01-08 06:51:19,616 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@697] - Notification time out: 400
  53. 2012-01-08 06:51:20,019 - WARN  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@384] - Cannot open channel to 2 at election address slave-02/192.168.0.178:3888
  54. java.net.ConnectException: Connection refused
  55. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  56. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  57. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  58. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  59. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
  60. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
  61. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
  62. 2012-01-08 06:51:20,021 - WARN  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@384] - Cannot open channel to 3 at election address slave-03/192.168.0.177:3888
  63. java.net.ConnectException: Connection refused
  64. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  65. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  66. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  67. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  68. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
  69. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
  70. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
  71. 2012-01-08 06:51:20,022 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@697] - Notification time out: 800
  72. 2012-01-08 06:51:20,825 - WARN  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@384] - Cannot open channel to 2 at election address slave-02/192.168.0.178:3888
  73. java.net.ConnectException: Connection refused
  74. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  75. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  76. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  77. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  78. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
  79. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
  80. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
  81. 2012-01-08 06:51:20,827 - WARN  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@384] - Cannot open channel to 3 at election address slave-03/192.168.0.177:3888
  82. java.net.ConnectException: Connection refused
  83. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  84. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  85. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  86. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  87. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
  88. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
  89. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
  90. 2012-01-08 06:51:20,828 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@697] - Notification time out: 1600
  91. 2012-01-08 06:51:22,435 - WARN  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@384] - Cannot open channel to 2 at election address slave-02/192.168.0.178:3888
  92. java.net.ConnectException: Connection refused
  93. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  94. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  95. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  96. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  97. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
  98. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
  99. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
  100. 2012-01-08 06:51:22,439 - WARN  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@384] - Cannot open channel to 3 at election address slave-03/192.168.0.177:3888
  101. java.net.ConnectException: Connection refused
  102. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  103. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  104. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  105. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  106. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
  107. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
  108. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
  109. 2012-01-08 06:51:22,441 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@697] - Notification time out: 3200
  110. 2012-01-08 06:51:22,945 - INFO  [WorkerReceiver Thread:FastLeaderElection@496] - Notification: 2 (n.leader), 0 (n.zxid), 1 (n.round), LOOKING (n.state), 2 (n.sid), LOOKING (my state)
  111. 2012-01-08 06:51:22,946 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@721] - Updating proposal
  112. 2012-01-08 06:51:22,949 - WARN  [WorkerSender Thread:QuorumCnxManager@384] - Cannot open channel to 3 at election address slave-03/192.168.0.177:3888
  113. java.net.ConnectException: Connection refused
  114. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  115. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
  116. at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
  117. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
  118. at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:340)
  119. at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:360)
  120. at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:333)
  121. at java.lang.Thread.run(Thread.java:662)
  122. 2012-01-08 06:51:22,951 - INFO  [WorkerReceiver Thread:FastLeaderElection@496] - Notification: 2 (n.leader), 0 (n.zxid), 1 (n.round), LOOKING (n.state), 1 (n.sid), LOOKING (my state)
  123. 2012-01-08 06:51:23,156 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumPeer@643] - FOLLOWING
  124. 2012-01-08 06:51:23,170 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Learner@80] - TCP NoDelay set to: true
  125. 2012-01-08 06:51:23,206 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:zookeeper.version=3.3.3-1203054, built on 11/17/2011 05:47 GMT
  126. 2012-01-08 06:51:23,207 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:host.name=slave-01
  127. 2012-01-08 06:51:23,207 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:java.version=1.6.0_30
  128. 2012-01-08 06:51:23,208 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:java.vendor=Sun Microsystems Inc.
  129. 2012-01-08 06:51:23,208 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:java.home=/home/hadoop/installation/jdk1.6.0_30/jre
  130. 2012-01-08 06:51:23,209 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:java.class.path=/home/hadoop/installation/zookeeper-3.3.4/bin/../build/classes:/home/hadoop/installation/zookeeper-3.3.4/bin/../build/lib/*.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../zookeeper-3.3.4.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../lib/log4j-1.2.15.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../lib/jline-0.9.94.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../lib/commons-lang-2.4.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../lib/commons-collections-3.2.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../lib/commons-cli-1.1.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../lib/apache-rat-tasks-0.6.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../lib/apache-rat-core-0.6.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../src/java/lib/*.jar:/home/hadoop/installation/zookeeper-3.3.4/bin/../conf:/home/hadoop/installation/jdk1.6.0_30/lib/*.jar:/home/hadoop/installation/jdk1.6.0_30/jre/lib/*.jar
  131. 2012-01-08 06:51:23,210 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:java.library.path=/home/hadoop/installation/jdk1.6.0_30/jre/lib/i386/client:/home/hadoop/installation/jdk1.6.0_30/jre/lib/i386:/home/hadoop/installation/jdk1.6.0_30/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
  132. 2012-01-08 06:51:23,210 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:java.io.tmpdir=/tmp
  133. 2012-01-08 06:51:23,212 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:java.compiler=<NA>
  134. 2012-01-08 06:51:23,212 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:os.name=Linux
  135. 2012-01-08 06:51:23,212 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:os.arch=i386
  136. 2012-01-08 06:51:23,213 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:os.version=3.0.0-14-generic
  137. 2012-01-08 06:51:23,213 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:user.name=hadoop
  138. 2012-01-08 06:51:23,214 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:user.home=/home/hadoop
  139. 2012-01-08 06:51:23,214 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Environment@97] - Server environment:user.dir=/home/hadoop/installation/zookeeper-3.3.4
  140. 2012-01-08 06:51:23,223 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:ZooKeeperServer@151] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir /home/hadoop/storage/zookeeper/version-2 snapdir /home/hadoop/storage/zookeeper/version-2
  141. 2012-01-08 06:51:23,339 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Learner@294] - Getting a snapshot from leader
  142. 2012-01-08 06:51:23,358 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Learner@325] - Setting leader epoch 1
  143. 2012-01-08 06:51:23,358 - INFO  [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FileTxnSnapLog@254] - Snapshotting: 0
  144. 2012-01-08 06:51:25,511 - INFO  [WorkerReceiver Thread:FastLeaderElection@496] - Notification: 3 (n.leader), 0 (n.zxid), 1 (n.round), LOOKING (n.state), 3 (n.sid), FOLLOWING (my state)
  145. 2012-01-08 06:51:42,584 - INFO  [WorkerReceiver Thread:FastLeaderElection@496] - Notification: 3 (n.leader), 0 (n.zxid), 2 (n.round), LOOKING (n.state), 3 (n.sid), FOLLOWING (my state)

我启动的顺序是slave-01>slave-02>slave-03,由于ZooKeeper集群启动的时候,每个结点都试图去连接集群中的其它结点,先启动的肯定连不上后面还没启动的,所以上面日志前面部分的异常是可以忽略的。通过后面部分可以看到,集群在选出一个Leader后,最后稳定了。

其他结点可能也出现类似问题,属于正常。

10、连接到ZooKeeper:

    在命令行中输入:zkCli.sh -server 192.168.25.129:2181,即可连接到其中一台ZooKeeper服务器。其他自动实现同步,客户端只需要和一台保持连接即可。

11.创建zNode节点:

    连接成功后,在屏幕上输入: create  /hello  helloworld即可在主节点上创建一个新的zNode节点。zNode节点名称hello  ,数据helloworld,产看其他节点上同步的数据。

zookeeper(1)初识zookeeper的更多相关文章

  1. zookeeper篇-初识zookeeper

    点赞再看,养成习惯,微信搜索「小大白日志」关注这个搬砖人. 文章不定期同步公众号,还有各种一线大厂面试原题.我的学习系列笔记. 什么是zookeeper? 中间件 作用于分布式系统 支持java.c语 ...

  2. 【Zookeeper】初识zookeeper

    单机模式 安装并解压: 修改配置文件,conf/zoo.cfg(配置完成后,启动后,可以通过netstat-ano命令查看是否有你配置的clientPort端口号在监听服务) tickTime: zo ...

  3. 初识zookeeper(1)之zookeeper的安装及配置

    初识zookeeper(一)之zookeeper的安装及配置 1.简要介绍 zookeeper是一个分布式的应用程序协调服务,是Hadoop和Hbase的重要组件,是一个树型的目录服务,支持变更推送. ...

  4. 初识zookeeper以及安装和集群部署

    初识zookeeper以及安装和集群部署     一.Zookeeper单体版安装     在安装zookeeper之前要先安装jdk环境,具体在linux环境安装jdk1.8请参照linux笔记. ...

  5. 初识ZooKeeper

    最近在看Apache下的一个开源项目ZooKeeper(http://zookeeper.apache.org/doc/trunk/),用百度百科介绍的来说,Zookeeper是一个针对大型分布式系统 ...

  6. Zookeeper笔记(一)初识Zookeeper

    为什么需要Zookeeper Zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用程序可以基于它实现诸如数据发布/订阅.负载均衡.命名服务.分布式协调/通知.集群管理.Master选举 ...

  7. 初识ZooKeeper与集群搭建实例

    原文链接:http://www.linuxidc.com/Linux/2015-02/114230.htm zookeeper是什么 Zookeeper,一种分布式应用的协作服务,是Google的Ch ...

  8. 读<分布式一致性原理>初识zookeeper

    zookeeper是什么 zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用程序可以基于它实现诸如:数据发布/订阅,负载均衡,命名服务,分布式协调/通知 ,集群管理,Master选举 ...

  9. 初识 Zookeeper

    云计算越来越流行的今天,单一机器处理能力已经不能满足我们的需求,不得不采用大量的服务集群.服务集群对外提供服务的过程中,有很多的配置需要随时更新,服务间需要协调工作,这些信息如何推送到各个节点?并且保 ...

  10. 1. 初识ZooKeeper。

    转自:https://blog.csdn.net/en_joker/article/details/78661466 Apache ZooKeeper是由 Apache Hadoop的子项目发展而来, ...

随机推荐

  1. 【转】C# 开发Chrome内核浏览器(WebKit.net)

    WebKit.net是对WebKit的.Net封装,使用它.net程序可以非常方便的集成和使用webkit作为加载网页的容器.这里介绍一下怎么用它来显示一个网页这样的一个最简单的功能. 第一步: 下载 ...

  2. ALGO-123_蓝桥杯_算法训练_A+B problem

    问题描述 Given two integers A and B, your task is to output their sum, A+B. 输入格式 The input contains of o ...

  3. 【git】之使用eclipse-git插件查看本地文件和远程文件区别

    选中文件右键 Team->Show Local History 在历史中右键 Compare Current with Local

  4. Hadoop概念学习系列之Hadoop新手学习指导之入门需知(二十)

    不多说,直接上干货! 零基础学习hadoop,没有想象的那么困难,也没有想象的那么容易.从一开始什么都不懂,到能够搭建集群,开发.整个过程,只要有Linux基础,虚拟机化和java基础,其实hadoo ...

  5. BIO & NIO & NIO常见框架

    BIO & NIO BIO - Blocking IO - 同步式阻塞式IO --- UDP/TCP NIO - New  IO - 同步式非阻塞式IO AIO  - Asynchronous ...

  6. 微服务之分布式跟踪系统(springboot+zipkin+mysql)

    通过上一节<微服务之分布式跟踪系统(springboot+zipkin)>我们简单熟悉了zipkin的使用,但是收集的数据都保存在内存中重启后数据丢失,不过zipkin的Storage除了 ...

  7. flume-拦截器、channel选择器、sink组合sink处理器

    1. Flume Interceptors Flume有能力修改/删除流程中的events.这是在拦截器(interceptor)的帮助下完成的.拦截器(Interceptors)是实现org.apa ...

  8. Java学习——this、this()、super 和 super()的使用

    编写程序:说明 this.super 和 super()的用法.程序首先定义 Point(点)类,然后创建点的子类 Line(线)),最后通过 LX7_3 类输出线段的长度. package Pack ...

  9. centos6.5虚拟机快照技术

    一.查看现有磁盘镜像格式与转换 查看磁盘格式 [root@localhost ~]# qemu-img info /var/lib/libvirt/images/centos7.img image: ...

  10. centos7+apache+svn配置 踩坑,注意权限问题。apache应用目录checkout应用 必须用这个命令:svn co file:///home/svn/test/ test ,通过svn add * &&commit 及任意修改都是不行的

    阅读帮助 命令提示符 [root@server-002 ~]# 表示当前服务root用户执行的命令 [svn@server-002 ~]$ 表示普通用户svn执行的命令 [root@localhost ...