ZooKeeper Client API 安装及使用指北

下载

wget https://archive.apache.org/dist/zookeeper/zookeeper-3.5.4-beta/zookeeper-3.5.4-beta.tar.gz

解压

tar -zxf zookeeper-3.5.4-beta.tar.gz

安装

cd zookeeper-3.5.4-beta/src/c/
./configure
make
sudo make install

make 这一步大概率会出现报错:

User
make[1]: Entering directory '/root/zookeeper-3.5.4-beta/src/c'
/bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.  -I./include -I./tests -I./generated   -Wall -Werror -Wdeclaration-after-statement -g -O2 -D_GNU_SOURCE -MT zookeeper.lo -MD -MP -MF .deps/zookeeper.Tpo -c -o zookeeper.lo `test -f 'src/zookeeper.c' || echo './'`src/zookeeper.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I./include -I./tests -I./generated -Wall -Werror -Wdeclaration-after-statement -g -O2 -D_GNU_SOURCE -MT zookeeper.lo -MD -MP -MF .deps/zookeeper.Tpo -c src/zookeeper.c  -fPIC -DPIC -o .libs/zookeeper.o
src/zookeeper.c: In function ‘print_completion_queue’:
src/zookeeper.c:2530:5: error: argument 1 null where non-null expected [-Werror=nonnull]
 2530 |     fprintf(LOGSTREAM,"Completion queue: ");
      |     ^~~~~~~
In file included from ./include/zookeeper.h:35,
                 from src/zookeeper.c:28:
/usr/include/stdio.h:312:12: note: in a call to function ‘fprintf’ declared ‘nonnull’
  312 | extern int fprintf (FILE *__restrict __stream,
      |            ^~~~~~~
src/zookeeper.c:2532:9: error: argument 1 null where non-null expected [-Werror=nonnull]
 2532 |         fprintf(LOGSTREAM,"empty\n");
      |         ^~~~~~~
/usr/include/stdio.h:312:12: note: in a call to function ‘fprintf’ declared ‘nonnull’
  312 | extern int fprintf (FILE *__restrict __stream,
      |            ^~~~~~~
src/zookeeper.c:2538:9: error: argument 1 null where non-null expected [-Werror=nonnull]
 2538 |         fprintf(LOGSTREAM,"%d,",cptr->xid);
      |         ^~~~~~~
/usr/include/stdio.h:312:12: note: in a call to function ‘fprintf’ declared ‘nonnull’
  312 | extern int fprintf (FILE *__restrict __stream,
      |            ^~~~~~~
src/zookeeper.c:2541:5: error: argument 1 null where non-null expected [-Werror=nonnull]
 2541 |     fprintf(LOGSTREAM,"end\n");
      |     ^~~~~~~
/usr/include/stdio.h:312:12: note: in a call to function ‘fprintf’ declared ‘nonnull’
  312 | extern int fprintf (FILE *__restrict __stream,
      |            ^~~~~~~
cc1: all warnings being treated as errors
Makefile:1025: recipe for target 'zookeeper.lo' failed
make[1]: *** [zookeeper.lo] Error 1
make[1]: Leaving directory '/root/zookeeper-3.5.4-beta/src/c'
Makefile:684: recipe for target 'all' failed
make: *** [all] Error 2

主要原因还是linux的版本问题,这边用的是ubuntu18+gcc13,网上找了一圈解决方法少之又少,基本是通过换centos解决,其实只需要将当前目录 Makefile 文件中 -Werror 选项去除即可,这样报错就会变成警告。

什么是ZooKeeper?

Zookeeper实际上运行在Zab协议(ZooKeeper Atomic Broadcast)之上,Zab几乎与Raft是一样的。从Raft说起,Raft实际上就是一个库。你可以在一些更大的多副本系统中使用Raft库。但是Raft不是一个你可以直接交互的独立的服务,你必须要设计你自己的应用程序来与Raft库交互。所以这里有一个有趣的问题:是否有一些有用的,独立的,通用的系统可以帮助人们构建分布式系统?是否有这样的服务可以包装成一个任何人都可以使用的独立服务,并且极大的减轻构建分布式应用的痛苦?所以,对于一个通用的服务,API应该是怎样?Zookeeper可以被认为是一个通用的协调服务(General-Purpose Coordination Service)。

Zookeeper 允许客户端将读请求发送给任意副本,并由副本根据自己的状态来响应读请求。副本的 Log 可能并没有拥有最新的条目,所以尽管系统中可能有一些更新的数据,这个副本可能还是会返回旧的数据。

Zookeeper 的一致性保证:写请求是线性一致的、 FIFO 客户端序列(所有客户端发送的请求以一个特定的序列执行,通过 zxid 维护)。

使用场景

TODO

Client API

TODO

相关推荐

  1. ZooKeeper Client API 安装使用

    2023-12-25 07:06:03       34 阅读
  2. sonarqube使用(一)- 基于docker的安装部署

    2023-12-25 07:06:03       15 阅读
  3. Swift

    2023-12-25 07:06:03       28 阅读
  4. React Hooks学习

    2023-12-25 07:06:03       34 阅读
  5. React Hooks学习

    2023-12-25 07:06:03       35 阅读
  6. Python入门学习

    2023-12-25 07:06:03       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-25 07:06:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-25 07:06:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-25 07:06:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-25 07:06:03       20 阅读

热门阅读

  1. 适配器模式(Adapter)

    2023-12-25 07:06:03       45 阅读
  2. servlet

    servlet

    2023-12-25 07:06:03      42 阅读
  3. 最简单的GPT的Transformer架构

    2023-12-25 07:06:03       30 阅读
  4. 删除开发分支 新建另一个开发分支

    2023-12-25 07:06:03       34 阅读
  5. 零基础搭建k8s集群(一)- 基础准备

    2023-12-25 07:06:03       44 阅读
  6. Mysql中的快照读和当前读

    2023-12-25 07:06:03       31 阅读
  7. Error: EACCES: permission denied, mkdir

    2023-12-25 07:06:03       37 阅读