导航

Heka 的编译 和 Heka 插件的编译

Posted on 2016-07-27 14:19  蝈蝈俊  阅读(649)  评论(0编辑  收藏  举报

相关英文文档在: https://hekad.readthedocs.io/en/latest/installing.html 

所有系统都必须的如下:

Prerequisites (all systems):

 

编译需要的依赖项:

CMark

下载地址: https://cmake.org/download/

我下载的是 适用 Mac OS X 10.6 or later 的 cmake-3.6.1-Darwin-x86_64.dmg 

修改 PATH 设置, 确保命令行可以使用

One may add CMake to the PATH:

PATH="/Applications/CMake.app/Contents/bin":"$PATH"

Or, to install symlinks to '/usr/local/bin', run:

sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install

Or, to install symlinks to another directory, run:

sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install=/path/to/bin

安装成功的标示如下:

$ cmake --version
cmake version 3.6.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

 

git

我下载的是Mac 下最新版本的git : git-2.9.2-intel-universal-mavericks.dmg

https://git-scm.com/download/mac 

安装完成后的检查是否正常的方法仍然是:

$ git --version
git version 2.9.2

Mercurial

下载地址 : https://www.mercurial-scm.org/   我下载的是 Mercurial-3.8.2-macosx10.10.pkg

安装完成后的检测方法:

$ hg --version
分布式软件配置管理工具 - 水银 (版本 3.8.2)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2016 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

编译项目

$ cd heka
$ source build.sh

注意,是 source build.sh

 

source命令(从 C Shell 而来)是bash shell的内置命令。点命令,就是个点符号,(从Bourne Shell而来)是source的另一名称。同样的,当前脚本中设置的变量也将作为脚本的环境,source(或点)命令通常用于重新执行刚修改的初始化文件,如 .bash_profile 和 .profile 等等。例如,如果在登录后对 .bash_profile 中的 EDITER 和 TERM 变量做了修改,则能用source命令重新执行 .bash_profile 中的命令而不用注销并重新登录。

source命令的作用就是用来执行一个脚本,那么:source a.sh 同直接执行 ./a.sh 有什么不同呢,比如你在一个脚本里export $KKK=111 ,如果你用./a.sh执行该脚本,执行完毕后,你运行 echo $KKK ,发现没有值,如果你用source来执行,然后再echo ,就会发现KKK=111。因为调用./a.sh来执行shell是在一个子shell里运行的,所以执行后,结果并没有反应到父shell里,不过source不同,他就是在本shell中执行的,所以能看到结果。

source命令是shell的一个内部命令,它从指定的shell 文件中读入所有命令语句并在当前进程中执行。 因此当多个shell进程(父子进程或无关进程均可)共享一组变量值时,就可以将这些变量赋值语句定义到一个shell文件里,并在需要这些变量值的程序中使用点语句来引用这个shell文件,从而实现变量值共享(对这些变量值的修改仅涉及到这个shell文件)。但要注意的是,这个shell文件不能包括含有位置参数的语句,即不能接受$1、$2等命令行参数。

参考: http://www.ahlinux.com/shell/23595.html

编译 go 写的 heka 插件

在  {heka root}/cmake/plugin_loader.cmake 文件中 , 通过 add_external_plugin 指定需要参与编译的目录或 git 地址

add_external_plugin(git https://github.com/mozilla-services/heka-mozsvc-plugins 6fe574dbd32a21f5d5583608a9d2339925edd2a7)
add_external_plugin(git https://github.com/example/path <tag> util filepath)
add_external_plugin(git https://github.com/bellycard/heka-sns-input :local)
# The ':local' tag is a special case, it copies {heka root}/externals/{plugin_name} into the Go
# work environment every time `make` is run. When local development is complete, and the source
# is checked in, the value can simply be changed to the correct tag to make it 'live'.
# i.e. {heka root}/externals/heka-sns-input -> {heka root}/build/heka/src/github.com/bellycard/heka-sns-input
 

:local标志就是代表从第一步创建的externals目录获取源码,否则就会自动的从此git地址checkout源码来编译,所以插件开发阶段此处应该是:local

 

然后重新编译 heka  就可以完成插件的编译。

参考: http://ju.outofmemory.cn/entry/72713