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实际上运行在Zab协议(ZooKeeper Atomic Broadcast)之上,Zab几乎与Raft是一样的。从Raft说起,Raft实际上就是一个库。你可以在一些更大的多副本系统中使用Raft库。但是Raft不是一个你可以直接交互的独立的服务,你必须要设计你自己的应用程序来与Raft库交互。所以这里有一个有趣的问题:是否有一些有用的,独立的,通用的系统可以帮助人们构建分布式系统?是否有这样的服务可以包装成一个任何人都可以使用的独立服务,并且极大的减轻构建分布式应用的痛苦?所以,对于一个通用的服务,API应该是怎样?Zookeeper可以被认为是一个通用的协调服务(General-Purpose Coordination Service)。
Zookeeper 允许客户端将读请求发送给任意副本,并由副本根据自己的状态来响应读请求。副本的 Log 可能并没有拥有最新的条目,所以尽管系统中可能有一些更新的数据,这个副本可能还是会返回旧的数据。
Zookeeper 的一致性保证:写请求是线性一致的、 FIFO 客户端序列(所有客户端发送的请求以一个特定的序列执行,通过 zxid 维护)。
TODO
TODO