Skip to content

CentOS 7.6上构建bcc-tools

## 更新: 在CentOS 7.7中,文件已经解决。直接`yum install bcc-tools`就可以了。

目前公司的CentOS 7.6系统上已经有bcc-tools软件包了,直接yum install bcc-tools就可以。遗憾的是,安装了之后程序运行报错。

CentOS 7.6 1810, with kernel 3.10.0-957.27.2.el7.x86_64 #1

运行tcplife,报错如下:

[hbcheng@myhost ~]$ sudo /usr/share/bcc/tools/tcplife [641/667]
[sudo] password for hbcheng:
In file included from /virtual/main.c:4:
In file included from /lib/modules/3.10.0-957.27.2.el7.x86_64/build/include/linux/tcp.h:21:

/lib/modules/3.10.0-957.27.2.el7.x86_64/build/arch/x86/include/asm/signal.h:23:2: note: array ‘sig’ declared here
unsigned long sig[_NSIG_WORDS];
^
49 warnings and 1 error generated.
Traceback (most recent call last):
File “/usr/share/bcc/tools/tcplife”, line 479, in <module>
b = BPF(text=bpf_text)
File “/usr/lib/python2.7/site-packages/bcc/__init__.py”, line 318, in __init__
raise Exception(“Failed to compile BPF text”)
Exception: Failed to compile BPF text

网上查了一下,好像跟llvm有关。于是决定从源码自己构建。

根据官方文档,流程如下:

## Centos - Source
## For Centos 7.6 only

#Install build dependencies
sudo yum install -y epel-release
sudo yum update -y
sudo yum groupinstall -y "Development tools"
sudo yum install -y elfutils-libelf-devel cmake3 git bison flex ncurses-devel
sudo yum install -y luajit luajit-devel  # for Lua support

##Install and compile LLVM
## You could compile LLVM from source code

curl  -LO  http://releases.llvm.org/7.0.1/llvm-7.0.1.src.tar.xz
curl  -LO  http://releases.llvm.org/7.0.1/cfe-7.0.1.src.tar.xz
tar -xf cfe-7.0.1.src.tar.xz
tar -xf llvm-7.0.1.src.tar.xz

mkdir clang-build
mkdir llvm-build

cd llvm-build
cmake3 -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
  -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ../llvm-7.0.1.src
make
sudo make install

cd ../clang-build
cmake3 -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
  -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ../cfe-7.0.1.src
make
sudo make install
cd ..

## Install and compile BCC
git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install

llvm和clang的构建比较费时间。在make那一步,可以试试make -j 8 (根据自己电脑性能调整数字)

incomplete definition of type ‘struct kiocb’

## 还有一个关键就是你需要安装跟系统内核版本对应的kernel 源码包,不然编译BPF程序的时候会报错。

Avatar

专业Linux/Unix/Windows系统管理员,开源技术爱好者。对操作系统底层技术,TCP/IP协议栈以及信息系统安全有强烈兴趣。电脑技术之外,则喜欢书法,古典诗词,数码摄影和背包行。

Sidebar