Github软件包地址

1
https://github.com/containerd/containerd/releases/tag/1.5.0

安装依赖

1
[root@harbor-server ~]# yum -y install runc

安装container

1
2
3
4
5
6
7
[root@harbor-server ~]# tar zxf containerd-1.5.0-linux-amd64.tar.gz 
[root@harbor-server ~]# cd bin/
[root@harbor-server bin]# ls
containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 ctr
[root@harbor-server bin]# cd ..
[root@harbor-server ~]# cp bin/* /usr/bin/
[root@harbor-server ~]# mkdir -p /etc/containerd

生成默认配置文件

1
[root@harbor-server ~]# containerd config default > /etc/containerd/config.toml

使用systemd cgroup驱动程序

对于使用 systemd 作为 init system 的 Linux 的发行版,使用 systemd 作为容器的 cgroup driver 可以确保节点在资源紧张的情况更加稳定,所以推荐将 containerd 的 cgroup driver 配置为 systemd。修改前面生成的配置文件 /etc/containerd/config.toml,在 plugins.”io.containerd.grpc.v1.cri”.containerd.runtimes.runc.options 配置块下面将 SystemdCgroup 设置为 true

1
2
3
[root@harbor-server ~]# vi /etc/containerd/config.toml
···
SystemdCgroup = true

编辑启动文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[root@harbor-server ~]# vi /usr/lib/systemd/system/containerd.service
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target

启动服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@harbor-server ~]# systemctl start containerd
[root@harbor-server ~]# systemctl status containerd
● containerd.service - containerd container runtime
Loaded: loaded (/usr/lib/systemd/system/containerd.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2021-11-17 15:32:51 CST; 6s ago
Docs: https://containerd.io
Process: 8493 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
Main PID: 8495 (containerd)
Memory: 15.4M
CGroup: /system.slice/containerd.service
└─8495 /usr/bin/containerd
[root@harbor-server ~]# runc -v
runc version spec: 1.0.1-dev
[root@harbor-server ~]# ctr -v
ctr github.com/containerd/containerd v1.5.0

配置镜像仓库

1
2
3
4
5
6
[root@harbor-server ~]# vi /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri".registry]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://xxxxxxxx.mirror.aliyuncs.com" ,"https://registry-1.docker.io"]
# endpoint位置添加阿里云的镜像源