红联Linux门户
Linux帮助

Facebook scribe在Ubuntu下面安装笔记

发布时间:2014-12-20 09:29:00来源:linux网站作者:emili

由于没有测试开发机,只能在自己的电脑上装了一个虚机用来测试一下如何安装和测试 facebook 的 scribe ,费了好大劲,在老公的协助下终于安装成功了,记录一下,作为参考:

由于我的虚机安装的是最小的功能,因此在安装过程中遇到了很多麻烦,缺少很多的包,所以安装过程比较长,可能在公司服务器上安装会好些。

(1)安装 g++: sudo apt-get install g++

(2) 安装 ruby : sudo apt-get install ruby1.8-dev( 因为在后面要安装 thrift 需要 require mkmf, 因此必须安装 ruby1.8-dev)

(3)安装 python: 一般系统会自带,但后后面安装的时候会报告说缺少 Python.h 这个文件,因此必须安装 python-dev 这个包。所以最好这里重新安装一下 python ,安装命令如下 : sudo apt-get install python-dev 。

(4)安装 libevent:

1.首先下载这个包 wget http://www.monkey.org/~provos/libevent-2.0.10-stable.tar.gz

2.tar –xvf libevent-2.0.10-statble.tar.gz

3. ./configure

4.make

5. make install

(5)安装 php

1.       必须先安装 libxml2 ,然后在安装 php, 下载 libxml2: Libxml2 的安装包下载地址: ftp://xmlsoft.org/libxml2/ ,下载 libxml2-2.7.4.tar.gz

2.       Tar –xvf libxml2-2.7.4.tar.gz

3.       Configure

4.       Make

5.       Make install

6.       下载 php: Php 下载地址 http://cn.php.net/downloads.php ,下载了 PHP 5.3.5 (tar.gz)

7.       Tar –vxf  PHP 5.3.5 (tar.gz)

8.       ./configure --prefix=/usr/local/php5 --with-php-config=/usr/local/php5/bin/php-config (因为在 scribe 的一些版本中用到 php-config ,所以这里面要用 —with-php-config ,但是在我的安装过程没有用到,所以这个可以忽略)

9.       Make

10.   Make install

(6) 安装 boost

1. Wget http://nchc.dl.sourceforge.net/project/boost/boost/1.45.0/boost_1_45_0.tar.bz2

2.tar jxvf boost_1_45_0.tar.bz2

3.                        cd boost_1_45_0

4.                        sudo apt-get install zlib2-dev( 因为我的系统在安装的时候报错了,说是缺少 zlib.h 文件,因此我必须得安装这个包,才能进行后续的操作 )

5.                        ./bootstrap.sh

6.                        ./bjam -s HAVE_ICU=1 --prefix=/usr/local/boost --includedir=/usr/local/boost/include --libdir=/usr/local/boost/lib

7.                        ./bjam install --prefix=/usr/local/boost

(7)       安装 thrift

因为 thrift 的安装决定了后面的 scribe 的安装,我开始安装 thrift-0.5.0.tar.gz 这个版本的,但在 scribe 的时候会一直报: scribe_server.h:45: error: conflicting return type specified for ‘virtual scribe::thrift::ResultCode scribeHandler::Log(const std::vector<scribe::thrift::LogEntry, std::allocator<scribe::thrift::LogEntry> >&)’ 这个错误,后来查了一下,说是因为 thrift 的 0.5.0 版本有问题,因此这在里应该选择 thrift-0.4.0.tar.gz 这个版本(我是在 2011-2-17 日安装的,可能在后面的版本会修复这个 bug 吧)。

1.       下载 thrift: http://apache.etoak.com//incubator/thrift/ 在这里选择 0.4.0 ,具体下载 wget http://apache.etoak.com//incubator/thrift/0.4.0-incubating/thrift-0.4.0.tar.gz

2.       因为我在 thrift 过程中报了很多错误,我把所有需要的系统的包全部安装了一下,具体有如下这些 sudo apt-get install libghc6-http-dev libghc6-binary-dev libboost-iostreams-dev libboost-filesystem-dev libboost-dev automake libtool flex bison pkg-config g++ ant ivy libslf4j-java libcommons-lang-java liblog4j1.2-java automake1.10

3.       tar -xvf thrift-0.4.0.tar.gz

4.       cd thrift-0.4.0

5.       ./configure --with-boost=/usr/local/boost ( 在 0.5.0 里面可能需要 --with-php-config=/usr/local/php5/bin/php-config, 但在 0.4.0 里面是不需要的 )

6.       Make

7.       make install

安装 fb303

8.       cd contrib/fb303

9.       ./bootstrap.sh

10.   ./configure --with-boost=/usr/local/boost

11.   make

12.   make install

(8)       安装 scribe

下载 scribe ,网上的资料都是说要安装 facebook-scribe-2ee14d3.tar.gz ,但是现在网上找不到这个包,忙乎了一大通,后来终于搞清楚了,现在要去 https://github.com/pcting/scribe/ 这个网站,选择右上角的 Downloads 这个按钮,选择下载 .tar.gz 文件,下载下来的文件是 pcting-scribe-2ee14d3.tar.gz 文件。注意这个网站下面有一些 message ,会针对某些安装过程报的 bug 做出一些解释,可以翻看一下。

1.       设置变量: export BOOST_ROOT=/usr/local/boost

export LD_LIBRARY_PATH=/usr/local/boost/lib::/usr/lob:/usr/local/lib

ldconfig –v

2.       tar –xvf pcting-scribe-2ee14d3.tar.gz

3.       cd   pcting-scribe-2ee14d3

4.       ./bootstrap.sh

5.       ./configure --with-boost=/usr/local/boost --prefix=/usr/local/scribe

6.       Make

7.       make install

(9)       测试

还是在 pcting-scribe-2ee14d3/examples 这个目录下,有一个 README 文件,里面举例如何测试 scribe 是否安装和运行正常的。

mkdir /tmp/scribetest

在 pcting-srcibe-2ee14d3 目录下执行:

src/scribed examples/example1.conf 如果显示类似下面的内容,表示成功启动 scribe

[Wed Feb 16 21:21:29 2011] "setrlimit error (setting max fd size)"

[Wed Feb 16 21:21:29 2011] "STATUS: STARTING"

[Wed Feb 16 21:21:29 2011] "STATUS: configuring"

[Wed Feb 16 21:21:29 2011] "got configuration data from file <examples/example1.conf>"

[Wed Feb 16 21:21:29 2011] "CATEGORY : default"

[Wed Feb 16 21:21:29 2011] "Creating default store"

[Wed Feb 16 21:21:29 2011] "configured <1> stores"

[Wed Feb 16 21:21:29 2011] "STATUS: "

[Wed Feb 16 21:21:29 2011] "STATUS: ALIVE"

[Wed Feb 16 21:21:29 2011] "Starting scribe server on port 1463"

Thrift: Wed Feb 16 21:21:29 2011 libevent 2.0.10-stable method epoll

退出当前状态,然后执行

Nohup src/scribed examples/example1.conf & (让其后台运行)

设置变量 export PYTHONPATH= /usr/lib/python2.5/site-packages

然后执行 echo "hello world" | ./scribe_cat test

看看 cat /tmp/scribetest/test/test_current 里面的结果是不是 hello world? 是就 ok 了,不是那就悲剧了。

(10)   一个用来将 apache 等日志传到 scribe 的 python 例子
Pipe Apache (or any) Logs to Scribe

I created a simple Python script called scribe_log to tail a log file and pipe it to Scribe.

I use supervisor to start and keep the pipe running.

Relevant supervisord.conf configuration:

[program:scribe.apache.access]
command=/usr/local/sbin/scribe_log --category apache.access --file /var/log/httpd/access_log

usage: scribe_log [options]options:
-h, --help           show this help message and exit
--file=FILE          file to tail into Scribe
--category=CATEGORY  Scribe category
--host=HOST          destination Scribe host server
--port=PORT          destination Scribe port
--prefix=PREFIX      add to the beginning of each log line
--postfix=POSTFIX    add to the end of each log line