[Zookeeper]介绍及Linux下安装使用。ZooKeeper是源代码开放的分布式协调服务,由雅虎创建,是Google的开源实现。ZooKeeper是一个高性能的分布式数据一致性解决方案,他将那些复杂的、容易出错的分布式一致性服务封装起来,构成一个高效可靠的原语集,并提供一系列简单易用的接口给用户使用。
典型应用场景
1.集群维护(master选举) 2.配置管理(数据的发布和订阅) 3.分布式锁 4.分布式队列 5.命名服务
优势
源代码开放 它是分布式协调服务,解决了分布式数据一致性的问题1.顺序一致性 2.原子性 3.单一视图 4.可靠性 5.实时性高性能 我们可以通过调用zookeeper提供的接口来解决一些分布式应用中的实际问题
下面我们来安装Zookeeper
下载解压后备份zoo_sample.cfg
$ cp zoo_sample.cfg zoo.cfg
修改 zoo.cfg 配置文件
$ vi 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/usr/zookeeper/zookeeper-3.4.6/data dataLogDir=/root/usr/zookeeper/zookeeper-3.4.6/logs # the port at which the clients will connect clientPort=2181 #2888,3888 are election port server.1=192.168.1.7:2888:3888
在 dataDir=/root/usr/zookeeper/zookeeper-3.4.6/data下创建 myid 文件。
编辑 myid 文件,并在对应的 IP 的机器上输入对应的编号。
启动
$ zkServer.sh start
查看状态
$ zkServer.sh status
停止 zookeeper 进程
$ zkServer.sh stop
连接zookeeper
使用zkCli.sh可以连接zookeeper,以及在客户端操作zookeeper。 ./bin/zkCli.sh -timeout 5000 -server 127.0.0.1:2181
连接成功后会有如下提示界面
之后回车即可进入控制台界面