用vmware拷贝出三个相同的ubuntu搭建小的zookeeper集群

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用vmware拷贝出三个相同的ubuntu搭建小的zookeeper集群相关的知识,希望对你有一定的参考价值。

第一次配置zookeeper的集群

因为想运行storm必须搭建集群
在自己的电脑上拷贝了自己的ubuntu虚拟机
采用的是vmware给虚拟机分配的地址
三个机器的配置基本上一样除了myid这个文件
看了这么久的一致,选举什么的也想试试这个过程的感觉

首先下载安装一个ubuntu
安装配置好jdk

下载zookeeper然后添加到~/.bashrc里面

1 source ~/.bashrc
2 使得文件配置生效
3 echo $PATH
4 查看路径中有没有java和zookeeper需要的可执行文件的路径

 

 1 修改zookeeper的配置文件
 2 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/conf$ ls
 3 configuration.xsl  log4j.properties  zoo.cfg  zoo.cfg~
 4 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/conf$ cat zoo.cfg
 5 # The number of milliseconds of each tick
 6 tickTime=2000
 7 # The number of ticks that the initial 
 8 # synchronization phase can take
 9 initLimit=10
10 # The number of ticks that can pass between 
11 # sending a request and getting an acknowledgement
12 syncLimit=5
13 # the directory where the snapshot is stored.
14 # do not use /tmp for storage, /tmp here is just 
15 # example sakes.
16 dataDir=/home/jason/StormProcessing/data
17 dataLogDir=/home/jason/StormProcessing/log
18 # the port at which the clients will connect
19 clientPort=2181
20 # the maximum number of client connections.
21 # increase this if you need to handle more clients
22 #maxClientCnxns=60
23 #
24 # Be sure to read the maintenance section of the 
25 # administrator guide before turning on autopurge.
26 #
27 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
28 #
29 # The number of snapshots to retain in dataDir
30 #autopurge.snapRetainCount=3
31 # Purge task interval in hours
32 # Set to "0" to disable auto purge feature
33 #autopurge.purgeInterval=1
34 
35 #其中2888表示这个服务器和集群中的leader交换信息的端口
36 #3888表示万一集群中的leader挂了,找到一个新的leader使用的通信端口
37 #在真正的集群中,几个服务器使用的端口是一样的,但是在伪集群方式中端口不能一样
38 server.1=192.168.60.129:2888:3888
39 server.2=192.168.60.132:2888:3888
40 server.3=192.168.60.133:2888:3888
41 #server.2=127.0.0.1:2889:3889

 

1 新建一下 
2 dataDir=/home/jason/StormProcessing/data
3 dataLogDir=/home/jason/StormProcessing/log
4 这两个文件夹

 

在data文件夹下面新建一个文本文件myid里面就写一个1

拷贝磁盘,做成单个虚拟机,分别改其中的myid为2,3,注意ip之间的对应

 

 1 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/bin$ ./zkServer.sh start
 2 ZooKeeper JMX enabled by default
 3 Using config: /home/jason/StormProcessing/zookeeper-3.4.8/bin/../conf/zoo.cfg
 4 Starting zookeeper ... STARTED
 5 分别启动三个虚拟机
 6 然后随便查看一个得到下面的结果:
 7 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/bin$ ./zkServer.sh status
 8 ZooKeeper JMX enabled by default
 9 Using config: /home/jason/StormProcessing/zookeeper-3.4.8/bin/../conf/zoo.cfg
10 Error contacting service. It is probably not running.

 

1 运行这个
2 netstat -an |grep 2181
3 得到空

 

查google有很多可能
第一是没新建data或者log文件夹,我没这问题
第二是配置文件错误,我也没问题
第三是启动脚本zkServer.sh中重复定义端口号,我也没问题(没动这个文件)

 

1 查看自己的下面这个文件
2 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/bin$ cat zookeeper.out 
3 nohup: 无法运行命令"/home/jason/StormProcessing/jdk1.8/bin/java": 权限不够

 

找到原因了
chmod 755 java
也不行

1 受到参考文献2的启发用下面的后两个代替前两个就出现了正常的结果
2 ./zkServer.sh start
3 ./zkServer.sh status
4 sudo ./zkServer.sh start
5 sudo ./zkServer.sh status

 

 1 下面是server.1
 2 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/bin$ sudo ./zkServer.sh status
 3 ZooKeeper JMX enabled by default
 4 Using config: /home/jason/StormProcessing/zookeeper-3.4.8/bin/../conf/zoo.cfg
 5 Mode: follower
 6 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/bin$ netstat -an |grep 2181
 7 tcp6       0      0 :::2181                 :::*                    LISTEN     
 8 server.2
 9 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/bin$ sudo ./zkServer.sh status
10 ZooKeeper JMX enabled by default
11 Using config: /home/jason/StormProcessing/zookeeper-3.4.8/bin/../conf/zoo.cfg
12 Mode: follower
13 server.3
14 jason@ubuntu:~/StormProcessing/zookeeper-3.4.8/bin$ sudo ./zkServer.sh status
15 ZooKeeper JMX enabled by default
16 Using config: /home/jason/StormProcessing/zookeeper-3.4.8/bin/../conf/zoo.cfg
17 Mode: leader

 

下面是新的成功的  zookeeper.out

 1 ason@ubuntu:~/StormProcessing/zookeeper-3.4.8/bin$ sudo cat zookeeper.out 
 2 2016-05-25 13:21:29,768 [myid:] - INFO  [main:QuorumPeerConfig@103] - Reading configuration from: /home/jason/StormProcessing/zookeeper-3.4.8/bin/../conf/zoo.cfg
 3 2016-05-25 13:21:29,817 [myid:] - INFO  [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.60.133 to address: /192.168.60.133
 4 2016-05-25 13:21:29,817 [myid:] - INFO  [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.60.132 to address: /192.168.60.132
 5 2016-05-25 13:21:29,818 [myid:] - INFO  [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.60.129 to address: /192.168.60.129
 6 2016-05-25 13:21:29,818 [myid:] - INFO  [main:QuorumPeerConfig@331] - Defaulting to majority quorums
 7 2016-05-25 13:21:29,832 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
 8 2016-05-25 13:21:29,832 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
 9 2016-05-25 13:21:29,832 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
10 2016-05-25 13:21:29,845 [myid:1] - INFO  [main:QuorumPeerMain@127] - Starting quorum peer
11 2016-05-25 13:21:29,970 [myid:1] - INFO  [main:NioserverCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181
12 2016-05-25 13:21:29,993 [myid:1] - INFO  [main:QuorumPeer@1019] - tickTime set to 2000
13 2016-05-25 13:21:29,993 [myid:1] - INFO  [main:QuorumPeer@1039] - minSessionTimeout set to -1
14 2016-05-25 13:21:29,993 [myid:1] - INFO  [main:QuorumPeer@1050] - maxSessionTimeout set to -1
15 2016-05-25 13:21:29,993 [myid:1] - INFO  [main:QuorumPeer@1065] - initLimit set to 10
16 2016-05-25 13:21:30,026 [myid:1] - INFO  [main:QuorumPeer@533] - currentEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation
17 2016-05-25 13:21:30,031 [myid:1] - INFO  [main:QuorumPeer@548] - acceptedEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation
18 2016-05-25 13:21:30,043 [myid:1] - INFO  [ListenerThread:QuorumCnxManager$Listener@534] - My election bind port: /192.168.60.129:3888
19 2016-05-25 13:21:30,056 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer@774] - LOOKING
20 2016-05-25 13:21:30,057 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@818] - New election. My id =  1, proposed zxid=0x0
21 2016-05-25 13:21:30,061 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 1 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
22 2016-05-25 13:21:30,062 [myid:1] - INFO  [WorkerSender[myid=1]:QuorumCnxManager@199] - Have smaller server identifier, so dropping the connection: (2, 1)
23 2016-05-25 13:21:30,064 [myid:1] - INFO  [WorkerSender[myid=1]:QuorumCnxManager@199] - Have smaller server identifier, so dropping the connection: (3, 1)
24 2016-05-25 13:21:30,097 [myid:1] - INFO  [/192.168.60.129:3888:QuorumCnxManager$Listener@541] - Received connection request /192.168.60.132:59080
25 2016-05-25 13:21:30,101 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 2 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
26 2016-05-25 13:21:30,102 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
27 2016-05-25 13:21:30,103 [myid:1] - INFO  [WorkerSender[myid=1]:QuorumCnxManager@199] - Have smaller server identifier, so dropping the connection: (3, 1)
28 2016-05-25 13:21:30,104 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), FOLLOWING (n.state), 2 (n.sid), 0x1 (n.peerEpoch) LOOKING (my state)
29 2016-05-25 13:21:30,104 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), FOLLOWING (n.state), 2 (n.sid), 0x1 (n.peerEpoch) LOOKING (my state)
30 2016-05-25 13:21:30,120 [myid:1] - INFO  [/192.168.60.129:3888:QuorumCnxManager$Listener@541] - Received connection request /192.168.60.133:55452
31 2016-05-25 13:21:30,122 [myid:1] - INFO  [/192.168.60.129:3888:QuorumCnxManager$Listener@541] - Received connection request /192.168.60.133:55453
32 2016-05-25 13:21:30,123 [myid:1] - WARN  [RecvWorker:3:QuorumCnxManager$RecvWorker@810] - Connection broken for id 3, my id = 1, error = 
33 java.io.EOFException
34     at java.io.DataInputStream.readInt(DataInputStream.java:392)
35     at org.apache.zookeeper.server.quorum.QuorumCnxManager$RecvWorker.run(QuorumCnxManager.java:795)
36 2016-05-25 13:21:30,152 [myid:1] - WARN  [RecvWorker:3:QuorumCnxManager$RecvWorker@813] - Interrupting SendWorker
37 2016-05-25 13:21:30,150 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 3 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
38 2016-05-25 13:21:30,152 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LEADING (n.state), 3 (n.sid), 0x1 (n.peerEpoch) LOOKING (my state)
39 2016-05-25 13:21:30,152 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer@844] - FOLLOWING
40 2016-05-25 13:21:30,149 [myid:1] - WARN  [SendWorker:3:QuorumCnxManager$SendWorker@727] - Interrupted while waiting for message on queue
41 java.lang.InterruptedException
42     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
43     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2095)
44     at java.util.concurrent.ArrayBlockingQueue.poll(ArrayBlockingQueue.java:389)
45     at org.apache.zookeeper.server.quorum.QuorumCnxManager.pollSendQueue(QuorumCnxManager.java:879)
46     at org.apache.zookeeper.server.quorum.QuorumCnxManager.access$500(QuorumCnxManager.java:65)
47     at org.apache.zookeeper.server.quorum.QuorumCnxManager$SendWorker.run(QuorumCnxManager.java:715)
48 2016-05-25 13:21:30,153 [myid:1] - WARN  [SendWorker:3:QuorumCnxManager$SendWorker@736] - Send worker leaving thread
49 2016-05-25 13:21:30,157 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Learner@86] - TCP NoDelay set to: true
50 2016-05-25 13:21:30,166 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT
51 2016-05-25 13:21:30,166 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:host.name=ubuntu
52 2016-05-25 13:21:30,166 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.version=1.7.0_95
53 2016-05-25 13:21:30,166 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.vendor=Oracle Corporation
54 2016-05-25 13:21:30,166 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.home=/usr/lib/jvm/java-7-openjdk-i386/jre
55 2016-05-25 13:21:30,166 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.class.path=/home/jason/StormProcessing/zookeeper-3.4.8/bin/../build/classes:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../build/lib/*.jar:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../lib/slf4j-api-1.6.1.jar:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../lib/netty-3.7.0.Final.jar:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../lib/log4j-1.2.16.jar:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../lib/jline-0.9.94.jar:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../zookeeper-3.4.8.jar:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../src/java/lib/*.jar:/home/jason/StormProcessing/zookeeper-3.4.8/bin/../conf:
56 2016-05-25 13:21:30,166 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.library.path=/usr/java/packages/lib/i386:/usr/lib/i386-linux-gnu/jni:/lib/i386-linux-gnu:/usr/lib/i386-linux-gnu:/usr/lib/jni:/lib:/usr/lib
57 2016-05-25 13:21:30,167 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.io.tmpdir=/tmp
58 2016-05-25 13:21:30,167 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.compiler=<NA>
59 2016-05-25 13:21:30,167 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.name=Linux
60 2016-05-25 13:21:30,167 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.arch=i386
61 2016-05-25 13:21:30,167 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.version=3.16.0-67-generic
62 2016-05-25 13:21:30,167 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.name=root
63 2016-05-25 13:21:30,167 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.home=/root
64 2016-05-25 13:21:30,167 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.dir=/home/jason/StormProcessing/zookeeper-3.4.8/bin
65 2016-05-25 13:21:30,169 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:ZooKeeperServer@170] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir /home/jason/StormProcessing/log/version-2 snapdir /home/jason/StormProcessing/data/version-2
66 2016-05-25 13:21:30,169 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Follower@63] - FOLLOWING - LEADER ELECTION TOOK - 112
67 2016-05-25 13:21:30,171 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.60.133 to address: /192.168.60.133
68 2016-05-25 13:21:30,178 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Learner@329] - Getting a snapshot from leader
69 2016-05-25 13:21:30,183 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FileTxnSnapLog@240] - Snapshotting: 0x100000000 to /home/jason/StormProcessing/data/version-2/

以上是关于用vmware拷贝出三个相同的ubuntu搭建小的zookeeper集群的主要内容,如果未能解决你的问题,请参考以下文章

VMware Ubuntu 共享文件夹

安装Vmware并创建Ubuntu虚拟机

转载VMware下的Ubuntu用ifconfig不能显示ip地址的解决方案

ubuntu 无法为移动硬盘拷贝文件?

错误记录VMware 虚拟机报错 ( 向 VMWare 虚拟机中的 Ubuntu 系统拷贝文件时磁盘空间不足 )

Git版本控制之ubuntu搭建Git服务器