1.yum安装
1.1.获取阿里云YUM源
[root@centos]# wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1.2.查看YUM源中Containerd软件
[root@centos]# yum list | grep containerd
containerd.io.x86_64 1.4.12-3.1.el7 docker-ce-stable
1.3.使用yum命令安装
安装Containerd.io软件,即可安装Containerd
[root@centos]# yum -y install containerd.io
1.4.验证安装及启动服务
使用rpm -qa命令查看是否安装
[root@centos]# rpm -qa | grep containerd
1.5.设置containerd服务启动及开机自启
[root@centos]# systemctl enable containerd
[root@centos]# systemctl start containerd
1.6.查看containerd服务状态
[root@centos]# systemctl status containerd
1.7.验证是否可用
[root@centos]# ctr version
Client:
Version: 1.4.12
Server:
Version: 1.4.12
2.二进制安装
2.1.下载Containerd安装包
[root@centos]# wget https://github.com/containerd/containerd/releases/download/v1.6.0/cri-containerd-cni-1.6.0-linux-amd64.tar.gz
2.2.安装containerd
查看获取的安装包
[root@centos]# ls
cri-containerd-cni-1.6.0-linux-amd64.tar.gz
解压下载的软件包
[root@centos]# tar xf cri-containerd-cni-1.6.0-linux-amd64.tar.gz
查看解压后目录
[root@centos]# ls
etc opt usr
查看etc目录
[root@centos]# ls etc/systemd/system/
containerd.service
查看opt目录
[root@centos]# ls opt/containerd/cluster/gce
cloud-init cni.template configure.sh env
查看usr目录
[root@centos]# ls usr/local/sbin
runc
2.3.查看containerd安装位置
[root@centos]# cat etc/systemd/system/containerd.service
......
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd 查看此位置,把containerd二进制文件放置于此处即可完成安装。
2.4.复制containerd运行时文件至系统
查看宿主机/usr/local/bin目录,里面没有任何内容。
[root@centos]# ls /usr/local/bin/
查看解压后usr/local/bin目录,里面包含containerd运行时文件
[root@centos]# ls usr/local/bin/
containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 containerd-stress crictl critest ctd-decoder ctr
复制containerd文件至/usr/local/bin目录中。
[root@centos]# cp usr/local/bin/containerd /usr/local/bin/
[root@centos]# ls /usr/local/bin/
containerd
2.5.添加containerd.service文件至系统
查看解压后的etc/system目录
[root@centos]# ls etc/systemd/system/
containerd.service
复制containerd服务管理配置文件至/usr/lib/systemd/system/目录中
[root@centos]# cp etc/systemd/system/containerd.service /usr/lib/systemd/system/containerd.service
查看复制后结果
[root@centos]# ls /usr/lib/systemd/system/containerd.service
/usr/lib/systemd/system/containerd.service
2.6.查看containerd使用帮助
[root@centos]# containerd --help
2.7.生成containerd模块配置文件
创建配置文件目录
[root@centos]# mkdir /etc/containerd
生成配置文件
[root@centos]# containerd config default > /etc/containerd/config.toml
替换配置文件
[root@centos]# cat /etc/containerd/config.toml
root = "/var/lib/containerd"
state = "/run/containerd"
oom_score = -999
[grpc]
address = "/run/containerd/containerd.sock"
uid = 0
gid = 0
max_recv_message_size = 16777216
max_send_message_size = 16777216
[debug]
address = ""
uid = 0
gid = 0
level = ""
[metrics]
address = ""
grpc_histogram = false
[cgroup]
path = ""
[plugins]
[plugins.cgroups]
no_prometheus = false
[plugins.cri]
stream_server_address = "127.0.0.1"
stream_server_port = "0"
enable_selinux = false
sandbox_image = "easzlab/pause-amd64:3.2"
stats_collect_period = 10
systemd_cgroup = false
enable_tls_streaming = false
max_container_log_line_size = 16384
[plugins.cri.containerd]
snapshotter = "overlayfs"
no_pivot = false
[plugins.cri.containerd.default_runtime]
runtime_type = "io.containerd.runtime.v1.linux"
runtime_engine = ""
runtime_root = ""
[plugins.cri.containerd.untrusted_workload_runtime]
runtime_type = ""
runtime_engine = ""
runtime_root = ""
[plugins.cri.cni]
bin_dir = "/opt/kube/bin"
conf_dir = "/etc/cni/net.d"
conf_template = "/etc/cni/net.d/10-default.conf"
[plugins.cri.registry]
[plugins.cri.registry.mirrors]
[plugins.cri.registry.mirrors."docker.io"]
endpoint = [
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
]
[plugins.cri.registry.mirrors."gcr.io"]
endpoint = [
"https://gcr.mirrors.ustc.edu.cn"
]
[plugins.cri.registry.mirrors."k8s.gcr.io"]
endpoint = [
"https://gcr.mirrors.ustc.edu.cn/google-containers/"
]
[plugins.cri.registry.mirrors."quay.io"]
endpoint = [
"https://quay.mirrors.ustc.edu.cn"
]
[plugins.cri.registry.mirrors."harbor.lzh.com"] 此处添加了本地容器镜像仓库 Harbor,做为本地容器镜像仓库。
endpoint = [
"http://harbor.lzh.com"
]
[plugins.cri.x509_key_pair_streaming]
tls_cert_file = ""
tls_key_file = ""
[plugins.diff-service]
default = ["walking"]
[plugins.linux]
shim = "containerd-shim"
runtime = "runc"
runtime_root = ""
no_shim = false
shim_debug = false
[plugins.opt]
path = "/opt/containerd"
[plugins.restart]
interval = "10s"
[plugins.scheduler]
pause_threshold = 0.02
deletion_threshold = 0
mutation_threshold = 100
schedule_delay = "0s"
startup_delay = "100ms"
2.8. 启动containerd服务并设置开机自启动
[root@centos]# systemctl enable containerd
Created symlink from /etc/systemd/system/multi-user.target.wants/containerd.service to /usr/lib/systemd/system/containerd.service.
[root@centos]# systemctl start containerd
2.9.复制ctr命令至系统
[root@centos]# ls usr/local/bin/
containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 containerd-stress crictl critest ctd-decoder ctr
[root@centos]# cp usr/local/bin/ctr /usr/bin/
2.10.查看已安装containerd服务版本
[root@centos]# ctr version
Client:
Version: v1.6.0
Server:
Version: v1.6.0
2.11.安装runC
使用wget下载
[root@centos]# wget https://github.com/opencontainers/runc/releases/download/v1.1.0/runc.amd64
2.12.安装runC验证安装结果
查看已下载文件
[root@centos]# ls
runc.amd64
安装runC
[root@centos]# mv runc.amd64 /usr/sbin/runc
为runC添加可执行权限
[root@centos]# chmod +x /usr/sbin/runc
使用runc命令验证是否安装成功
[root@centos]# runc -v
runc version 1.1.0
commit: v1.1.0-0-g067aaf85
spec: 1.0.2-dev
go: go1.17.6
libseccomp: 2.5.3