最近准备整合多个系统的日志,于是想到构建一套分布式日志存储系统,首先考虑的是Scribe,不过编译安装耗费了不少时间(Scribe相关文档确实少了点,相比Flume) html
环境:Ubuntu13.04 32bit bootstrap
组件:
scribe 2.x(最新版)
thrift 0.9.0
boost 1.54
fb303 thrift自带 分布式
至于其余所依赖的相关包(如libevent、automake、flex、bison等)可根据configure的结果进行安装或更新。 测试
一、安装boost flex
官网下载boost,版本要求高于1.36(做者用的是1.54.0),按照文档中给出的方法编译:
$tar --bzip2 -xf /home/vincent/Download/boost_1_54_0.tar.bz2
$cd /home/vincent/Download/boost_1_54_0
$./bootstrap.sh --help
$./bootstrap.sh --prefix=opt/boost_1.54
$./b2 install ui
至此,boost库编译完成,编译时无需指定其余选项,在--prefix参数指定的目录下生成include和lib文件夹存放头文件和库文件。 spa
二、安装thrift 日志
下载thrift包,安装是经典的三大步:
$tar zxvf thrift-0.9.0.tar.gz
$cd thrift-0.9.0/
$sudo ./configure CPPFLAGS="-DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H"
$sudo make
$sudo make install server
configure时CPPFLAGS参数不可少,不然make时会产生诸如“uint_32未定义”之类错误。另外,configure时如找不到boost库,则需使用--with-boost参数指定boost库位置。thrift安装后能够进行简单的测试以确认是否安装成功。 htm
三、安装fb303
fb303包含在thrift安装包里,直接make安装:
$cd contrib/fb303
$sudo ./bootstrap.sh --with-boost=/opt/boost_1.54/lib/
$sudo make
$sudo make install
此处--with-boost便是指定boost库位置
四、安装scribe
依赖组件安装完毕,便可开始编译scribe:
$./bootstrap.sh
$sudo ./configure --with-boost=/opt/boost_1.54/lib/ --prefix=/opt/scribe
$sudo make
$sudo make install
编译时可能会产生相关错误:
1)configure若遇到以下错误
checking whether the Boost::System library is available… yes
checking whether the Boost::Filesystem library is available… yes
configure: error: Could not link against !
则需在configure时加上参数
--with-boost-system=lboost_system
--with-boost-filesystem=lboost_filesystem
笔者的configure以下:
sudo ./configure --prefix=/opt/scribe --with-boost=/usr/local/lib --with-boost-system=boost_system --with-boost-filesystem=boost_filesystem CPPFLAGS="-DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -DBOOST_FILESYSTEM_VERSION=3"
2)make时若遇到:
undefined reference to 'boost::system::generic_category()'
undefined reference to 'boost::system::system_category()'
在确认boost::system库存在且路径正确后,检查GCC连接代码(根据make输出),笔者的以下:
g++ -Wall -O3 -L/usr/local/lib/ -lboost_system -lboost_filesystem -o scribed store.o store_queue.o conf.o file.o conn_pool.o scribe_server.o network_dynamic_config.o dynamic_bucket_updater.o env_default.o -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -lfb303 -lthrift -lthriftnb -levent -lpthread libscribe.a libdynamicbucketupdater.a
此时需将-lboost_system -lboost_filesystem两个选项放在最后,并在src目录下手动执行连接便可完成编译。(该问题是因为gcc在静态连接时对依赖库的顺序有要求致使,详细解释可参考http://www.cppblog.com/wiisola/archive/2010/05/18/115637.html)