一、升级内核
bcc-tools 需要内核版本为 4.1 或者更新的版本,如果你用的是 CentOS,那就需要手动升级,Centos7.6内核升级。
注意:BPF 堆栈跟踪仅 4.6 版本以上可用!!!强烈建议升级到 4.6 内核以上。
yum install gcc-c++
wget https://cmake.org/files/v3.7/cmake-3.7.0.tar.gz
tar xf cmake-3.7.0.tar.gz
cd cmake-3.7.0
./configure
make -j $THREADS
make install
cd ..复制
二、安装 bison
curl -OL https://ftp.gnu.org/gnu/bison/bison-3.0.tar.xz
tar -xf bison-3.0.tar.xz
cd bison-3.0
./configure
make
make install
cd ..复制
三、安装并编译LLVM
curl -LO http://releases.llvm.org/3.9.1/cfe-3.9.1.src.tar.xz
curl -LO http://releases.llvm.org/3.9.1/llvm-3.9.1.src.tar.xz
tar -xf cfe-3.9.1.src.tar.xz
tar -xf llvm-3.9.1.src.tar.xz
mkdir clang-build
mkdir llvm-build
cd llvm-build
cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ../llvm-3.9.1.src
make -j $THREADS
make install
cd ../clang-build
cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ../cfe-3.9.1.src
make -j $THREADS
make install
cd ..复制
四、安装netperf
git clone https://github.com/multipath-tcp/netperf.git
cd netperf
./configure
make
make install复制
五、安装 bcc 依赖
yum install -y elfutils-libelf-devel flex iperf
复制
六、安装bcc
git clone https://github.com/iovisor/bcc.git
export CFLAGS=-I${HOME}/build/linux-4.9.71/usr/include
mkdir bcc-build
cd bcc-build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr ../bcc
make -j $THREADS
make install复制
七、开启 debugfs
# Copy bcc package for python 2.7
cp -r usr/lib/python2.6/site-packages/bcc usr/local/lib/python2.7/site-packages/bcc
# MANUAL! Mount DEBUGFS in fstab:
#debugfs sys/kernel/debug debugfs defaults 0 0
# or
mount -t debugfs debugfs sys/kernel/debug复制
八、问题解决
[root@k8s ~]# cachestat 1 1
modprobe: FATAL: Module kheaders not found.
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module) or installing the kernel development package for your running kernel version.
chdir(/lib/modules/4.4.236-1.el7.elrepo.x86_64/build): No such file or directory
Traceback (most recent call last):
File "/usr/share/bcc/tools/cachestat", line 96, in <module>
b = BPF(text=bpf_text)
File "/usr/lib/python2.7/site-packages/bcc/__init__.py", line 364, in __init__
raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>
[root@k8s ~]#复制
解决办法: 查看kernel 版本, 然后安装 kernel-devel,请确保它与系统上当前安装的内核版本匹配。
yum install "kernel-devel-uname-r == $(uname -r)"
复制
问题:安装时出现显示 No package。
[root@k8s ~]# yum install "kernel-devel-uname-r == $(uname -r)"
已加载插件:fastestmirror
Determining fastest mirrors
epel/x86_64/metalink | 5.8 kB 00:00:00
* base: mirrors.aliyun.com
* elrepo: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.bfsu.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
dell | 2.3 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
elrepo | 2.9 kB 00:00:00
Not using downloaded elrepo/repomd.xml because it is older than what we have:
Current : Fri Sep 25 08:15:03 2020
Downloaded: Fri Sep 25 06:15:03 2020
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
没有可用软件包 kernel-devel-uname-r == 4.4.236-1.el7.elrepo.x86_64。
错误:无须任何处理
[root@k8s ~]#复制
解决办法:启用[elrepo-kerne]存储库:
vim /etc/yum.repos.d/elrepo.repo
九、内核升级后也可以使用 yum 安装
[root@k8s ~]# yum install -y bcc-tools
[root@k8s ~]## echo 'export PATH=$PATH:/usr/share/bcc/tools' > /etc/profile.d/bcc-tools.sh
[root@k8s ~]# . /etc/profile.d/bcc-tools.sh复制
十、使用
[root@k8s ~]# cachestat 1 5
HITS MISSES DIRTIES HITRATIO BUFFERS_MB CACHED_MB
239 0 311 100.00% 0 34865
7847 0 173 100.00% 0 34865
5752 0 176 100.00% 0 34866
141 0 190 100.00% 0 34866
1425 0 230 100.00% 0 34866
[root@k8s ~]#复制
cachetop 显示如下:
内存泄漏的工具 memleak,可以跟踪系统或指定进程的内存分配、释放请求,然后定期输出一个未释放内存和相应调用栈的汇总情况(默认 5 秒)。
memleak -a -p <PID>
复制
总结
提供两种安装方式,不过源码编译安装过程中,会出现问题,这里简单记录下,方便下次使用。bcc-tools,提供几个常用工具如:cachestat 系统缓存命中率查看工具、cachetop 进程缓存命中率查看工具、memleak 内存泄露检测工具。
文章转载自Linux点滴运维实践,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
export CFLAGS=-I${HOME}/build/linux-4.9.71/usr/include
这个命令不对吧?
22天前

评论
相关阅读
55.HarmonyOS NEXT 登录模块开发教程(九):部署与发布
若城
165次阅读
2025-03-13 21:13:14
演讲实录 | MaxCompute 智能物化视图
阿里云大数据AI技术
104次阅读
2025-02-28 13:47:15
降价46%,Hologres Serverless Computing 快速入门
阿里云大数据AI技术
91次阅读
2025-03-11 10:42:00
Pigsty v3.3 发布:扩展遥遥领先,丝滑建站体验,Dify, Supabase, Odoo一键自建
非法加冯
38次阅读
2025-02-26 10:02:33
Autodesk AutoCAD 2025(cad2025设计绘图软件)v2025.1中文破解版安装教程
白衣衫
33次阅读
2025-02-28 11:24:14
适用于Mac的文件浏览和管理软件 Path Finder for Mac中文版
一梦江湖远
32次阅读
2025-03-06 09:47:22
“.chewbac勒索病毒”来袭:如何识别与防范?
weixin_shuju315
32次阅读
2025-03-01 21:44:52
CrossOver25震撼发布。一文带你了解CrossOver25都做了哪些重磅更新
墨上花开
31次阅读
2025-03-15 16:26:58
永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
...
30次阅读
2025-02-27 09:59:22
RAR Extractor - Unzip for mac(强大的解压缩软件)12.6.0激活版
一梦江湖远
29次阅读
2025-02-25 17:26:25