1、Build Boost Library:https://www.boost.org/doc/libs/1_61_0/more/getting_started/unix-variants.html
1 | cd boost_1_61_0 |
要求boost在1.54以上,cmake要求3.0以上 ,gcc在4.8 以上
另外需要安装一些包:
1 | yum install openssl-devel go |
2、Build Casablanca: https://github.com/Microsoft/cpprestsdk
1 | git clone https://github.com/Microsoft/cpprestsdk.git |
因为cpprestsdk源码中中有些变量没有用到,会把警告当错误。 需要注释掉
1 | cpprestsdk-2.10.1/Release/CMakeLists.txt:14: |
如若手动指定boost库版本,需要在
vi cpprestsdk-2.10.1/Release/cmake/cpprest_find_boost.cmake
在20行下面添加
1 | 20 elseif(UNIX) |
3、Install grpc for C++ :https://github.com/grpc/grpc.git
1 | cd grpc |
安装路径在Makefile中配置prefix
4、Install Protobuf :这里使用grpc下自带的第三方protobuf编译安装
1 | cd grpc/third_party/protobuf/ |
5、Install etcd :
源码安装(需要安装go环境)
1 | git clone https://github.com/coreos/etcd.git |
或者下载 https://github.com/coreos/etcd/releases etcd-v3.3.8-linux-amd64的二进制包
1 | unzip etcd-v3.3.8-linux-amd64 |
6、etcd-cpp-apiv3 安装:https://github.com/nokia/etcd-cpp-apiv3.git
在 etcd-cpp-apiv3-master中如果是自定义头文件或库安装路径的话需要对
CMakeLists.txt 进行更改
1 | vi etcd-cpp-apiv3-master/CMakeLists.txt |
1 | vi etcd-cpp-apiv3-master/src/CMakeLists.txt |
etcd-cpp-apiv3-master/tst/CMakeLists.txt一行设置有问题
需改为:
1 | find_path(CATCH_INCLUDE_DIR NAMES catch.hpp ..) |
把由第三步第四步生成protoc grpc_cpp_plugin 二进制程序(在install后的bin中)拷贝到proto目录,执行相应的命令生成protoc的接口文件
1 | cd etcd-cpp-apiv3-master/proto |
编译安装最终 libetcd-cpp-api.so Client.hpp Response.hpp SyncClient.hpp Value.hpp Watcher.hpp
1 | cd etcd-cpp-apiv3-master |
注意事项:
1、grpc需使用git clone下来的master版本,而且还需要下载子模块
2、个别模块中的CMakeLists.txt需要更改,测试用例个别有问题
3、etcd v3的c++ client实现使用的是https://github.com/nokia/etcd-cpp-apiv3上的开源代码,其实现的功能有限且不稳定,增删改查、订阅功能都有,更新租约(保活)、事务操作等都没实现。
4、开源client代码中订阅功能会在grpc通信write阶段发生coredump,参考了https://github.com/nokia/etcd-cpp-apiv3/issues/5进行解决,但没解决根本原因,需要进一步研究grpc调用过程。
5、thrift 中协议有些字段与protobuf 中的字段冲突,引发难以查找的错误。 如文件中的version字段
6 还有就是cpprest中concurrency 与apache中apache::thrift::concurrency命名冲突 ,在cpprest前加上pplx域名空间
6、用c++11 版本编译,std::shared_ptr 与boost::shared_ptr 冲突,后改为用boost::shared——ptr ,本来打算用std::shared_ptr ,单如此的话还有要更改一些第三方问文件,且会与以前版本不兼容
需要更改的头文件 cpprest中出现concurrency的,/usr/include/thrift/config.h中的version或者/usr/local/include/proto/rpc.proto 中version改名字
monitor中所有的shared_ptr 都加上boost命名空间前缀