LinuxBCC 工具安装
Posted 宣之于口
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LinuxBCC 工具安装相关的知识,希望对你有一定的参考价值。
【Linux】BCC 工具安装
一、安装步骤
1. 安装构建依赖项
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
2. 安装并编译LLVM
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 ../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 ../cfe-7.0.1.src
make
sudo make install
cd ..
3. 安装并编译BCC
git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
cmake ..
make
sudo make install
4. 测试
执行./hello_world.py
最终输出:
$ ./hello_world.py
sshd-1665 [000] d... 1195.866430: : Hello, World!
sshd-28313 [001] d... 1196.174047: : Hello, World!
sshd-1665 [000] d... 1206.072681: : Hello, World!
sshd-28315 [000] d... 1206.370377: : Hello, World!
sshd-28315 [000] d... 1209.032548: : Hello, World!
二、问题
问题: This file requires compiler and library support for the iso c++ 2011 standard
解决办法:
$ vim /bcc/CMakeLists.txt
# 修改下面这一行
set(CMAKE_CXX_FLAGS "$CMAKE_CXX_FLAGS -Wall $CXX_ISYSTEM_DIRS")
# 加上-std=c++11 -O3
set(CMAKE_CXX_FLAGS "$CMAKE_CXX_FLAGS -Wall $CXX_ISYSTEM_DIRS -std=c++11 -O3 ")
问题:
modprobe: FATAL: Module kheaders not found.
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module)
chdir(/lib/modules/5.6.2-1.el7.elrepo.x86_64/build): No such file or directory
Traceback (most recent call last):
File "./hello_world.py", line 12, in <module>
BPF(text='int kprobe__sys_clone(void *ctx) bpf_trace_printk("Hello, World!\\\\n"); return 0; ').trace_print()
File "/usr/lib/python2.7/site-packages/bcc/__init__.py", line 356, in __init__
raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>
解决办法: 查看kernel 版本, 要求4.1以上, 发现不符合要求,注意BPF堆栈跟踪仅4.6版本以上可用!!!
$ uname -r
3.10.0-1062.9.1.el7.x86_64
升级kernel至4.6版本以上: 参考这篇文章
然后安装kernel-devel
, 请确保它与系统上当前安装的内核版本匹配
sudo yum install "kernel-devel-uname-r == $(uname -r)"
问题: 在安装kernel-devel
显示 No package
No package kernel-devel-uname-r == 5.6.2-1.el7.elrepo.x86_64 available.
解决办法: 启用[elrepo-kerne]存储库, vim /etc/yum.repos.d/elrepo.repo
[elrepo-kernel]
name=ELRepo.org Community Enterprise Linux Kernel Repository - el7
baseurl=http://elrepo.org/linux/kernel/el7/$basearch/
http://mirrors.coreix.net/elrepo/kernel/el7/$basearch/
http://mirror.rackspace.com/elrepo/kernel/el7/$basearch/
http://repos.lax-noc.com/elrepo/kernel/el7/$basearch/
http://mirror.ventraip.net.au/elrepo/kernel/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-kernel.el7
# 修改这一行将0改为1
enabled=1
然后重新执行: sudo yum install "kernel-devel-uname-r == $(uname -r)"
问题: No module named bcc
[root@rumia examples]# ./hello_world.py
Traceback (most recent call last):
File "./hello_world.py", line 9, in <module>
from bcc import BPF
ImportError: No module named bcc
解决办法: 检查sudo make install
日志是否被正确执行。
我发现我没有该目录/usr/lib/python2.7/site-packages/bcc
, 重新执行了 sudo make install
以上是关于LinuxBCC 工具安装的主要内容,如果未能解决你的问题,请参考以下文章