Ubuntu安裝BCC


Ubuntu安裝BCC

教程

官方文檔

安裝

這里官方文檔中首先講到的是二進制文件的安裝,直接通過apt進行安裝

sudo apt-get install bpfcc-tools linux-headers-$(uname -r)

這里安裝好后,對於/usr/sbin目錄下的部分工具,使用時會報編譯錯誤,無法編譯BPF代碼

對於低版本的類型的Ubuntu系統,通過以下方式,可以實現安裝,並成功使用

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
echo "deb https://repo.iovisor.org/apt/$(lsb_release -cs) $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/iovisor.list
sudo apt-get update
sudo apt-get install bcc-tools libbcc-examples linux-headers-$(uname -r)

具體的還需要自行嘗試。

我使用的是最新的Ubuntu 20.04版本,上述方法中的lsb_release -cs在網站中是404,不能安裝。

在官方的GitHub issue里對此提到,推薦的安裝方法是通過源碼進行編譯安裝,因為repo.iovisor.org上的版本老舊,且存在bug。

image-20210801160606970

最后安裝官方教程采用源碼安裝

首先安裝依賴

# Trusty (14.04 LTS) and older
VER=trusty
echo "deb http://llvm.org/apt/$VER/ llvm-toolchain-$VER-3.7 main
deb-src http://llvm.org/apt/$VER/ llvm-toolchain-$VER-3.7 main" | \
  sudo tee /etc/apt/sources.list.d/llvm.list
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update

# For Bionic (18.04 LTS)
sudo apt-get -y install bison build-essential cmake flex git libedit-dev \
  libllvm6.0 llvm-6.0-dev libclang-6.0-dev python zlib1g-dev libelf-dev libfl-dev

# For Eoan (19.10) or Focal (20.04.1 LTS)
sudo apt install -y bison build-essential cmake flex git libedit-dev \
  libllvm7 llvm-7-dev libclang-7-dev python zlib1g-dev libelf-dev libfl-dev

# For other versions
sudo apt-get -y install bison build-essential cmake flex git libedit-dev \
  libllvm3.7 llvm-3.7-dev libclang-3.7-dev python zlib1g-dev libelf-dev

# For Lua support
sudo apt-get -y install luajit luajit-5.1-dev

之后從GitHub克隆代碼,進行安裝

git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
cmake ..
make
sudo make install
cmake -DPYTHON_CMD=python3 .. # build python3 binding
pushd src/python/
make
sudo make install
popd

安裝成功后,在/usr/share/bcc/tools下可以看到官方提供的工具,這里我挑選的是tcptop進行測試

直接輸入tcptop運行

image-20210801161146900

看到抓取到了tcp報文,即成功完成安裝


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM