k8s安装读取内核modules_centos7 安装 bcctools 软件包

一、升级内核

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.gitcd netperf
./configuremakemake 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/includemkdir bcc-buildcd bcc-build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr ../bccmake -j $THREADSmake 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
    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 ""))
Exception: Failed to compile BPF module
[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

7a6c5acba96e999f3e9887f9a0e15ae2.png

九、内核升级后也可以使用 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 显示如下:

8406509ad8eab87246fdc878988faad8.png

内存泄漏的工具 memleak,可以跟踪系统或指定进程的内存分配、释放请求,然后定期输出一个未释放内存和相应调用栈的汇总情况(默认 5 秒)。

memleak -a -p 

总结

提供两种安装方式,不过源码编译安装过程中,会出现问题,这里简单记录下,方便下次使用。bcc-tools,提供几个常用工具如:cachestat 系统缓存命中率查看工具、cachetop 进程缓存命中率查看工具、memleak 内存泄露检测工具。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值