下载 golang 压缩包
wget https://dl.google.com/go/go1.16.3.linux-amd64.tar.gz
配置环境变量
mkdir /root/go
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export GOPATH=/root/go" >> /etc/profile
echo "export GO111MODULE=on" >> /etc/profile
echo "export PATH=$PATH:$GOPATH/bin" >> /etc/profile
source /etc/profile
安装
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 根据提示选择默认配置:1
配置环境变量
source $HOME/.cargo/env
创建config文件,配置rust加速源
[~]# cat $HOME/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
** rust 安装依赖(重要)**
安装依赖 x86_64-unknown-linux-musl
,不然后续编译 agent 时会失败
rustup target add x86_64-unknown-linux-musl
mkdir -p $GOPATH/src/github.com/kata-containers
cd $GOPATH/src/github.com/kata-containers/kata-containers
git clone [email protected]:kata-containers/kata-containers.git
在 kata-containers 顶层目录下 执行
make build-all
此步骤会编译
- 二进制可执行文件
- kata-runtime
- containerd-shim-kata-v2
- kata-monitor
- kata-netmon
- configuration.toml 文件
cd $GOPATH/src/github.com/kata-containers/kata-containers/src/runtime
make
用于在 Goland IDE 中查看引用关系
rust 语言
cd $GOPATH/src/github.com/kata-containers/kata-containers/src/libs/protocols
cargo clean
cargo build
# 结果生成在 $GOPATH/src/github.com/kata-containers/kata-containers/src/libs/protocols/src
go 语言
cd $GOPATH/src/github.com/kata-containers/kata-containers/src/agent
make generate-protocols
cd $GOPATH/src/github.com/kata-containers/kata-containers/src/agent
make
export distro=centos # 可选项 alpine, centos, clearlinux, debian, euleros, fedora, suse, ubuntu
export ROOTFS_DIR=${GOPATH}/src/github.com/kata-containers/kata-containers/tools/osbuilder/rootfs-builder/rootfs
sudo rm -rf ${ROOTFS_DIR}
cd $GOPATH/src/github.com/kata-containers/kata-containers/tools/osbuilder/rootfs-builder
script -fec 'sudo -E USE_DOCKER=true SECCOMP=no EXTRA_PKGS="bash coreutils" ./rootfs.sh ${distro}'
# EXTRA_PKGS 为需要打包到rootfs 中的二进制, coreutils 为 包含 bash,kata exec 进入 console 用的
# 最新版本已经默认加了 coreustils 了
cd $GOPATH/src/github.com/kata-containers/kata-containers/tools/osbuilder/image-builder
script -fec 'sudo -E USE_DOCKER=true ./image_builder.sh ${ROOTFS_DIR}'
# 部分 rootfs 构建时需要下载对应的安装包,需要代理
# export http_proxy=xxx https_proxy= xxx
cd $GOPATH/src/github.com/kata-containers/kata-containers/tools/osbuilder/
make clean # 清除上次构建结果
make DISTRO=ubuntu \
OS_VERSION=10.10 \
EXTRA_PKGS="chrony xfsprogs strace lsof nfs-common binutils ipvsadm ethtool e2fsprogs netcat tcpdump iproute2 net-tools telnet iputils-ping" \
USE_DOCKER=true image