• bcc安装过程以及遇到的问题


    对于5.15版本的安装

    1. $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
    2. Executing: /tmp/apt-key-gpghome.yKCApS0t8A/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
    3. gpg: 密钥 4052245BD4284CDD:公钥 “Brenden Blanco ” 已导入
    4. gpg: 处理的总数:1
    5. gpg: 已导入:1
    6. $ echo "deb https://repo.iovisor.org/apt/xenial xenial main" | sudo tee /etc/apt/sources.list.d/iovisor.list
    7. deb https://repo.iovisor.org/apt/xenial xenial main
    8. $ sudo apt-get update
    9. 命中:1 http://packages.microsoft.com/repos/code stable InRelease
    10. 命中:2 http://dl.google.com/linux/chrome/deb stable InRelease
    11. 命中:3 http://security.ubuntu.com/ubuntu focal-security InRelease
    12. 命中:4 http://cn.archive.ubuntu.com/ubuntu focal InRelease
    13. 命中:5 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease
    14. 命中:6 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease
    15. 获取:7 https://repo.iovisor.org/apt/xenial xenial InRelease [2,419 B]
    16. 命中:8 http://lenovo.archive.canonical.com focal InRelease
    17. 获取:9 https://repo.iovisor.org/apt/xenial xenial/main i386 Packages [1,062 B]
    18. 获取:10 https://repo.iovisor.org/apt/xenial xenial/main amd64 Packages [1,197 B]
    19. 已下载 2,259 B,耗时 2秒 (1,050 B/s)
    20. 正在读取软件包列表... 完成
    21. $ sudo apt-get install -y bcc-tools libbcc-examples linux-headers-$(uname -r)
    22. 正在读取软件包列表... 完成
    23. 正在分析软件包的依赖关系树
    24. 正在读取状态信息... 完成
    25. linux-headers-5.15.0-46-generic 已经是最新版 (5.15.0-46.49~20.04.1)。
    26. linux-headers-5.15.0-46-generic 已设置为手动安装。
    27. 将会同时安装下列软件:
    28. libbcc python-bcc
    29. 下列【新】软件包将被安装:
    30. bcc-tools libbcc libbcc-examples python-bcc
    31. 升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 29 个软件包未被升级。
    32. 需要下载 12.6 MB 的归档。
    33. 解压缩后会消耗 45.2 MB 的额外空间。
    34. 获取:1 https://repo.iovisor.org/apt/xenial xenial/main amd64 libbcc all 0.10.0-1 [11.9 MB]
    35. 获取:2 https://repo.iovisor.org/apt/xenial xenial/main amd64 python-bcc all 0.10.0-1 [30.8 kB]
    36. 获取:3 https://repo.iovisor.org/apt/xenial xenial/main amd64 bcc-tools all 0.10.0-1 [356 kB]
    37. 获取:4 https://repo.iovisor.org/apt/xenial xenial/main amd64 libbcc-examples amd64 0.10.0-1 [278 kB]
    38. 已下载 12.6 MB,耗时 4分 15秒 (49.3 kB/s)
    39. 正在选中未选择的软件包 libbcc。
    40. (正在读取数据库 ... 系统当前共安装有 279008 个文件和目录。)
    41. 准备解压 .../libbcc_0.10.0-1_all.deb ...
    42. 正在解压 libbcc (0.10.0-1) ...
    43. 正在选中未选择的软件包 python-bcc。
    44. 准备解压 .../python-bcc_0.10.0-1_all.deb ...
    45. 正在解压 python-bcc (0.10.0-1) ...
    46. 正在选中未选择的软件包 bcc-tools。
    47. 准备解压 .../bcc-tools_0.10.0-1_all.deb ...
    48. 正在解压 bcc-tools (0.10.0-1) ...
    49. 正在选中未选择的软件包 libbcc-examples。
    50. 准备解压 .../libbcc-examples_0.10.0-1_amd64.deb ...
    51. 正在解压 libbcc-examples (0.10.0-1) ...
    52. 正在设置 libbcc (0.10.0-1) ...
    53. 正在设置 python-bcc (0.10.0-1) ...
    54. 正在设置 libbcc-examples (0.10.0-1) ...
    55. 正在设置 bcc-tools (0.10.0-1) ...
    56. 正在处理用于 libc-bin (2.31-0ubuntu9.9) 的触发器 ...
    57. $ bcc
    58. Command 'bcc' not found, but can be installed with:
    59. sudo apt install bcc
    60. $ cachestat
    61. Command 'cachestat' not found, did you mean:
    62. command 'cachestats' from deb nocache (1.1-1)
    63. Try: sudo apt install
    64. $ export PATH=$PATH:/usr/share/bcc/tools
    65. $ cachestat
    66. Traceback (most recent call last):
    67. File "/usr/share/bcc/tools/cachestat", line 21, in
    68. from bcc import BPF
    69. File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 27, in
    70. from .libbcc import lib, bcc_symbol, bcc_symbol_option, bcc_stacktrace_build_id, _SYM_CB_TYPE
    71. File "/usr/lib/python2.7/dist-packages/bcc/libbcc.py", line 17, in
    72. lib = ct.CDLL("libbcc.so.0", use_errno=True)
    73. File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
    74. self._handle = _dlopen(self._name, mode)
    75. OSError: libtinfo.so.5: cannot open shared object file: No such file or directory
    76. $ sudo -i
    77. ~# export PATH=$PATH:/usr/share/bcc/tools
    78. ~# cachestat
    79. Traceback (most recent call last):
    80. File "/usr/share/bcc/tools/cachestat", line 21, in
    81. from bcc import BPF
    82. File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 27, in
    83. from .libbcc import lib, bcc_symbol, bcc_symbol_option, bcc_stacktrace_build_id, _SYM_CB_TYPE
    84. File "/usr/lib/python2.7/dist-packages/bcc/libbcc.py", line 17, in
    85. lib = ct.CDLL("libbcc.so.0", use_errno=True)
    86. File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
    87. self._handle = _dlopen(self._name, mode)
    88. OSError: libtinfo.so.5: cannot open shared object file: No such file or directory
    89. ~# cat /boot/
    90. config-5.15.0-41-generic grub/ initrd.img-5.15.0-46-generic memtest86+.elf System.map-5.15.0-46-generic vmlinuz-5.15.0-46-generic
    91. config-5.15.0-46-generic initrd.img initrd.img.old memtest86+_multiboot.bin vmlinuz vmlinuz.old
    92. efi/ initrd.img-5.15.0-41-generic memtest86+.bin System.map-5.15.0-41-generic vmlinuz-5.15.0-41-generic
    93. ~# cat /boot/config-5.15.0-46-generic | grep BPF
    94. CONFIG_BPF=y
    95. CONFIG_HAVE_EBPF_JIT=y
    96. CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y
    97. # BPF subsystem
    98. CONFIG_BPF_SYSCALL=y
    99. CONFIG_BPF_JIT=y
    100. CONFIG_BPF_JIT_ALWAYS_ON=y
    101. CONFIG_BPF_JIT_DEFAULT_ON=y
    102. CONFIG_BPF_UNPRIV_DEFAULT_OFF=y
    103. # CONFIG_BPF_PRELOAD is not set
    104. CONFIG_BPF_LSM=y
    105. # end of BPF subsystem
    106. CONFIG_CGROUP_BPF=y
    107. CONFIG_IPV6_SEG6_BPF=y
    108. CONFIG_NETFILTER_XT_MATCH_BPF=m
    109. CONFIG_BPFILTER=y
    110. CONFIG_BPFILTER_UMH=m
    111. CONFIG_NET_CLS_BPF=m
    112. CONFIG_NET_ACT_BPF=m
    113. CONFIG_BPF_STREAM_PARSER=y
    114. CONFIG_LWTUNNEL_BPF=y
    115. CONFIG_BPF_EVENTS=y
    116. CONFIG_BPF_KPROBE_OVERRIDE=y
    117. CONFIG_TEST_BPF=m
    118. ~# cachestat 1 3
    119. Traceback (most recent call last):
    120. File "/usr/share/bcc/tools/cachestat", line 21, in
    121. from bcc import BPF
    122. File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 27, in
    123. from .libbcc import lib, bcc_symbol, bcc_symbol_option, bcc_stacktrace_build_id, _SYM_CB_TYPE
    124. File "/usr/lib/python2.7/dist-packages/bcc/libbcc.py", line 17, in
    125. lib = ct.CDLL("libbcc.so.0", use_errno=True)
    126. File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
    127. self._handle = _dlopen(self._name, mode)
    128. OSError: libtinfo.so.5: cannot open shared object file: No such file or directory
    129. ~#

    解决方法

    1. ~# ls /usr/libtinfo*
    2. ls: 无法访问 '/usr/libtinfo*': 没有那个文件或目录
    3. ~# exit
    4. 注销
    5. $ sudo apt-get install libncurses5
    6. 正在读取软件包列表... 完成
    7. 正在分析软件包的依赖关系树
    8. 正在读取状态信息... 完成
    9. 将会同时安装下列软件:
    10. libtinfo5
    11. 下列【新】软件包将被安装:
    12. libncurses5 libtinfo5
    13. 升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 29 个软件包未被升级。
    14. 需要下载 180 kB 的归档。
    15. 解压缩后会消耗 864 kB 的额外空间。
    16. 您希望继续执行吗? [Y/n] y
    17. 获取:1 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 libtinfo5 amd64 6.2-0ubuntu2 [83.0 kB]
    18. 获取:2 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 libncurses5 amd64 6.2-0ubuntu2 [96.9 kB]
    19. 已下载 180 kB,耗时 1秒 (123 kB/s)
    20. 正在选中未选择的软件包 libtinfo5:amd64。
    21. (正在读取数据库 ... 系统当前共安装有 279539 个文件和目录。)
    22. 准备解压 .../libtinfo5_6.2-0ubuntu2_amd64.deb ...
    23. 正在解压 libtinfo5:amd64 (6.2-0ubuntu2) ...
    24. 正在选中未选择的软件包 libncurses5:amd64。
    25. 准备解压 .../libncurses5_6.2-0ubuntu2_amd64.deb ...
    26. 正在解压 libncurses5:amd64 (6.2-0ubuntu2) ...
    27. 正在设置 libtinfo5:amd64 (6.2-0ubuntu2) ...
    28. 正在设置 libncurses5:amd64 (6.2-0ubuntu2) ...
    29. 正在处理用于 libc-bin (2.31-0ubuntu9.9) 的触发器 ...
    30. $ cachestat
    31. In file included from :317:
    32. In file included from <command line>:7:
    33. In file included from /virtual/include/bcc/bpf.h:12:
    34. In file included from include/linux/types.h:6:
    35. In file included from include/uapi/linux/types.h:14:
    36. In file included from ./include/uapi/linux/posix_types.h:5:
    37. In file included from include/linux/stddef.h:5:
    38. In file included from include/uapi/linux/stddef.h:2:
    39. In file included from include/linux/compiler_types.h:80:
    40. include/linux/compiler-clang.h:41:9: warning: '__HAVE_BUILTIN_BSWAP32__' macro redefined [-Wmacro-redefined]
    41. #define __HAVE_BUILTIN_BSWAP32__
    42. ^
    43. <command line>:4:9: note: previous definition is here
    44. #define __HAVE_BUILTIN_BSWAP32__ 1
    45. ^
    46. In file included from :317:
    47. In file included from <command line>:7:
    48. In file included from /virtual/include/bcc/bpf.h:12:
    49. In file included from include/linux/types.h:6:
    50. In file included from include/uapi/linux/types.h:14:
    51. In file included from ./include/uapi/linux/posix_types.h:5:
    52. In file included from include/linux/stddef.h:5:
    53. In file included from include/uapi/linux/stddef.h:2:
    54. In file included from include/linux/compiler_types.h:80:
    55. include/linux/compiler-clang.h:42:9: warning: '__HAVE_BUILTIN_BSWAP64__' macro redefined [-Wmacro-redefined]
    56. #define __HAVE_BUILTIN_BSWAP64__
    57. ^
    58. <command line>:5:9: note: previous definition is here
    59. #define __HAVE_BUILTIN_BSWAP64__ 1
    60. ^
    61. In file included from :317:
    62. In file included from <command line>:7:
    63. In file included from /virtual/include/bcc/bpf.h:12:
    64. In file included from include/linux/types.h:6:
    65. In file included from include/uapi/linux/types.h:14:
    66. In file included from ./include/uapi/linux/posix_types.h:5:
    67. In file included from include/linux/stddef.h:5:
    68. In file included from include/uapi/linux/stddef.h:2:
    69. In file included from include/linux/compiler_types.h:80:
    70. include/linux/compiler-clang.h:43:9: warning: '__HAVE_BUILTIN_BSWAP16__' macro redefined [-Wmacro-redefined]
    71. #define __HAVE_BUILTIN_BSWAP16__
    72. ^
    73. <command line>:3:9: note: previous definition is here
    74. #define __HAVE_BUILTIN_BSWAP16__ 1
    75. ^
    76. In file included from /virtual/main.c:2:
    77. In file included from include/uapi/linux/ptrace.h:153:
    78. In file included from ./arch/x86/include/asm/ptrace.h:5:
    79. ./arch/x86/include/asm/segment.h:255:2: error: expected '(' after 'asm'
    80. alternative_io ("lsl %[seg],%[p]",
    81. ^
    82. ./arch/x86/include/asm/alternative.h:248:2: note: expanded from macro 'alternative_io'
    83. asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
    84. ^
    85. include/linux/compiler_types.h:258:24: note: expanded from macro 'asm_inline'
    86. #define asm_inline asm __inline
    87. ^
    88. 3 warnings and 1 error generated.
    89. Traceback (most recent call last):
    90. File "/usr/share/bcc/tools/cachestat", line 96, in
    91. b = BPF(text=bpf_text)
    92. File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 325, in __init__
    93. raise Exception("Failed to compile BPF text")
    94. Exception: Failed to compile BPF text

    对于4.19版本的安装

    1. rlk@ubuntu:~$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
    2. [sudo] password for rlk:
    3. Executing: /tmp/apt-key-gpghome.mIpNWGNyeE/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
    4. gpg: key 4052245BD4284CDD: "Brenden Blanco " not changed
    5. gpg: Total number processed: 1
    6. gpg: unchanged: 1
    7. rlk@ubuntu:~$ cat /etc/apt/sources.list.d/iovisor.list
    8. deb https://repo.iovisor.org/apt/xenial xenial main
    9. rlk@ubuntu:~$
    10. rlk@ubuntu:~$ sudo apt-get update
    11. Hit:1 http://mirrors.cn99.com/ubuntu bionic InRelease
    12. Hit:2 http://mirrors.cn99.com/ubuntu bionic-updates InRelease
    13. Hit:3 http://mirrors.cn99.com/ubuntu bionic-backports InRelease
    14. Hit:4 http://mirrors.cn99.com/ubuntu bionic-security InRelease
    15. Ign:5 https://repo.iovisor.org/apt/xenial xenial InRelease
    16. Err:6 https://repo.iovisor.org/apt/xenial xenial Release
    17. Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate. Could not handshake: Error in the certificate verification. [IP: 104.199.116.191 443]
    18. Err:7 http://archive.ubuntukylin.com:10006/ubuntukylin xenial InRelease
    19. Could not connect to archive.ubuntukylin.com:10006 (124.126.103.228). - connect (111: Connection refused)
    20. Err:8 http://archive.ubuntukylin.com:10006/ubuntukylin bionic InRelease
    21. Unable to connect to archive.ubuntukylin.com:10006:
    22. Reading package lists... Done
    23. E: The repository 'https://repo.iovisor.org/apt/xenial xenial Release' does not have a Release file.
    24. N: Updating from such a repository can't be done securely, and is therefore disabled by default.
    25. N: See apt-secure(8) manpage for repository creation and user configuration details.

    解决方法

    将 https://repo.iovisor.org/apt/xenial xenial InRelease的https 修改为 http

    去掉 http://archive.ubuntukylin.com:10006/ubuntukylin

    再来一遍

    1. root@ubuntu:apt# apt update
    2. Hit:1 http://mirrors.cn99.com/ubuntu bionic InRelease
    3. Hit:2 http://mirrors.cn99.com/ubuntu bionic-updates InRelease
    4. Hit:3 http://mirrors.cn99.com/ubuntu bionic-backports InRelease
    5. Hit:4 http://mirrors.cn99.com/ubuntu bionic-security InRelease
    6. Hit:5 http://repo.iovisor.org/apt/xenial xenial InRelease
    7. Reading package lists... Done
    8. Building dependency tree
    9. Reading state information... Done
    10. 723 packages can be upgraded. Run 'apt list --upgradable' to see them.
    11. root@ubuntu:apt# apt-get install -y bcc-tools libbcc-examples
    12. Reading package lists... Done
    13. Building dependency tree
    14. Reading state information... Done
    15. The following additional packages will be installed:
    16. libbcc python-bcc
    17. The following NEW packages will be installed:
    18. bcc-tools libbcc libbcc-examples python-bcc
    19. 0 upgraded, 4 newly installed, 0 to remove and 723 not upgraded.
    20. Need to get 12.6 MB of archives.
    21. After this operation, 45.2 MB of additional disk space will be used.
    22. Get:1 http://repo.iovisor.org/apt/xenial xenial/main amd64 libbcc all 0.10.0-1 [11.9 MB]
    23. Get:2 http://repo.iovisor.org/apt/xenial xenial/main amd64 python-bcc all 0.10.0-1 [30.8 kB]
    24. Get:3 http://repo.iovisor.org/apt/xenial xenial/main amd64 bcc-tools all 0.10.0-1 [356 kB]
    25. Get:4 http://repo.iovisor.org/apt/xenial xenial/main amd64 libbcc-examples amd64 0.10.0-1 [278 kB]
    26. Fetched 12.6 MB in 32s (398 kB/s)
    27. Selecting previously unselected package libbcc.
    28. (Reading database ... 275684 files and directories currently installed.)
    29. Preparing to unpack .../libbcc_0.10.0-1_all.deb ...
    30. Unpacking libbcc (0.10.0-1) ...
    31. Selecting previously unselected package python-bcc.
    32. Preparing to unpack .../python-bcc_0.10.0-1_all.deb ...
    33. Unpacking python-bcc (0.10.0-1) ...
    34. Selecting previously unselected package bcc-tools.
    35. Preparing to unpack .../bcc-tools_0.10.0-1_all.deb ...
    36. Unpacking bcc-tools (0.10.0-1) ...
    37. Selecting previously unselected package libbcc-examples.
    38. Preparing to unpack .../libbcc-examples_0.10.0-1_amd64.deb ...
    39. Unpacking libbcc-examples (0.10.0-1) ...
    40. Setting up libbcc (0.10.0-1) ...
    41. Setting up python-bcc (0.10.0-1) ...
    42. Setting up bcc-tools (0.10.0-1) ...
    43. Setting up libbcc-examples (0.10.0-1) ...
    44. Processing triggers for libc-bin (2.27-3ubuntu1) ...

    4.19版本也遇到如下问题的话

    1. rlk@ubuntu:~$ /usr/share/bcc/tools/cachestat
    2. Traceback (most recent call last):
    3. File "/usr/share/bcc/tools/cachestat", line 21, in
    4. from bcc import BPF
    5. ImportError: No module named bcc

    解决方法

    1. root@ubuntu:apt# uname -a
    2. Linux ubuntu 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    3. root@ubuntu:apt#
    4. rlk@ubuntu:~$ ls /usr/src/
    5. linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic
    6. rlk@ubuntu:~$ ls /usr/src/ -l
    7. total 8
    8. drwxr-xr-x 27 root root 4096 Jul 24 2018 linux-headers-4.15.0-29
    9. drwxr-xr-x 8 root root 4096 Jul 24 2018 linux-headers-4.15.0-29-generic
    10. rlk@ubuntu:~$ uname -a
    11. Linux ubuntu 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    12. rlk@ubuntu:~$ sudo -i
    13. root@ubuntu:~# mkdir /usr/src/kernel
    14. root@ubuntu:~# mkdir /usr/src/kernels
    15. root@ubuntu:~# rm -rf /usr/src/kernel
    16. root@ubuntu:~# ln -s /usr/src/linux-headers-4.15.0-29-generic /usr/src/kernels/linux-headers-4.15.0-29-generic
    17. root@ubuntu:~# ls /usr/src/kernels/
    18. linux-headers-4.15.0-29-generic
    19. root@ubuntu:~# /usr/share/bcc/tools/cachestat

    开始运行

    1. root@ubuntu:apt# usr/share/bcc/tools/cachestat
    2. -bash: usr/share/bcc/tools/cachestat: No such file or directory
    3. root@ubuntu:apt# /usr/share/bcc/tools/cachestat
    4. HITS MISSES DIRTIES HITRATIO BUFFERS_MB CACHED_MB
    5. 11632 0 837 100.00% 56 1148
    6. 4549 0 809 100.00% 56 1148
    7. 46702 0 5 100.00% 56 1148
    8. 3 0 0 100.00% 56 1148
    9. 0 0 8 0.00% 56 1148
    10. 3 0 0 100.00% 56 1148
    11. 3 0 0 100.00% 56 1148
    12. 3 0 0 100.00% 56 1148
    13. 3 0 0 100.00% 56 1148

    ubuntu 缺少 libtinfo.so.5 问题
    https://blog.csdn.net/lsqtzj/article/details/108553576

    执行/usr/share/bcc/tools/filetop -C报错Exception: Failed to compile BPF module 
    https://blog.csdn.net/liuqiuxiu/article/details/108421958

    Could not connect to archive.ubuntukylin.com:10006 (120.240.95.35), connection timed out
    https://blog.csdn.net/shanpenghui/article/details/108552367

    ImportError: No module named 通用解决方法
    https://blog.csdn.net/jdbc/article/details/80351833

  • 相关阅读:
    IE停止维护 导致 @vue/cli-plugin-babel 编译失败
    开发工程师必备————【Day15】python操作Mysql及SQL语法补充
    javaee spring aop 注解实现
    redis-benchmark工具学习笔记
    一个菜鸟管理的学习和思考(一)
    关于C#导出Word时报错“{00020970-0000-0000-C000-000000000046}加载类型库/DLL 时出错”的解决办法
    哈夫曼树的递归打印不能实现
    软件教程 | Jupyter&stata之stata_kernel攻略
    Torch not compiled with CUDA enabled
    参加了个算法比赛,真是一言难尽啊
  • 原文地址:https://blog.csdn.net/shipinsky/article/details/126894469