一脸懵逼搭建Zookeeper分布式集群

1:首先将http://zookeeper.apache.org/下载好的zookeeper-3.4.5.tar.gz上传到三台虚拟机上,之前博客搭建好的。

2:然后对zookeeper-3.4.5.tar.gz进行解压缩操作:

[hadoop@master ~]$ tar -zxvf zookeeper-3.4.5.tar.gz


3:然后进入cond目录(将zoo_sample.cfg修改为zoo.cfg):

4:然后打开zoo.cfg文件:

 修改一些配置:

tickTime=2000 心跳间隔
initLimit=10 初始容忍的心跳数
syncLimit=5 等待最大容忍的心跳数
dataDir=/tmp/zookeeper 本地保存数据的目录
clientPort=2181 客户端默认端口号

修改后的如下所示(红色圈起来的是修改的):

 5:由于需要事先创建好data目录,所以现在创建data目录:

然后在data目录创建一个文件myid,里面写一个1,如下所示:

 5:然后将修改好的复制到slaver1和slaver2上面

 然后分别将slaver1和slaver2的myid修改为2和3,如下所示:

 6:至此Zookeeper搭建结束,下面开始启动Zookeeper,分别启动:

 少于三台不会正常工作的,可以通过命令查询状态:

 7:接下来启动slaver1和slaver2的服务:

三台机器启动完成以后,可以查看其状态,开始报这个错,就是启动不了Zookeeper,然后百度呗,百度很多方法,还存在版本问题,新生事物永远在争议中成长,name百度的也没帮助我解决,最后重启三台机器,问题解决:

1 JMX enabled by default
2 Using config: /home/hadoop/zookeeper-3.4.5/bin/../conf/zoo.cfg
3 Error contacting service. It is probably not running.

上面的是master节点的,下面的是slaver1节点和slaver2节点的(对于出现这个启动不了的问题,我是这样想的,如果百度的方法不行,就重启一下

重启以后我开始启动master节点的,然后查看状态,肯定没启动起来,正常,查看一下进程jps,

然后启动slaver1节点的,然后查看状态,肯定没启动起来,正常,查看一下进程jps

然后启动slaver2节点的,然后查看状态,肯定启动起来,正常,查看一下进程jps,正常,

如果没启动起来,估计问题不好弄了都,我的就解决到这里吧!):

 8:至此,Zookerper集群就启动起来了,然后就可以通过java的api往里面写数据,注入分布式应用让Zookerper协调的数据,或者使用命令行的客户端zkCli.sh模式,zkCli.sh连到集群上面去访问数据,可以用来做测试(不带参数连接到本节点上面去):

 

Connecting to localhost:2181
2017-10-11 02:39:39,035 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT
2017-10-11 02:39:39,040 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=slaver2
2017-10-11 02:39:39,040 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_65
2017-10-11 02:39:39,040 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2017-10-11 02:39:39,040 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/home/hadoop/jdk1.7.0_65/jre
2017-10-11 02:39:39,040 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/hadoop/zookeeper-3.4.5/bin/../build/classes:/home/hadoop/zookeeper-3.4.5/bin/../build/lib/*.jar:/home/hadoop/zookeeper-3.4.5/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/hadoop/zookeeper-3.4.5/bin/../lib/slf4j-api-1.6.1.jar:/home/hadoop/zookeeper-3.4.5/bin/../lib/netty-3.2.2.Final.jar:/home/hadoop/zookeeper-3.4.5/bin/../lib/log4j-1.2.15.jar:/home/hadoop/zookeeper-3.4.5/bin/../lib/jline-0.9.94.jar:/home/hadoop/zookeeper-3.4.5/bin/../zookeeper-3.4.5.jar:/home/hadoop/zookeeper-3.4.5/bin/../src/java/lib/*.jar:/home/hadoop/zookeeper-3.4.5/bin/../conf:
2017-10-11 02:39:39,041 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/i386:/lib:/usr/lib
2017-10-11 02:39:39,041 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2017-10-11 02:39:39,041 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=
2017-10-11 02:39:39,044 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2017-10-11 02:39:39,044 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=i386
2017-10-11 02:39:39,044 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=2.6.32-358.el6.i686
2017-10-11 02:39:39,044 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=hadoop
2017-10-11 02:39:39,045 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/hadoop
2017-10-11 02:39:39,046 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/hadoop/zookeeper-3.4.5/bin
2017-10-11 02:39:39,047 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@1a685ae
Welcome to ZooKeeper!
2017-10-11 02:39:39,096 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@966] - 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
2017-10-11 02:39:39,111 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@849] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
2017-10-11 02:39:39,241 [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 = 0x35f0ac132690000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]

 连接到本节点的2181端口之后向集群里面写任何数据,在另外两个节点都可以看到(Zookerper管理客户所存放的数据采用的是类似于文件树的结构):

 

在其他节点也可以看到的:

 

 

你可能感兴趣的:(zookeeper)