转载从:https://blog.csdn.net/shenlan211314/article/details/6170717

一、zookeeper 介绍

  ZooKeeper 是一个为分布式应用所设计的分布的、开源的协调服务。它的文件系统使用我们所熟悉的目录树结构。ZooKeeper 使用 Java 所编写,但是支持 Java 和 C 两种编程语言。我们设计 ZooKeeper 的目的是为了减轻分布式应用程序所承担的协调任务。

二、zookeeper的安装

首先linux系统需要安装jdk8

下载

https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/

下载:apache-zookeeper-3.4.14.tar,上传至服务器

单机模式:通俗,就是只安装在同一台机子上面

解压:

tar -xvf apache-zookeeper-3.4.14.tar.gz

删除安装包:

rm -rf apache-zookeeper-3.4.14.tar.gz

重命名:

配置环境变量:

export ZOOKEEPER_HOME=/home/linewell/zookeeper
export PATH=$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$PATH
source /etc/profile

配置zookeeper

修改配置文件的名字:

创建data目录:

配置zookeeper:

vim zoo.cfg

tickTime:心跳时间,为了确保连接存在的,以毫秒为单位,最小超时时间为两个心跳时间
initLimit:多少个心跳时间内,允许其他server连接并初始化数据,如果ZooKeeper管理的数据较大,则应相应增大这个值
clientPort:服务的监听端口
dataDir:用于存放内存数据库快照的文件夹,同时用于集群的myid文件也存在这个文件夹里(注意:一个配置文件只能包含一个dataDir字样,即使它被注释掉了。)
dataLogDir:用于单独设置transaction log的目录,transaction log分离可以避免和普通log还有快照的竞争
syncLimit:多少个tickTime内,允许follower同步,如果follower落后太多,则会被丢弃。

server.A=B:C:D:
A是一个数字,表示这个是第几号服务器,B是这个服务器的ip地址
C第一个端口用来集群成员的信息交换,表示的是这个服务器与集群中的Leader服务器交换信息的端口
D是在leader挂掉时专门用来进行选举leader所用

配置如下:

# 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=/tmp/zookeeper
# 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=0
#
minSessionTimeout=4000
maxSessionTimeout=10000
# 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

dataDir=/usr/local/zookeeper/data

server.1=ip:2888:3888

启动:

/home/linewell/zookeeper/bin/zkServer.sh start /home/linewell/zookeeper/conf/zoo.cfg

查看状态:

zkServer.sh status

启动报错:

切换成前台启动:

./bin/zkServer.sh start-foreground

然后就可以查看打印的信息。

搭建zookeeper集群,搭建zookeeper集群的方式和单机的方式大同小异。需要在datadir所指向的目录创建一个叫做myid的文件。上面写下当前服务器的编号。

然后myid里面写下当前服务器的编号。然后配置到zoo.cfg当中。

zoo.cfg的服务器配置:

server.1=ip:2888:3888
server.2=ip:2888:3888

zookeeper 四字命令的使用

先yum安装nc

yum install -y nc

然后测试:

就可以得到配置信息了。

zookeeper的命令行工具使用

输入

zkCli.sh –server 10.77.20.23:2181

进入命令行工具

输入 help 之后,屏幕会输出可用的 ZooKeeper 命令

相关命令使用:

查看特定的路径下,的节点信息,就是查兰特定路径下的节点:

创建一个节点,并添加数据:

查看节点的字符串信息:

重置节点的字符串信息:

然后从新查看,可以发现,已经被重置了。

delete操作删除对应的节点:

删除后用ls命令查看,发现没有了对应的节点了。

zookeeper相关的api介绍:

maven依赖:

<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.13</version>
</dependency>

demo:

图片copy从:https://blog.csdn.net/asd54090/article/details/80920489

zookeeper的安装使用的更多相关文章

  1. zookeeper的安装(图文详解。。。来点击哦!)

    zookeeper的安装(图文详解...来点击哦!) 一.服务器的配置 三台服务器: 192.168.83.133   sunshine 192.168.83.134   sunshineMin 19 ...

  2. (原) 1.1 Zookeeper单机安装

    本文为原创文章,转载请注明出处,谢谢 zookeeper 单机安装配置 1.安装前准备 linux系统(此文环境为Centos6.5) Zookeeper安装包,官网https://zookeeper ...

  3. ZooKeeper的安装、配置、启动和使用(一)——单机模式

    ZooKeeper的安装.配置.启动和使用(一)——单机模式 ZooKeeper的安装非常简单,它的工作模式分为单机模式.集群模式和伪集群模式,本博客旨在总结ZooKeeper单机模式下如何安装.配置 ...

  4. ZooKeeper 的安装和配置---单机和集群

    如题本文介绍的是ZooKeeper 的安装和配置过程,此过程非常简单,关键是如何应用(将放在下节及相关节中介绍). 单机安装.配置: 安装非常简单,只要获取到 Zookeeper 的压缩包并解压到某个 ...

  5. JDK+Tomcat+Zookeeper+DubboAdmin安装教程

    JDK+Tomcat+Zookeeper+DubboAdmin安装教程 1. 安装内容: JDK 1.8.131 Tomcat 7.0.77 Zookeeper 3.4.9 Dubbo admin 2 ...

  6. Zookeeper的安装的配置

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt192 安装和配置详解 本文介绍的 Zookeeper 是以 3.2.2 这个 ...

  7. Zookeeper的安装部署

    1.Zookeeper的安装部署 7.1 Zookeeper工作机制 7.1.1.Zookeeper集群角色 Zookeeper集群的角色:  Leader 和  follower (Observer ...

  8. Zookeeper的安装配置及基本开发

    一.简介 Zookeeper 是分布式服务框架,主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务.状态同步服务.集群管理.分布式应用配置项的管理等等. ZooKeeper的目标就 ...

  9. ZooKeeper的安装

    一.准备 需要提前安装好Java 准备好zookeeper的软件包:软件包地址   二.部署 解压zookeeper压缩包到指定目录 执行如下命令: .tar.gz -C /opt/   三.修改配置 ...

  10. ZooKeeper的安装与部署

    本文讲述如何安装和部署ZooKeeper. 一.系统要求 ZooKeeper可以运行在多种系统平台上面,表1展示了zk支持的系统平台,以及在该平台上是否支持开发环境或者生产环境. 表1:ZooKeep ...

随机推荐

  1. ASP.NET Core中的运行状况检查

    由卢克·莱瑟姆和格伦Condron ASP.NET Core提供了运行状况检查中间件和库,用于报告应用程序基础结构组件的运行状况. 运行状况检查由应用程序公开为HTTP终结点.可以为各种实时监视方案配 ...

  2. flow

    Flow vs Stream https://wikidiff.com/flow/stream As nouns the difference between flow and stream is t ...

  3. await 只能在 async 中使用吗? 并不是

    for await (let a of [1,2,3]) { console.log(a) } ​

  4. (原)关于音频onset detection算法的阅读

    Orgin:Using Audio Onset Detection Algorithms 本文档只记录了部分的内容,主要以aubio相关内容为主,并非整个文档的完整内容,记录人:lihaiping16 ...

  5. Anaconda + PyCharm + Pytorch

    Anaconda 1.  下载Anaconda https://www.anaconda.com/download/ 2.  安装 3. 添加环境变量 Path - C:\Users\Godzilla ...

  6. kubernetes-通过VMware搭建k8s集群遇到的问题

    VMWare版本:14.13 Centos版本:CentOS-7-x86_64-DVD-1810.iso 遇到的问题:ping不通 报could not resolve host这个错误 解决办法:参 ...

  7. 去掉WARN spring.jpa.open-in-view is enabled by default

    使用springboot jpa,在运行项目时发现一个WARN WARN 11472 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : sp ...

  8. activiti学习5:开启流程和流程前进

    目录 activiti学习5:开启流程和流程前进 一.流程和任务的关系 二.开启流程 2.1根据流程定义key开启流程 三.查询用户任务 3.1 TaskQuery 四.完成任务 activiti学习 ...

  9. 【转】pdf文件自动切白边

    pdf文件自动剪裁(自动切白边) FROM:http://www.ai7.org/wp/html/754.html 可能用到的环境.工具:Ubuntu 10.04+TeXLive 2008+pdfcr ...

  10. nginx+upsync+consul 构建动态nginx配置系统

    参考: http://www.php230.com/weixin1456193048.html  [upsync模块说明.性能评测] https://www.jianshu.com/p/76352ef ...