zookeeper(1)初识zookeeper
一、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服务的脚本,如下所示:
- hadoop@slave-01:~/installation/zookeeper-3.3.4$ tail -500f zookeeper.out
- 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
- 2012-01-08 06:51:19,133 - INFO [main:QuorumPeerConfig@310] - Defaulting to majority quorums
- 2012-01-08 06:51:19,167 - INFO [main:QuorumPeerMain@119] - Starting quorum peer
- 2012-01-08 06:51:19,227 - INFO [main:NIOServerCnxn$Factory@143] - binding to port 0.0.0.0/0.0.0.0:2181
- 2012-01-08 06:51:19,277 - INFO [main:QuorumPeer@819] - tickTime set to 2000
- 2012-01-08 06:51:19,278 - INFO [main:QuorumPeer@830] - minSessionTimeout set to -1
- 2012-01-08 06:51:19,279 - INFO [main:QuorumPeer@841] - maxSessionTimeout set to -1
- 2012-01-08 06:51:19,281 - INFO [main:QuorumPeer@856] - initLimit set to 5
- 2012-01-08 06:51:19,347 - INFO [Thread-1:QuorumCnxManager$Listener@473] - My election bind port: 3888
- 2012-01-08 06:51:19,393 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumPeer@621] - LOOKING
- 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
- 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)
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:340)
- at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:360)
- at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:333)
- at java.lang.Thread.run(Thread.java:662)
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:340)
- at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:360)
- at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:333)
- at java.lang.Thread.run(Thread.java:662)
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
- at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
- at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
- at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
- at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
- 2012-01-08 06:51:19,616 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@697] - Notification time out: 400
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
- at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
- at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
- at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
- at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
- 2012-01-08 06:51:20,022 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@697] - Notification time out: 800
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
- at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
- at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
- at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
- at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
- 2012-01-08 06:51:20,828 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@697] - Notification time out: 1600
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
- at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
- at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:404)
- at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:688)
- at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:622)
- 2012-01-08 06:51:22,441 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@697] - Notification time out: 3200
- 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)
- 2012-01-08 06:51:22,946 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FastLeaderElection@721] - Updating proposal
- 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
- java.net.ConnectException: Connection refused
- at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
- at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
- at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:100)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:371)
- at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:340)
- at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:360)
- at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:333)
- at java.lang.Thread.run(Thread.java:662)
- 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)
- 2012-01-08 06:51:23,156 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:QuorumPeer@643] - FOLLOWING
- 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
- 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
- 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
- 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
- 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.
- 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
- 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
- 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
- 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
- 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>
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 2012-01-08 06:51:23,358 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:Learner@325] - Setting leader epoch 1
- 2012-01-08 06:51:23,358 - INFO [QuorumPeer:/0:0:0:0:0:0:0:0:2181:FileTxnSnapLog@254] - Snapshotting: 0
- 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)
- 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的更多相关文章
- zookeeper篇-初识zookeeper
点赞再看,养成习惯,微信搜索「小大白日志」关注这个搬砖人. 文章不定期同步公众号,还有各种一线大厂面试原题.我的学习系列笔记. 什么是zookeeper? 中间件 作用于分布式系统 支持java.c语 ...
- 【Zookeeper】初识zookeeper
单机模式 安装并解压: 修改配置文件,conf/zoo.cfg(配置完成后,启动后,可以通过netstat-ano命令查看是否有你配置的clientPort端口号在监听服务) tickTime: zo ...
- 初识zookeeper(1)之zookeeper的安装及配置
初识zookeeper(一)之zookeeper的安装及配置 1.简要介绍 zookeeper是一个分布式的应用程序协调服务,是Hadoop和Hbase的重要组件,是一个树型的目录服务,支持变更推送. ...
- 初识zookeeper以及安装和集群部署
初识zookeeper以及安装和集群部署 一.Zookeeper单体版安装 在安装zookeeper之前要先安装jdk环境,具体在linux环境安装jdk1.8请参照linux笔记. ...
- 初识ZooKeeper
最近在看Apache下的一个开源项目ZooKeeper(http://zookeeper.apache.org/doc/trunk/),用百度百科介绍的来说,Zookeeper是一个针对大型分布式系统 ...
- Zookeeper笔记(一)初识Zookeeper
为什么需要Zookeeper Zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用程序可以基于它实现诸如数据发布/订阅.负载均衡.命名服务.分布式协调/通知.集群管理.Master选举 ...
- 初识ZooKeeper与集群搭建实例
原文链接:http://www.linuxidc.com/Linux/2015-02/114230.htm zookeeper是什么 Zookeeper,一种分布式应用的协作服务,是Google的Ch ...
- 读<分布式一致性原理>初识zookeeper
zookeeper是什么 zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用程序可以基于它实现诸如:数据发布/订阅,负载均衡,命名服务,分布式协调/通知 ,集群管理,Master选举 ...
- 初识 Zookeeper
云计算越来越流行的今天,单一机器处理能力已经不能满足我们的需求,不得不采用大量的服务集群.服务集群对外提供服务的过程中,有很多的配置需要随时更新,服务间需要协调工作,这些信息如何推送到各个节点?并且保 ...
- 1. 初识ZooKeeper。
转自:https://blog.csdn.net/en_joker/article/details/78661466 Apache ZooKeeper是由 Apache Hadoop的子项目发展而来, ...
随机推荐
- 构建Jenkins自动化编译管理环境
今天研究了一下Jenkins,有了一个粗浅的认识,顺手把构建的过程说一下,后续慢慢补充: (1)Secure CRT 连接到Linux服务器 要注意的一点是,要搞好一个文件传输的路子,否则不好传东西. ...
- 两种方式:mysql查看正在执行的sql语句
mysql查看正在执行的sql语句 2015年08月21日 17:32:59 阅读数:15398 有2个方法: 1.使用processlist,但是有个弊端,就是只能查看正在执行的sql语句,对应 ...
- 关于在项目中使用spring data redis与jedis的选择
项目中需要用到redis,主要用来作为缓存,redis的客户端有两种实现方式,一是可以直接调用jedis来实现,二是可以使用spring data redis,通过spring的封装来调用. 应该使用 ...
- maven打包时跳过测试
本文转载自:https://blog.csdn.net/thc1987/article/details/42458895 运行mvn install时跳过Test 方法一: <project&g ...
- react基础
上一篇文章主要是记录了自己是如何创建react项目的,今天则主要是总结一下react中的一个基础入门知识,包括数据定义和绑定.属性绑定.数组循环等等. 组件继承和挂载 当我们使用脚手架或者命令行创建一 ...
- 滚动效果marquee的用户体验不好,很少被用到,一般用jquery替代
滚动效果marquee的用户体验不好,很少被用到,一般用jquery替代
- [UE4]UE4是单线程的吗?
并行与串行 并行是同时在执行,串行是一个接一个地执行 进程与线程 笼统的说,进程是游戏的一次运行,线程是进程里面分配CPU资源的最小单位 类比 1.把世界看成一台计算机 2.世界里面的人可以看成是一个 ...
- typescript接口扩展、接口的继承
//接口扩展:接口可以继承接口 // interface Animal{ // eat():void; // } // interface Person extends Animal{ // work ...
- vue808
自定义键盘信息: Vue.directive('on').keyCodes.ctrl=17; Vue.directive('on').keyCodes.myenter=13; 数据深度监听 ...
- Select模式和超时
fd_set rset; FD_ZERO(&rset); int nready; int maxfd; int fd_stdin = fileno(stdin); if(fd_stdin &g ...