1. 环境


2. 安装基础软件

yum install -y elfutils-libelf elfutils-libelf-devel elfutils-libs elfutils-default-yama-scope elfutils-libelf-devel gcc wget curl git
yum install -y epel-release
yum install -y cmake3
# 查看 cmake3
cmake3 --version
yum install -y centos-release-scl
yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-11-gcc devtoolset-11-gcc-c++
# 在 /etc/profile 中增加如下内容
source /opt/rh/devtoolset-11/enable

2.1. 实用命令


3. 安装 go 1.21.10、bpf2go v0.14.0

wget https://go.dev/dl/go1.21.10.linux-amd64.tar.gz
tar -xf go1.21.10.linux-amd64.tar.gz
mv go /usr/local/

# 在 /etc/profile 中增加如下内容
export GOROOT=/usr/local/go
export GOPATH=/root/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

source /etc/profile
go env -w GOPROXY=https://goproxy.cn,direct

# 安装 bpf2go
go install github.com/cilium/ebpf/cmd/bpf2go@v0.14.0
bpf2go -h

4. 安装 LLVM 14、Clang 14

wget https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/llvm-project-14.0.0.src.tar.xz
tar -xf llvm-project-14.0.0.src.tar.xz
cd llvm-project-14.0.0.src/llvm/
mkdir build/
cd build/
cmake3 .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lld"
make && make install

5. 安装 libbpf、bpftool

git clone --recursive https://github.com/libbpf/bpftool
cd bpftool/src/
git checkout v6.8.0
make && make install

git clone https://github.com/libbpf/libbpf
cd libbpf/src/
git checkout v1.2.0
make && make install

参考文档