containerd 安装

containerd 安装

下载二进制安装包

githubr地址:https://github.com/containerd/containerd/releases

下载地址:https://github.com/containerd/containerd/releases/download/v1.6.6/containerd-1.6.6-linux-amd64.tar.gz

上传安装包到服务器并开始解压安装

# 解压
tar xf containerd-1.6.6-linux-amd64.tar.gz
# 复制文件到bin目录
cp -r bin/* /usr/local/bin/

创建containerd systemd service启动管理文件

修改ExecStart=/usr/local/bin/containerd为当前containerd文件路径

tee /etc/systemd/system/containerd.service <<-'EOF'
#  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/local/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
EOF

# 重新加载系统管理服务文件
systemctl daemon-reload

# 创建配置文件
mkdir /etc/containerd

# 生成模板配置文件
containerd config default > /etc/containerd/config.toml

# 修改配置文件
cd /etc/containerd/
vim config.toml

# vim下搜索/mirrors,添加镜像加速,使用docker镜像源即可,上下级配置,缩进两个空格。
   [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
          endpoint = ["https://fsk4g3nu.mirror.aliyuncs.com"]

# 启动containerd并设置开机自启动
systemctl enable containerd --now

#  查看当前containerd状态是否为running
systemctl status containerd

安装runc

github地址:https://github.com/opencontainers/runc/releases
下载地址:https://github.com/opencontainers/runc/releases/download/v1.1.3/runc.amd64

chmod +x runc.amd64
cp runc.amd64 /usr/local/bin/runc

# 查看是否安装成功
ctr --help

# 测试拉取镜像(非必须)
ctr images pull docker.io/library/nginx:latest

# 查看本地的镜像
ctr images ls

# 运行容器
ctr run -t  docker.io/library/nginx:latest container1 bash

安装containerd客户端工具

客户端工具有两种,分别是crictl和nerdctl
推使用nerdctl,使用效果与docker命令的语法一致
github下载链接:https://github.com/containerd/nerdctl/releases

安装nerdctl

# 解压
tar xf nerdctl-0.22.0-linux-amd64.tar.gz

# 复制文件到bin目录
cp nerdctl /usr/local/bin/

# 查看是否安装成功
nerdctl version

安装cni网络插件

CNI:Container network interface容器网络接口,为容器分配ip地址网卡等

github链接:https://github.com/containernetworking/plugins/releases

下载地址:https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz

安装cni

 mkdir /opt/cni/bin -p
 tar xf cni-plugins-linux-amd64-v1.1.1.tgz -C /opt/cni/bin/

以上就是关于container的介绍与安装