3-二進(jìn)制安裝containerd和docker

視頻鏈接:二進(jìn)制安裝containerd及docker
1.?安裝containerd
> [下載頁](https://github.com/containerd/containerd/releases)
```shell
## 先在ceph01上操作
## 直接下載:cri-containerd-1.7.2-linux-amd64.tar.gz,該包里面包含了containerd、 ctr、crictl、containerd-shim等二進(jìn)制文件,還有啟動命令等,只要在/下解壓即可。
# tar xf cri-containerd-1.7.2-linux-amd64.tar.gz -C /
# cat > /etc/crictl.yaml << EOF
runtime-endpoint: unix:///var/run/containerd/containerd.sock
image-endpoint: unix:///var/run/containerd/containerd.sock
timeout: 10
debug: false
EOF
## 生成containerd配置文件
# mkdir /etc/containerd
# containerd config default > /etc/containerd/config.toml
## 修改 /etc/containerd/config.toml
## 把SystemdCgroup = false修改為:SystemdCgroup = true
# vi /etc/containerd/config.toml
## 調(diào)整日志
max_container_log_line_size = 163840
## 用于從安全上下文中提取設(shè)備所有權(quán)信息,kubevirt cdi依賴該參數(shù),不設(shè)置該參數(shù)可能出現(xiàn)無權(quán)限
device_ownership_from_security_context = true
SystemdCgroup = true
```
> 修改/etc/systemd/system/containerd.service,將`LimitNOFILE=infinity`改為`LimitNOFILE=655360`
```shell
# systemctl enable containerd && systemctl restart containerd
## 使用 crictl info 查看配置是否生效
## 其他節(jié)點只需將相關(guān)文件拷貝過去啟動即可
# 在ceph01上操作
# for i in {2..5};do scp -rp /usr/local/bin ceph0$i:/usr/lobal/;scp -rp /usr/local/sbin ceph0$i:/usr/lobal/;scp /etc/containerd ceph0$i:/etc/; scp /etc/systemd/system/containerd.service ceph0$i:/etc/systemd/;done
## 在ceph02-05上操作
# systemctl daemon-reload && systemctl enable containerd && systemctl restart containerd
```
2. 安裝docker
```shell
## 先在ceph01上操作
1). 下載docker安裝包 https://download.docker.com/linux/static/stable/x86_64/docker-20.10.23.tgz
2). 解壓
# tar xf docker-20.10.23.tgz
3). 需要用到的二進(jìn)制文件包括:docker 和 dockerd,拷貝到 /usr/bin/目錄下即可。
# mv docker/docker* /usr/bin/
4). 創(chuàng)建 docker 用戶 useradd -s /sbin/nologin docker ? # 如果docker組存在,則使用 useradd -s /sbin/nologin docker -g docker
5). 啟動的配置文件 docker.serivce 和 docker.socket 拷貝到 /usr/lib/systemd/system/,daemon.json文件放到/etc/docker目錄
# cat > /usr/lib/systemd/system/docker.service ?<<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# ExecStart=/usr/bin/dockerd --graph=/data/docker -H fd:// --containerd=/run/containerd/containerd.sock --cri-containerd --debug
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --cri-containerd --debug
ExecReload=/bin/kill -s HUP \$MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
# 可能會出現(xiàn)錯誤:"Failed at step LIMITS spawning /usr/bin/dockerd: Operation not permitted",則需要將LimitNOFILE=infinity 改成:LimitNOFILE=65530
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
[Install]
WantedBy=multi-user.target
EOF
# cat > /usr/lib/systemd/system/docker.socket <<EOF
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
EOF
## 啟動docker
# systemctl daemon-reload && systemctl enable docker --now
## 配置鏡像加速和私有倉庫
# cat > /etc/docker/daemon.json <<EOF
{
?"registry-mirrors": ["https://vty0b0ux.mirror.aliyuncs.com"],
?"exec-opts": ["native.cgroupdriver=systemd"],
?"log-driver": "json-file",
?"log-opts": {
? ?"max-size": "500m"
?},
?"storage-driver": "overlay2",
?"insecure-registries": ["registry.demo.com","192.168.59.249:5000"]
}
EOF
# systemctl restart docker
## 在ceph01上操作
# for i in {2..5};do scp /usr/bin/docker* ceph0$i:/usr/bin/;scp -rp /etc/docker ceph0$i:/etc/;scp /usr/lib/systemd/system/docker.service ceph0$i:/usr/lib/systemd/system/;scp /usr/lib/systemd/system/docker.socket ceph0$i:/usr/lib/systemd/system/;done
## 在ceph02-05上操作
# useradd -s /sbin/nologin docker
# systemctl daemon-reload && systemctl enable docker --now
```