前面一样的我就不写了,请先看这里zookeeper伪分布配置
1.接着那篇,修改drguo3的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=/opt/zookeeper-3.4.8/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.80.153:2888:3888
server.2=0.0.0.0:2888:3888
server.3=192.168.80.152:2888:3888
drguo3对应ip192.168.80.151
drguo4对应ip192.168.80.152
drguo5对应ip192.168.80.153
你可能会问,为什么不按顺序写,因为我想让drguo3成为leader~
你可能还会问,为什么写0.0.0.0,因为之前这样写的
server.1=drguo5:2888:3888
server.2=drguo3:2888:3888
server.3=drguo4:2888:3888
查看状态时
guo@drguo4:~$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
查看日志发现
2016-03-24 21:22:18,937 [myid:2] - WARN [WorkerSender[myid=2]:QuorumCnxManager@400] - Cannot open channel to 3 at election address /192.168.80.152:3888
java.net.ConnectException: 拒绝连接
然后我搜到了这个:http://stackoverflow.com/questions/30940981/zookeeper-error-cannot-open-channel-to-x-at-election-address
贴一下吧:
This is what worked for me
Step 1: Node 1: zoo.cfg server.1= 0.0.0.0:<port>:<port2> server.2= <IP>:<port>:<port2> . . . server.n= <IP>:<port>:<port2> Node 2 : server.1= <IP>:<port>:<port2> server.2= 0.0.0.0:<port>:<port2> . . . server.n= <IP>:<port>:<port2> Now in location defined by datadir on your zoo.cfg Node 1: echo 1 > <datadir>/id Node 2: echo 2 > <datadir>/id . . . Node n: echo n > <datadir>/id
This one helped me to start zoo keeper successfully but will know more once i start playing with it. Hope this helps.
他说的已经很明白了,drguo4和drguo5也修改一下zoo.cfg文件,然后建data目录,再在里面建一个myid文件,myid里输入对应的id,就是下面的server.后面的数
server.1=drguo5:2888:3888
server.2=drguo3:2888:3888
server.3=drguo4:2888:3888
2.我还是来一遍吧,以drguo3为例
建data文件夹
guo@drguo3:~$ cd /opt/zookeeper-3.4.8/
guo@drguo3:/opt/zookeeper-3.4.8$ mkdir data
建myid文件,并输入2
guo@drguo3:~$ echo 2 > myid
将zookeeper整个文件夹复制给drguo4和drguo5
guo@drguo3:~$ scp -r zookeeper-3.4.8/ drguo4:/opt/
guo@drguo3:~$ scp -r zookeeper-3.4.8/ drguo5:/opt/
注意:opt目录默认是属于root用户/组的,因为我是自己用的,所以直接把opt目录所属者全换成了我的普通用户/组,再公司里这么干肯定不行,你可以把zookeeper目录放到你所用用户的家目录下。
复制完之后,把drguo4/5的myid内容改成对应的ip。
3.启动zookeeper(3个都要手动启动)
guo@drguo3:~$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
guo@drguo3:~$ jps
2005 Jps
1994 QuorumPeerMain
guo@drguo3:~$ ssh drguo4
Welcome to Ubuntu 15.10 (GNU/Linux 4.2.0-16-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Fri Mar 25 14:04:43 2016 from 192.168.80.151
guo@drguo4:~$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
guo@drguo4:~$ jps
1977 Jps
1966 QuorumPeerMain
guo@drguo4:~$ exit
注销
Connection to drguo4 closed.
guo@drguo3:~$ ssh drguo5
Welcome to Ubuntu 15.10 (GNU/Linux 4.2.0-16-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Fri Mar 25 14:04:56 2016 from 192.168.80.151
guo@drguo5:~$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
guo@drguo5:~$ jps
2041 Jps
2030 QuorumPeerMain
guo@drguo5:~$ exit
注销
Connection to drguo5 closed.
4.三个全部启动之后!查看状态
guo@drguo3:~$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
Mode: leader
drguo3果然是leader
吧 = =
ps:leader是选举产生的,只有一个leader,其余都是follower,所以zookeeper集群要搭奇数个。