文章目录
1、YUM方式安装
1_获取YUM源
获取阿里云YUM源
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
发现有了docker-ce仓库
[root@localhost ~]# ls /etc/yum.repos.d/
centos-addons.repo centos.repo docker-ce.repo
查看YUM源中Containerd软件
[root@localhost ~]# yum list | grep containerd
containerd.io.x86_64 1.7.24-3.1.el9 docker-ce-stable
2_使用yum命令安装
安装Containerd.io软件,即可安装Containerd
yum -y install containerd.io
3_验证安装及启动服务
使用rpm -qa
命令查看是否安装,及对应的版本
[root@localhost ~]# rpm -qa | grep containerd
containerd.io-1.7.24-3.1.el9.x86_64
设置containerd服务启动及开机自启动
systemctl enable containerd
systemctl start containerd
查看containerd服务启动状态
[root@localhost ~]# systemctl status containerd
● containerd.service - containerd container runtime
Loaded: loaded (/usr/lib/systemd/system/containerd.service; enabled; preset: disabled)
Active: active (running) since Fri 2024-12-13 16:34:28 CST; 31min ago
Docs: https://containerd.io
Process: 79960 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
Main PID: 79961 (containerd)
Tasks: 9
Memory: 17.9M
CPU: 850ms
CGroup: /system.slice/containerd.service
└─79961 /usr/bin/containerd
4_验证可用性
安装Containerd时ctr
命令亦可使用,ctr命令主要用于管理容器及容器镜像等。
使用ctr命令查看Containerd客户端及服务端相关信息。
[root@localhost ~]# ctr version
Client:
Version: 1.7.24
Revision: 88bf19b2105c8b17560993bee28a01ddc2f97182
Go version: go1.22.9
Server:
Version: 1.7.24
Revision: 88bf19b2105c8b17560993bee28a01ddc2f97182
UUID: 05cc8807-00c0-4f3d-91dc-7c47eddc6cda
2、二进制方式安装
Containerd有两种安装包:
- 第一种是
containerd-xxx
,这种包用于单机测试没问题,不包含runC
,需要提前安装。 - 第二种是
cri-containerd-cni-xxxx
,包含runc
和k8s里的所需要的相关文件。k8s集群里需要用到此包。虽然包含runC,但是依赖系统中的seccomp
(安全计算模式,是一种限制容器调用系统资源的模式。)
1_获取安装包
下载Containerd安装包
wget https://github.com/containerd/containerd/releases/download/v1.7.24/cri-containerd-cni-1.7.24-linux-amd64.tar.gz
2_安装containerd
查看已获取的安装包
[root@localhost ~]# ls
cri-containerd-cni-1.7.24-linux-amd64.tar.gz
解压已下载的软件包
tar xf cri-containerd-cni-1.7.24-linux-amd64.tar.gz
查看解压后目录
[root@localhost ~]# ls
cri-containerd.DEPRECATED.txt etc opt usr
查看etc
目录,主要为containerd服务管理配置文件及cni
虚拟网卡配置文件
[root@localhost ~]# ls etc
cni crictl.yaml systemd
[root@localhost ~]# ls etc/systemd/
system
[root@localhost ~]# ls etc/systemd/system/
containerd.service
查看opt
目录,主要为gce
环境中使用containerd
配置文件及cni
插件
[root@localhost ~]# ls opt
cni containerd
[root@localhost ~]# ls opt/containerd/
cluster
[root@localhost ~]# ls opt/containerd/cluster
gce version
[root@localhost ~]# ls opt/containerd/cluster/gce
cloud-init cni.template configure.sh env
查看usr
目录,主要为containerd
运行时文件,包含runc
(比较小,不含静态文件)
[root@localhost ~]# ls usr
local
[root@localhost ~]# ls usr/local/
bin sbin
[root@localhost ~]# ls usr/local/bin
containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 containerd-stress crictl critest ctd-decoder ctr
[root@localhost ~]# ls usr/local/sbin
runc
3_查看containerd安装位置
查看containerd.service
文件,了解containerd文件安装位置
[root@localhost ~]# cat etc/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 dbus.service
[Service]
#uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration
#Environment="ENABLE_CRI_SANDBOXES=sandboxed"
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd 查看此位置,把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
4_复制containerd运行时文件至系统
查看宿主机/usr/local/bin
目录,里面没有任何内容。
ls /usr/local/bin/
查看解压后usr/local/bin
目录,里面包含containerd运行时文件
[root@localhost ~]# ls usr
local
[root@localhost ~]# ls usr/local/
bin sbin
[root@localhost ~]# 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
目录中,本次可仅复制containerd一个文件也可复制全部文件。
[root@localhost ~]# cp usr/local/bin/containerd /usr/local/bin/
[root@localhost ~]# ls /usr/local/bin/
containerd
5_添加containerd.service文件至系统
查看解压后的etc/system
目录
[root@localhost ~]# ls etc
cni crictl.yaml systemd
[root@localhost ~]# ls etc/systemd/
system
[root@localhost ~]# ls etc/systemd/system/
containerd.service
复制containerd服务管理配置文件至/usr/lib/systemd/system/
目录中
cp etc/systemd/system/containerd.service /usr/lib/systemd/system/containerd.service
查看复制后结果
[root@localhost ~]# ls /usr/lib/systemd/system/containerd.service
/usr/lib/systemd/system/containerd.service
6_查看containerd使用帮助
[root@localhost ~]# containerd --help
NAME:
containerd -
__ _ __
_________ ____ / /_____ _(_)___ ___ _________/ /
/ ___/ __ \/ __ \/ __/ __ `/ / __ \/ _ \/ ___/ __ /
/ /__/ /_/ / / / / /_/ /_/ / / / / / __/ / / /_/ /
\___/\____/_/ /_/\__/\__,_/_/_/ /_/\___/_/ \__,_/
high performance container runtime
USAGE:
containerd [global options] command [command options] [arguments...]
VERSION:
v1.7.24
DESCRIPTION:
containerd is a high performance container runtime whose daemon can be started
by using this command. If none of the *config*, *publish*, *oci-hook*, or *help* commands
are specified, the default action of the **containerd** command is to start the
containerd daemon in the foreground.
A default configuration is used if no TOML configuration is specified or located
at the default file location. The *containerd config* command can be used to
generate the default configuration for containerd. The output of that command
can be used and modified as necessary as a custom configuration.
COMMANDS:
config Information on the containerd config
publish Binary to publish events to containerd
oci-hook Provides a base for OCI runtime hooks to allow arguments to be injected.
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--config value, -c value Path to the configuration file (default: "/etc/containerd/config.toml")
--log-level value, -l value Set the logging level [trace, debug, info, warn, error, fatal, panic]
--address value, -a value Address for containerd's GRPC server
--root value containerd root directory
--state value containerd state directory
--help, -h show help
--version, -v print the version
7_生成containerd默认模块配置文件
Containerd 的默认配置文件为 /etc/containerd/config.toml
,可以使用containerd config default > /etc/containerd/config.toml
命令创建一份模块配置文件
创建配置文件目录
mkdir /etc/containerd
生成配置文件
containerd config default > /etc/containerd/config.toml
查看配置文件
[root@localhost ~]# cat /etc/containerd/config.toml
disabled_plugins = []
imports = []
oom_score = 0
plugin_dir = ""
required_plugins = []
root = "/var/lib/containerd"
state = "/run/containerd"
temp = ""
version = 2
[cgroup]
path = ""
[debug]
address = ""
format = ""
gid = 0
level = ""
uid = 0
[grpc]
address = "/run/containerd/containerd.sock"
gid = 0
max_recv_message_size = 16777216
max_send_message_size = 16777216
tcp_address = ""
tcp_tls_ca = ""
tcp_tls_cert = ""
tcp_tls_key = ""
uid = 0
[metrics]
address = ""
grpc_histogram = false
[plugins]
[plugins."io.containerd.gc.v1.scheduler"]
deletion_threshold = 0
mutation_threshold = 100
pause_threshold = 0.02
schedule_delay = "0s"
startup_delay = "100ms"
[plugins."io.containerd.grpc.v1.cri"]
cdi_spec_dirs = ["/etc/cdi", "/var/run/cdi"]
device_ownership_from_security_context = false
disable_apparmor = false
disable_cgroup = false
disable_hugetlb_controller = true
disable_proc_mount = false
disable_tcp_service = true
drain_exec_sync_io_timeout = "0s"
enable_cdi = false
enable_selinux = false
enable_tls_streaming = false
enable_unprivileged_icmp = false
enable_unprivileged_ports = false
ignore_deprecation_warnings = []
ignore_image_defined_volumes = false
image_pull_progress_timeout = "5m0s"
image_pull_with_sync_fs = false
max_concurrent_downloads = 3
max_container_log_line_size = 16384
netns_mounts_under_state_dir = false
restrict_oom_score_adj = false
sandbox_image = "registry.k8s.io/pause:3.8"
selinux_category_range = 1024
stats_collect_period = 10
stream_idle_timeout = "4h0m0s"
stream_server_address = "127.0.0.1"
stream_server_port = "0"
systemd_cgroup = false
tolerate_missing_hugetlb_controller = true
unset_seccomp_profile = ""
[plugins."io.containerd.grpc.v1.cri".cni]
bin_dir = "/opt/cni/bin"
conf_dir = "/etc/cni/net.d"
conf_template = ""
ip_pref = ""
max_conf_num = 1
setup_serially = false
[plugins."io.containerd.grpc.v1.cri".containerd]
default_runtime_name = "runc"
disable_snapshot_annotations = true
discard_unpacked_layers = false
ignore_blockio_not_enabled_errors = false
ignore_rdt_not_enabled_errors = false
no_pivot = false
snapshotter = "overlayfs"
[plugins."io.containerd.grpc.v1.cri".containerd.default_runtime]
base_runtime_spec = ""
cni_conf_dir = ""
cni_max_conf_num = 0
container_annotations = []
pod_annotations = []
privileged_without_host_devices = false
privileged_without_host_devices_all_devices_allowed = false
runtime_engine = ""
runtime_path = ""
runtime_root = ""
runtime_type = ""
sandbox_mode = ""
snapshotter = ""
[plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.options]
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
base_runtime_spec = ""
cni_conf_dir = ""
cni_max_conf_num = 0
container_annotations = []
pod_annotations = []
privileged_without_host_devices = false
privileged_without_host_devices_all_devices_allowed = false
runtime_engine = ""
runtime_path = ""
runtime_root = ""
runtime_type = "io.containerd.runc.v2"
sandbox_mode = "podsandbox"
snapshotter = ""
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
BinaryName = ""
CriuImagePath = ""
CriuPath = ""
CriuWorkPath = ""
IoGid = 0
IoUid = 0
NoNewKeyring = false
NoPivotRoot = false
Root = ""
ShimCgroup = ""
SystemdCgroup = false
[plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime]
base_runtime_spec = ""
cni_conf_dir = ""
cni_max_conf_num = 0
container_annotations = []
pod_annotations = []
privileged_without_host_devices = false
privileged_without_host_devices_all_devices_allowed = false
runtime_engine = ""
runtime_path = ""
runtime_root = ""
runtime_type = ""
sandbox_mode = ""
snapshotter = ""
[plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime.options]
[plugins."io.containerd.grpc.v1.cri".image_decryption]
key_model = "node"
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = ""
[plugins."io.containerd.grpc.v1.cri".registry.auths]
[plugins."io.containerd.grpc.v1.cri".registry.configs]
[plugins."io.containerd.grpc.v1.cri".registry.headers]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".x509_key_pair_streaming]
tls_cert_file = ""
tls_key_file = ""
[plugins."io.containerd.internal.v1.opt"]
path = "/opt/containerd"
[plugins."io.containerd.internal.v1.restart"]
interval = "10s"
[plugins."io.containerd.internal.v1.tracing"]
[plugins."io.containerd.metadata.v1.bolt"]
content_sharing_policy = "shared"
[plugins."io.containerd.monitor.v1.cgroups"]
no_prometheus = false
[plugins."io.containerd.nri.v1.nri"]
disable = true
disable_connections = false
plugin_config_path = "/etc/nri/conf.d"
plugin_path = "/opt/nri/plugins"
plugin_registration_timeout = "5s"
plugin_request_timeout = "2s"
socket_path = "/var/run/nri/nri.sock"
[plugins."io.containerd.runtime.v1.linux"]
no_shim = false
runtime = "runc"
runtime_root = ""
shim = "containerd-shim"
shim_debug = false
[plugins."io.containerd.runtime.v2.task"]
platforms = ["linux/amd64"]
sched_core = false
[plugins."io.containerd.service.v1.diff-service"]
default = ["walking"]
[plugins."io.containerd.service.v1.tasks-service"]
blockio_config_file = ""
rdt_config_file = ""
[plugins."io.containerd.snapshotter.v1.aufs"]
root_path = ""
[plugins."io.containerd.snapshotter.v1.blockfile"]
fs_type = ""
mount_options = []
root_path = ""
scratch_file = ""
[plugins."io.containerd.snapshotter.v1.btrfs"]
root_path = ""
[plugins."io.containerd.snapshotter.v1.devmapper"]
async_remove = false
base_image_size = ""
discard_blocks = false
fs_options = ""
fs_type = ""
pool_name = ""
root_path = ""
[plugins."io.containerd.snapshotter.v1.native"]
root_path = ""
[plugins."io.containerd.snapshotter.v1.overlayfs"]
mount_options = []
root_path = ""
sync_remove = false
upperdir_label = false
[plugins."io.containerd.snapshotter.v1.zfs"]
root_path = ""
[plugins."io.containerd.tracing.processor.v1.otlp"]
[plugins."io.containerd.transfer.v1.local"]
config_path = ""
max_concurrent_downloads = 3
max_concurrent_uploaded_layers = 3
[[plugins."io.containerd.transfer.v1.local".unpack_config]]
differ = ""
platform = "linux/amd64"
snapshotter = "overlayfs"
[proxy_plugins]
[stream_processors]
[stream_processors."io.containerd.ocicrypt.decoder.v1.tar"]
accepts = ["application/vnd.oci.image.layer.v1.tar+encrypted"]
args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
path = "ctd-decoder"
returns = "application/vnd.oci.image.layer.v1.tar"
[stream_processors."io.containerd.ocicrypt.decoder.v1.tar.gzip"]
accepts = ["application/vnd.oci.image.layer.v1.tar+gzip+encrypted"]
args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
path = "ctd-decoder"
returns = "application/vnd.oci.image.layer.v1.tar+gzip"
[timeouts]
"io.containerd.timeout.bolt.open" = "0s"
"io.containerd.timeout.metrics.shimstats" = "2s"
"io.containerd.timeout.shim.cleanup" = "5s"
"io.containerd.timeout.shim.load" = "5s"
"io.containerd.timeout.shim.shutdown" = "3s"
"io.containerd.timeout.task.state" = "2s"
[ttrpc]
address = ""
gid = 0
uid = 0
8_启动containerd服务并设置开机自启动
启动并设置开机自启
systemctl enable containerd
systemctl start containerd
查看状态
[root@localhost ~]# systemctl status containerd
● containerd.service - containerd container runtime
Loaded: loaded (/usr/lib/systemd/system/containerd.service; enabled; preset: disabled)
Active: active (running) since Fri 2024-12-13 20:17:32 CST; 24s ago
Docs: https://containerd.io
Process: 501971 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
Main PID: 501974 (containerd)
Tasks: 9
Memory: 14.7M
CPU: 122ms
CGroup: /system.slice/containerd.service
└─501974 /usr/local/bin/containerd
.......
9_复制ctr命令至系统
复制客户端工具,验证是否可用
[root@localhost ~]# ls usr/local/bin/
containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 containerd-stress crictl critest ctd-decoder ctr
[root@localhost ~]# cp usr/local/bin/ctr /usr/bin/
10_查看已安装containerd服务版本
验证可用
[root@localhost ~]# ctr version
Client:
Version: v1.7.24
Revision: 88bf19b2105c8b17560993bee28a01ddc2f97182
Go version: go1.22.9
Server:
Version: v1.7.24
Revision: 88bf19b2105c8b17560993bee28a01ddc2f97182
UUID: 7bffb6b6-fc62-498c-bcee-b9a88367d1ee
11_安装runC
由于二进制包中提供的runC默认需要系统中安装seccomp支持,需要单独安装,且不同版本runC对seccomp版本要求一致,所以建议单独下载runC二进制包进行安装,里面包含了seccomp(安全计算)模块支持。
11.1 获取runC
使用wget
下载
wget https://github.com/opencontainers/runc/releases/download/v1.2.3/runc.amd64
11.2 安装runC并验证安装结果
查看已下载文件
[root@localhost ~]# ls
runc.amd64
安装runC,将其移动到执行目录下即可
mv runc.amd64 /usr/sbin/runc
为runC添加可执行权限
chmod +x /usr/sbin/runc
使用runc命令验证是否安装成功
[root@localhost ~]# runc -v
runc version 1.2.3
commit: v1.2.3-0-g0d37cfd4
spec: 1.2.0
go: go1.22.10
libseccomp: 2.5.5
标签:安装,false,Containerd,plugins,v1,io,containerd,root From: https://blog.csdn.net/m0_62943934/article/details/144459913