Home | History | Annotate | Download | only in bcc
      1 # Installing BCC
      2 
      3 * [Kernel Configuration](#kernel-configuration)
      4 * [Packages](#packages)
      5   - [Ubuntu](#ubuntu---binary)
      6   - [Fedora](#fedora---binary)
      7   - [Arch](#arch---aur)
      8   - [Gentoo](#gentoo---portage)
      9   - [openSUSE](#opensuse---binary)
     10   - [RHEL](#redhat---binary)
     11 * [Source](#source)
     12   - [Debian](#debian---source)
     13   - [Ubuntu](#ubuntu---source)
     14   - [Fedora](#fedora---source)
     15   - [openSUSE](#opensuse---source)
     16   - [Amazon Linux](#amazon-linux---source)
     17 * [Older Instructions](#older-instructions)
     18 
     19 ## Kernel Configuration
     20 
     21 In general, to use these features, a Linux kernel version 4.1 or newer is
     22 required. In addition, the kernel should have been compiled with the following
     23 flags set:
     24 
     25 ```
     26 CONFIG_BPF=y
     27 CONFIG_BPF_SYSCALL=y
     28 # [optional, for tc filters]
     29 CONFIG_NET_CLS_BPF=m
     30 # [optional, for tc actions]
     31 CONFIG_NET_ACT_BPF=m
     32 CONFIG_BPF_JIT=y
     33 CONFIG_HAVE_BPF_JIT=y
     34 # [optional, for kprobes]
     35 CONFIG_BPF_EVENTS=y
     36 ```
     37 
     38 There are a few optional kernel flags needed for running bcc networking examples on vanilla kernel:
     39 
     40 ```
     41 CONFIG_NET_SCH_SFQ=m
     42 CONFIG_NET_ACT_POLICE=m
     43 CONFIG_NET_ACT_GACT=m
     44 CONFIG_DUMMY=m
     45 CONFIG_VXLAN=m
     46 ```
     47 
     48 Kernel compile flags can usually be checked by looking at `/proc/config.gz` or
     49 `/boot/config-<kernel-version>`.
     50 
     51 # Packages
     52 
     53 ## Ubuntu - Binary
     54 
     55 The stable and the nightly packages are built for Ubuntu Xenial (16.04), Ubuntu Artful (17.10) and Ubuntu Bionic (18.04). The steps are very straightforward, no need to upgrade the kernel or compile from source!
     56 
     57 **Stable and Signed Packages**
     58 
     59 ```bash
     60 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
     61 echo "deb https://repo.iovisor.org/apt/xenial xenial main" | sudo tee /etc/apt/sources.list.d/iovisor.list
     62 sudo apt-get update
     63 sudo apt-get install bcc-tools libbcc-examples linux-headers-$(uname -r)
     64 ```
     65 (replace `xenial` with `artful` or `bionic` as appropriate)
     66 
     67 **Nightly Packages**
     68 
     69 ```bash
     70 echo "deb [trusted=yes] https://repo.iovisor.org/apt/xenial xenial-nightly main" | sudo tee /etc/apt/sources.list.d/iovisor.list
     71 sudo apt-get update
     72 sudo apt-get install bcc-tools libbcc-examples linux-headers-$(uname -r)
     73 ```
     74 (replace `xenial` with `artful` or `bionic` as appropriate)
     75 
     76 ## Fedora - Binary
     77 
     78 Ensure that you are running a 4.2+ kernel with `uname -r`. If not, install a 4.2+ kernel from
     79 http://alt.fedoraproject.org/pub/alt/rawhide-kernel-nodebug, for example:
     80 
     81 ```bash
     82 sudo dnf config-manager --add-repo=http://alt.fedoraproject.org/pub/alt/rawhide-kernel-nodebug/fedora-rawhide-kernel-nodebug.repo
     83 sudo dnf update
     84 # reboot
     85 ```
     86 
     87 **Nightly Packages**
     88 
     89 Nightly bcc binary packages for Fedora 25, 26, 27, and 28 are hosted at
     90 `https://repo.iovisor.org/yum/nightly/f{25,26,27}`.
     91 
     92 To install:
     93 ```bash
     94 echo -e '[iovisor]\nbaseurl=https://repo.iovisor.org/yum/nightly/f27/$basearch\nenabled=1\ngpgcheck=0' | sudo tee /etc/yum.repos.d/iovisor.repo
     95 sudo dnf install bcc-tools kernel-headers kernel-devel
     96 ```
     97 
     98 **Stable and Signed Packages**
     99 
    100 Stable bcc binary packages for Fedora 25, 26, 27, and 28 are hosted at
    101 `https://repo.iovisor.org/yum/main/f{25,26,27}`.
    102 
    103 ```bash
    104 echo -e '[iovisor]\nbaseurl=https://repo.iovisor.org/yum/main/f27/$basearch\nenabled=1' | sudo tee /etc/yum.repos.d/iovisor.repo
    105 sudo dnf install bcc-tools kernel-devel-$(uname -r) kernel-headers-$(uname -r)
    106 ```
    107 
    108 ## Arch - AUR
    109 
    110 Upgrade the kernel to minimum 4.3.1-1 first; the ```CONFIG_BPF_SYSCALL=y``` configuration was not added until [this kernel release](https://bugs.archlinux.org/task/47008).
    111 
    112 Install these packages using any AUR helper such as [pacaur](https://aur.archlinux.org/packages/pacaur), [yaourt](https://aur.archlinux.org/packages/yaourt), [cower](https://aur.archlinux.org/packages/cower), etc.:
    113 ```
    114 bcc bcc-tools python-bcc python2-bcc
    115 ```
    116 All build and install dependencies are listed [in the PKGBUILD](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=bcc) and should install automatically.
    117 
    118 ## Gentoo - Portage
    119 
    120 First of all, upgrade the kernel of your choice to a recent version. For example:
    121 ```
    122 emerge sys-kernel/gentoo-sources
    123 ```
    124 Then, configure the kernel enabling the features you need. Please consider the following as a starting point:
    125 ```
    126 CONFIG_BPF=y
    127 CONFIG_BPF_SYSCALL=y
    128 CONFIG_NET_CLS_BPF=m
    129 CONFIG_NET_ACT_BPF=m
    130 CONFIG_BPF_JIT=y
    131 CONFIG_BPF_EVENTS=y
    132 ```
    133 Finally, you can install bcc with:
    134 ```
    135 emerge dev-util/bcc
    136 ```
    137 The appropriate dependencies (e.g., ```clang```, ```llvm``` with BPF backend) will be pulled automatically.
    138 
    139 ## openSUSE - Binary
    140 
    141 For openSUSE Leap 42.2 (and later) and Tumbleweed, bcc is already included in the official repo. Just install
    142 the packages with zypper.
    143 
    144 ```bash
    145 sudo zypper ref
    146 sudo zypper in bcc-tools bcc-examples
    147 ```
    148 
    149 ## RHEL - Binary
    150 
    151 For Redhat 7.6 (Beta) bcc is already included in the official yum repository as bcc-tools. As part of the install the following dependencies are installed: bcc.x86_64 0:0.6.0-3.el7 ,llvm-private.x86_64 0:6.0.1-2.el7 ,python-bcc.x86_64 0:0.6.0-3.el7,python-netaddr.noarch 0:0.7.5-9.el7
    152 
    153 ```
    154 yum install bcc-tools
    155 ```
    156 
    157 # Source
    158 
    159 ## Debian - Source
    160 ### Jessie
    161 #### Repositories
    162 
    163 The automated tests that run as part of the build process require `netperf`.  Since netperf's license is not "certified"
    164 as an open-source license, it is in Debian's `non-free` repository.
    165 
    166 `/etc/apt/sources.list` should include the `non-free` repository and look something like this:
    167 
    168 ```
    169 deb http://httpredir.debian.org/debian/ jessie main non-free
    170 deb-src http://httpredir.debian.org/debian/ jessie main non-free
    171 
    172 deb http://security.debian.org/ jessie/updates main non-free
    173 deb-src http://security.debian.org/ jessie/updates main non-free
    174 
    175 # wheezy-updates, previously known as 'volatile'
    176 deb http://ftp.us.debian.org/debian/ jessie-updates main non-free
    177 deb-src http://ftp.us.debian.org/debian/ jessie-updates main non-free
    178 ```
    179 
    180 BCC also requires kernel version 4.1 or above.  Those kernels are available in the `jessie-backports` repository.  To
    181 add the `jessie-backports` repository to your system create the file `/etc/apt/sources.list.d/jessie-backports.list`
    182 with the following contents:
    183 
    184 ```
    185 deb http://httpredir.debian.org/debian jessie-backports main
    186 deb-src http://httpredir.debian.org/debian jessie-backports main
    187 ```
    188 
    189 #### Install Build Dependencies
    190 
    191 Note, check for the latest `linux-image-4.x` version in `jessie-backports` before proceeding.  Also, have a look at the
    192 `Build-Depends:` section in `debian/control` file.
    193 
    194 ```
    195 # Before you begin
    196 apt-get update
    197 
    198 # Update kernel and linux-base package
    199 apt-get -t jessie-backports install linux-base linux-image-4.9.0-0.bpo.2-amd64 linux-headers-4.9.0-0.bpo.2-amd64
    200 
    201 # BCC build dependencies:
    202 apt-get install debhelper cmake libllvm3.8 llvm-3.8-dev libclang-3.8-dev \
    203   libelf-dev bison flex libedit-dev clang-format-3.8 python python-netaddr \
    204   python-pyroute2 luajit libluajit-5.1-dev arping iperf netperf ethtool \
    205   devscripts zlib1g-dev libfl-dev
    206 ```
    207 
    208 #### Sudo
    209 
    210 Adding eBPF probes to the kernel and removing probes from it requires root privileges.  For the build to complete
    211 successfully, you must build from an account with `sudo` access.  (You may also build as root, but it is bad style.)
    212 
    213 `/etc/sudoers` or `/etc/sudoers.d/build-user` should contain
    214 
    215 ```
    216 build-user ALL = (ALL) NOPASSWD: ALL
    217 ```
    218 
    219 or
    220 
    221 ```
    222 build-user ALL = (ALL) ALL
    223 ```
    224 
    225 If using the latter sudoers configuration, please keep an eye out for sudo's password prompt while the build is running.
    226 
    227 #### Build
    228 
    229 ```
    230 cd <preferred development directory>
    231 git clone https://github.com/iovisor/bcc.git
    232 cd bcc
    233 debuild -b -uc -us
    234 ```
    235 
    236 #### Install
    237 
    238 ```
    239 cd ..
    240 sudo dpkg -i *bcc*.deb
    241 ```
    242 
    243 ## Ubuntu - Source
    244 
    245 To build the toolchain from source, one needs:
    246 * LLVM 3.7.1 or newer, compiled with BPF support (default=on)
    247 * Clang, built from the same tree as LLVM
    248 * cmake (>=3.1), gcc (>=4.7), flex, bison
    249 * LuaJIT, if you want Lua support
    250 
    251 ### Install build dependencies
    252 ```
    253 # Trusty and older
    254 VER=trusty
    255 echo "deb http://llvm.org/apt/$VER/ llvm-toolchain-$VER-3.7 main
    256 deb-src http://llvm.org/apt/$VER/ llvm-toolchain-$VER-3.7 main" | \
    257   sudo tee /etc/apt/sources.list.d/llvm.list
    258 wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
    259 sudo apt-get update
    260 
    261 # All versions
    262 sudo apt-get -y install bison build-essential cmake flex git libedit-dev \
    263   libllvm3.7 llvm-3.7-dev libclang-3.7-dev python zlib1g-dev libelf-dev
    264 
    265 # For Lua support
    266 sudo apt-get -y install luajit luajit-5.1-dev
    267 ```
    268 
    269 ### Install and compile BCC
    270 ```
    271 git clone https://github.com/iovisor/bcc.git
    272 mkdir bcc/build; cd bcc/build
    273 cmake .. -DCMAKE_INSTALL_PREFIX=/usr
    274 make
    275 sudo make install
    276 ```
    277 
    278 ## Fedora - Source
    279 
    280 ### Install build dependencies
    281 
    282 ```
    283 sudo dnf install -y bison cmake ethtool flex git iperf libstdc++-static \
    284   python-netaddr python-pip gcc gcc-c++ make zlib-devel \
    285   elfutils-libelf-devel
    286 sudo dnf install -y luajit luajit-devel  # for Lua support
    287 sudo dnf install -y \
    288   http://repo.iovisor.org/yum/extra/mageia/cauldron/x86_64/netperf-2.7.0-1.mga6.x86_64.rpm
    289 sudo pip install pyroute2
    290 ```
    291 
    292 ### Install binary clang
    293 
    294 ```
    295 # FC22
    296 wget http://llvm.org/releases/3.7.1/clang+llvm-3.7.1-x86_64-fedora22.tar.xz
    297 sudo tar xf clang+llvm-3.7.1-x86_64-fedora22.tar.xz -C /usr/local --strip 1
    298 
    299 # FC23
    300 wget http://llvm.org/releases/3.9.0/clang+llvm-3.9.0-x86_64-fedora23.tar.xz
    301 sudo tar xf clang+llvm-3.9.0-x86_64-fedora23.tar.xz -C /usr/local --strip 1
    302 
    303 # FC24 and FC25
    304 sudo dnf install -y clang clang-devel llvm llvm-devel llvm-static ncurses-devel
    305 ```
    306 
    307 ### Install and compile BCC
    308 ```
    309 git clone https://github.com/iovisor/bcc.git
    310 mkdir bcc/build; cd bcc/build
    311 cmake .. -DCMAKE_INSTALL_PREFIX=/usr
    312 make
    313 sudo make install
    314 ```
    315 
    316 ## openSUSE - Source
    317 
    318 ### Install build dependencies
    319 
    320 ```
    321 sudo zypper in bison cmake flex gcc gcc-c++ git libelf-devel libstdc++-devel \
    322   llvm-devel clang-devel pkg-config python-devel python-setuptools python3-devel \
    323   python3-setuptools
    324 sudo zypper in luajit-devel       # for lua support in openSUSE Leap 42.2 or later
    325 sudo zypper in lua51-luajit-devel # for lua support in openSUSE Tumbleweed
    326 ```
    327 
    328 ### Install and compile BCC
    329 ```
    330 git clone https://github.com/iovisor/bcc.git
    331 mkdir bcc/build; cd bcc/build
    332 cmake -DCMAKE_INSTALL_PREFIX=/usr \
    333       -DLUAJIT_INCLUDE_DIR=`pkg-config --variable=includedir luajit` \ # for lua support
    334       ..
    335 make
    336 sudo make install
    337 cmake -DPYTHON_CMD=python3 .. # build python3 binding
    338 pushd src/python/
    339 make
    340 sudo make install
    341 popd
    342 ```
    343 
    344 ## Amazon Linux - Source
    345 
    346 Tested on Amazon Linux AMI release 2018.03 (kernel 4.14.47-56.37.amzn1.x86_64)
    347 
    348 ### Install packages required for building
    349 ```
    350 # enable epel to get iperf, luajit, luajit-devel, cmake3 (cmake3 is required to support c++11) 
    351 sudo yum-config-manager --enable epel
    352 
    353 sudo yum install -y bison cmake3 ethtool flex git iperf libstdc++-static python-netaddr gcc gcc-c++ make zlib-devel elfutils-libelf-devel
    354 sudo yum install -y luajit luajit-devel
    355 sudo yum install -y http://repo.iovisor.org/yum/extra/mageia/cauldron/x86_64/netperf-2.7.0-1.mga6.x86_64.rpm
    356 sudo pip install pyroute2
    357 sudo yum install -y ncurses-devel
    358 ```
    359 
    360 ### Install clang 3.7.1 pre-built binaries
    361 ```
    362 wget http://releases.llvm.org/3.7.1/clang+llvm-3.7.1-x86_64-fedora22.tar.xz
    363 tar xf clang*
    364 (cd clang* && sudo cp -R * /usr/local/)
    365 ```
    366 
    367 ### Build bcc
    368 ```
    369 git clone https://github.com/iovisor/bcc.git
    370 pushd .
    371 mkdir bcc/build; cd bcc/build
    372 cmake3 .. -DCMAKE_INSTALL_PREFIX=/usr
    373 time make
    374 sudo make install
    375 popd
    376 ```
    377 
    378 ### Setup required to run the tools
    379 ```
    380 sudo yum -y install kernel-devel-$(uname -r)
    381 sudo mount -t debugfs debugfs /sys/kernel/debug
    382 ```
    383 
    384 ### Test
    385 ```
    386 sudo /usr/share/bcc/tools/execsnoop
    387 ```
    388 
    389 # Older Instructions
    390 
    391 ## Build LLVM and Clang development libs
    392 
    393 ```
    394 git clone http://llvm.org/git/llvm.git
    395 cd llvm/tools; git clone http://llvm.org/git/clang.git
    396 cd ..; mkdir -p build/install; cd build
    397 cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
    398   -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install ..
    399 make
    400 make install
    401 export PATH=$PWD/install/bin:$PATH
    402 ```
    403